For the following courses you need to have
- Java 17 installed on your computer
- VsCode installed on your computer
- Maven installed on your computer
... which are already installed on our computers in our HSD laboratory!!!
WINDOWS
- Winget for Windows 10 users: LINK (winget is installed in Windows 11 by default)
- Java Open JDK 17
- Either via installer: Adoptium Open JDK installer
- Or via winget (system-wide by default):
winget install EclipseAdoptium.Temurin.17.JDK
- Visual Studio Code
-
Either via installer: Visual Studio Code Installer
- Download the vscode installer from the official website.
-
Or with winget system-wide:
winget install Microsoft.VisualStudioCode --scope machine -
Or with winget as a user-only installation:
winget install Microsoft.VisualStudioCode
-
- VSCode Java extension pack
- VSCode Spring Boot extension pack
- Gluon Scene Builder
- Either via installer: Gluon Scene Builder Installer
- Or with winget (user only):
winget install Gluon.SceneBuilder
- Maven
- open powershell as administrator (right-click: open as administrator) and run:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- Once the installation is completed, close the Powershell (Admin) or Terminal (Admin) and open it again and run:
choco install maven
- open powershell as administrator (right-click: open as administrator) and run:
MACOS
-
Homebrew (If wanted)
- If wanted you can use homebrew to complete the following installation steps. Homebrew is a unofficial package manager for macOS, which should help you with installing new software on your system. To get started with homebrew just paste the following command inside your terminal window:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- If wanted you can use homebrew to complete the following installation steps. Homebrew is a unofficial package manager for macOS, which should help you with installing new software on your system. To get started with homebrew just paste the following command inside your terminal window:
-
Java Open JDK 17
- Either via installer: Adoptium Open JDK installer
- Or via brew:
brew install --cask temurin
-
Visual Studio Code
- Either via installer: Visual Studio Code Installer
-
Download the vscode App from the official website.

