Installing the Java JDK, testing your first programme and building projects with Maven or Gradle.

## WHAT IT IS | The JDK.

Java is one of the most widely used programming languages, particularly for business software and Android. To create Java programmes, you need the **JDK** (Java Development Kit). The JRE is only for running programmes; make sure you use the JDK.

Choose an **LTS** version, such as Java 21 or 25. I’m using Temurin here: a free version from the Eclipse Foundation. You can also use Oracle’s version, but it has different licence terms for businesses.

### 01 / Windows

Open PowerShell via the Start menu and run the following:

```
winget install --id EclipseAdoptium.Temurin.21.JDK -e
```

Close PowerShell and open it again.

### 02 / Linux

**Ubuntu / Debian / Linux Mint**
```
sudo apt update
sudo apt install openjdk-21-jdk
```

**Fedora**
```
sudo dnf install java-21-openjdk-devel
```

**Arch Linux**
```
sudo pacman -S jdk21-openjdk
```

### 03 / Checking

```
java -version
javac -version
```

Please note: there is one hyphen here for ‘version’, not two.

## FIRST PROGRAMME | Testing whether it works.

### 04 / Create a file

Create a file called `Hallo.java`` with the following content:

```
public class Hallo {
    public static void main(String[] args) {
        System.out.println("Hallo!");
    }
}
```

### 05 / Start it

```
java Hallo.java
```

Can you see ‘Hello!?’? Then Java is working.

## PROJECTS | Maven and Gradle.

Larger Java projects use Maven (`pom.xml` file) or Gradle (`build.gradle` file). These retrieve the packages and build the programme.

### 06 / Maven project

Is there a file called `mvnw` or `mvnw.cmd` in the project? Use that; then you won’t need to install Maven separately:

**Windows**
```
.\mvnw.cmd package
```

**Linux**
```
./mvnw package
```

### 07 / Gradle project

**Windows**
```
.\gradlew.bat build
```

**Linux**
```
./gradlew build
```

## WORKING WITH AI | Ask your assistant.

### 08 / Multiple versions

Does a project require a different version of Java? You can install multiple JDKs side by side. Ask your AI assistant which version is currently active and how to switch between them.

### 09 / A task for your AI assistant

"Check which version of Java this project requires and whether it is installed. Build the project using the Maven or Gradle wrapper and explain what goes wrong if the build fails."

**Good to know**
Only download Java from adoptium.net, oracle.com or via your computer’s package manager. Websites offering ‘free Java’ with their own installation programme are often untrustworthy.