-
Install the app on your system. Simply drag and drop the downloaded
*.appfile into your Applications folder.
-
- Or via brew:
brew install --cask visual-studio-code
- Either via installer: Visual Studio Code Installer
-
Gluon Scene Builder
- Either via installer: Gluon Scene Builder Installer
- Or via brew:
brew install --cask scenebuilder
-
Maven
- Either manually using these setup instructions: Maven - Installing
- Or via brew:
brew install maven
UBUNTU
- Java Open JDK 17
sudo apt install openjdk-17-jdk
- Visual Studio Code
- Either via installer: Visual Studio Code Installer
- Or via snap:
sudo snap install code --classic
- VSCode Java extension pack
- VSCode Spring Boot extension pack
- Gluon Scene Builder
- via installer: Gluon Scene Builder Installer
- or via terminal:
wget https://download2.gluonhq.com/scenebuilder/17.0.0/install/linux/SceneBuilder-17.0.0.deb sudo dpkg -i SceneBuilder-17.0.0.deb
- Maven
sudo apt install maven
-
Click on the "Extension" Icon in the left panel
-
search for
java extension packin the search field click on the first entry (NOTE: check that the distributor is MICROSOFT and no-one else) and click on theInstallbutton to installer the extension pack. Wait until all extensions are installed.
ATTENTION: When you are inside the HSD laboratory room save ALL your work on the H:\ drive!!!
MacOS Users only - CLICK TO EXPAND
Please make sure to follow these steps to "downgrade" your TextEdit to save simple java files:
- on the menu bar on the top left corner of your screen, click on TextEdit, then Preferences.
- In the New Document tab, change the document format to Plain Text under the Format section. Uncheck the Smart quotes box under the Options section towards the bottom of the preference window.
- Switch to the Open and Save tab. Change the Opening files and Saving files to Unicode (UTF-8).
- Close the TextEdit application and re-open it. Open a new document.
- Create, compile and run a simple "Hello World" java application with only a text editor and the command line.
- Create and run a simple Java App, utilizing functions (methods) and recursion with VsCode.
- Let your file explorer show file extensions to safe files with the correct
.javafile extension:
-
Open a simple text editor (Windows Notepad, Ubuntu Gedit or MacOs TextEdit) enter the following code and save it as
Hello.javato your desired location:public class Hello { public static void main(String args[]) { System.out.println("Hello Java"); } }
-
Open a command line interface (Windows:
PowershellorTerminal- NOTcmd.exe, Ubuntu: CTRL + SHIFT + T, MacOs: search forTerminal) and navigate to the location where you saved your Java Code with:cd PATH_TO_YOU_FILE -
Type
javac Hello.javaand press enter -
Now the java code has been compiled to
Hello.classwhich you can run from within your terminal with:java Hello
GENERAL NOTE: While developing in VsCode, please check red squiggle lines and/or the "PROBLEMS" tab for any compilation errors or linter warnings. Often you can use the "Quick Fix" in the context menu (mouse over or CTRL + ., MacOs: CMD + .).
-
Create a new Java Project without build tools by...
EITHER clicking on the "Create Java project" button in the explorer view of VsCode (considering you have no directory currently opened, otherwise this button won't show up), selecting "No builds tools", choosing a directory to create the project in and naming it
se1c1OR by opening the VsCode command palette (press CTRL+SHIFT+P, MacOS: CMD+SHIFT+P) and typing Java: Create Java Project, selecting "No builds tools", choosing a directory to create the project in and naming it
se1c1 -
VsCode should have created the file
App.javafor you (if not, create it) -
Change
App.javato include- a
mainMethod (should be already inside) - inside the
mainmethod declare the following variables and initialize them if a fitting valueeineZahlof the typeintnochEineZahlof the typeinteineKommaZahlof the typedoubleeineZeichenKetteof the typeString
- outside of the
mainmethod, but insideApp- a
staticmethodaddierenwith two parameters (also called "arguments") of the typeint, for exampleaandb, that returns the addition ofaandb - a
staticmethoddividierenwith two parameters of the typedouble, for exampleaandb, that returnsadivided byb - a
staticmethodggt(größter, gemeinsamer Teiler) that calculates the greatest common divisor of the twointvariablesaandb- constraint: use recursion
- a
- call
addierenwitha:eineZahlandb:nochEineZahland save the result in the variablesumme - call
dividierenwitha:eineKommaZahlandb:summeand save the result in the variablequotient - Use the method
System.out.printlnto print outeineZeichenKette + quotientto the integrated terminal in VsCode - call
ggtwitha:eineZahlandb:nochEineZahland useSystem.out.printlnto print the result to the terminal - Explain why
addierenanddividierenneed to be declared asstatic - (OPTIONAL) Change
addierenthe arguments toint... zahlen, declare and initialize the variableint summme = 0inside the method body ofaddierenand iterate of the provided arguments with a for-loop to add each argument tosummeand finally returnsummeat the end
- a
- Create a new java project without build tools like in Course 01, Task 2
- Copy the code of
App.javaof Course 01, Task 2 into your newApp.java - (OPTIONAL) Additionally, add the following
staticmethods insideApp- multiplizieren
- sin(x)
- x^y
- Display a menu to the terminal which displays one option for each of your methods. For example:
CALCULATOR - please select: 0: Programmende 1: addieren 2: dividieren 3: multiplizieren 4: sin(x) 5: x^y - Read in user input in the terminal
- Display what parameters should now be provided by the user
- Read in user input for each parameter the selected methods requires (if you improved the parameters in
addierentoint... zahlenyou need to define a "stop" character likesfor stop) - Run the selected method and display the result in the terminal
- Repeat the programm until the user presses 0, which should close all open resources and exit the program.
Note: (Currently German only)
Die Klassen Kfz und Lkw werden erstellt, wobei die Grundprinzipien der Objektorientierung sukzessive einfließen. Dies bedeutet, dass wir mit einer "schlechten" Klasse KfzV0 anfangen und diese ständig verbessern, bis wir schließlich eine "schöne" Klasse Kfz erhalten. Hierzu werden im Folgenden zwei Arten von Klassen erstellt. KfzV0, Kfz und Lkw sollen zur Instanziierung von Objekten dienen und lediglich Attribute besitzen und Methoden zur Verfügung stellen. Die Demo-Klassen sollen genutzt werden, um einzelne Instanzen der Kfz Klassen zu erzeugen. Diese sollen eine main-Methode enthalten und somit ausführbar sein.
- Erstellen Sie das neue Java Projekt
se1c3. - Erstellen Sie sukzessive (nacheinander) die Klassen
KfzV0,KfzundLkw:- Implementieren Sie die Klasse
KfzV0mit den öffentlichen Integer-AttributensitzeundtankInhaltund dem öffentlichen Float-Attributverbrauch.
- Implementieren Sie die Klasse
- Implementieren Sie das Programm
KfzDemo.javamit einer main-Methode:- Das Objekt
minivanwird von der KlasseKfzV0erzeugt. - Die Attribute werden mit
sitze = 6,tankInhalt = 70,verbrauch = 14initialisiert. - Die mögliche Reichweite bei vollem Tank wird ausgerechnet und mit
System.out.printlnausgegeben.
- Das Objekt
- Erstellen Sie die Datei
ZweiKfz.javaund kopieren sie den Inhalt vonKfzDemo.javahinein, außerdem:- Zusätzlich zum
minivanObjekt wird ein Objektsportwagenvon der KlasseKfzV0erzeugt. - Die Attribute von
sportwagenwerden mitsitze = 2,tankInhalt = 45,verbrauch = 11initialisiert. - Die mögliche Reichweite von
sportwagenbei vollem Tank wird ausgerechnet und mittelsSystem.out.printlnausgegeben.
- Zusätzlich zum
- Erweitern Sie die Klasse
KfzV0um die Methodereichweite(), die die Reichweite als Rückgabewert liefert. - Erstellen Sie die Datei
ReturnDemo.javaund kopieren sie den Inhalt vonZweiKfz.javahinein, zusätzlich:- Die Ausgabe der Reichweite erfolgt in der main-Methode, wobei die Methode reichweite() genutzt wird.
- Die Klasse
KfzV0wird um die MethodespritVerbrauch(int km)erweitert.- Die Methode hat als Eingabeparameter eine Entfernung in Kilometern.
- Sie berechnet den entsprechenden Spritverbrauch für die Entfernung.
- Der Spritverbrauch wird als float-Ergebnis zurückgegeben.
- Erstellen Sie die Datei
SpritDemo.javaund kopieren Sie den Inhalt vonReturnDemo.javahinein, außerdem:- Die Methode spritVerbrauch wird in der main-Methode für die Entfernung 252 km aufgerufen und die Ergebnisse für die beiden Instanzen ausgegeben.
- Erstellen Sie die Klasse
Kfzund kopieren Sie den Inhalt vonKfzV0.javahinein. Die neue KlasseKfzwird um die Konstruktor-MethodeKfz(int sitze, int tankInhalt, float verbrauch)erweitert. Zusätzlich werden alle Attribute aufprivategesetzt. - Erstellen Sie die Datei
KonstruktorDemo.javaund kopieren Sie den Inhalt vonSpritDemo.javahinein, außerdem:- Die Attribute werden über den Konstruktor
Kfzinitialisiert.
- Die Attribute werden über den Konstruktor
- Die Klasse Lkw wird von
Kfzabgeleitet (Vererbung): - Sie hat die beiden zusätzlichen Attributeint ladeFlaecheundboolean hatAnhaenger. - Der KonstruktorLkwinitialisiert alle Attribute. - Die Lkw-MethodespritVerbrauchaddiert immer einen Liter zum errechneten Verbrauch hinzu. - Implementieren Sie das Programm
LkwDemo.javamit:- Einem Objekt
sportWagender KlasseKfzund ein Objektmagirusder KlasseLkw. - Das magirus-Objekt hat die gleichen Attribute wie das sportwagen-Objekt (nur zur Demo).
- Weisen Sie der zusätzlichen Referenz-Variable
kfzder Klasse Kfz (keine Instanziierung) nacheinandersportWagenundmagiruszu und geben Sie jeweils den Verbrauch auf 252 km aus.
- Einem Objekt
- Beschreiben sie mündlich was eine Konstruktor Methode generell macht auch wenn Sie keine Werte initialisiert, was sie zurück gibt und was sie mit diesem Rückgabewert machen können.
A calculator app made with JavaFX.
-
Create the Maven project
se1c4by using the archetypejavafx-archetype-simplefromorg.openjfxto create a JAVA FX (not Swing!) applictionIMPORTANT: if you have Java 21 installed instead of Java 17 (you can check the version with
java --versionin the terminal), you need to set the javafx-controls dependency version to 20 inside pom.xml! -
add the following dependency to your
pom.xmlfile:<dependency> <groupId>net.objecthunter</groupId> <artifactId>exp4j</artifactId> <version>0.4.8</version> </dependency>
-
Add the following line to your
module-info.javarequires exp4j; -
The warning...
Name of automatic module
exp4jis unstable, it is derived from the module's file name....can be IGNORED (the package creator did not follow java module naming conventions)!
-
IMPORTANT for Apple💻🍎 Mac M1/M2/M3 (not Intel!) users at home...
Change the javafx-controls dependency, to include
<classifier>mac-aarch64</classifier>after the version tag, or the UI will not start and the app will crash!
-
Create a calculator UI inside
App.javawith the following JavaFX UI classes:HsdButtonextendsButton- call the
superconstructor inside its constructor - set the min width and size to 50 inside its constructor
- set the background color to be white inside its constructor
- declare this
publicclassinside a new fileHsdButton.java
- call the
TextFieldGridPaneBorderPane
-
Make sure you import the correct UI classes from JavaFX! Not from AWT or Swing!!!
-
Import and use
ExpressionBuilderandExpressionfromnet.objecthunterto calculate the result and display it in the UI -
Explain verbally how you've built your user interface and why using and understanding maven ist important for Java applications.
Note: (feel free to adapt and improve the design, add more buttons or use css to improve the styling)















