Installation
Installing Java
Windows (WSL) and Linux
- Update your package index
bash
sudo apt update && sudo apt upgrade -y
- Install Java 21
bash
sudo apt install openjdk-21-jdk
- Verify Java (you might need to restart your terminal first)
bash
java -version
- Install Maven
bash
sudo apt install maven
- Verify Maven (you might need to restart your terminal first)
mvn -v
Mac
- Install Java
bash
brew install openjdk@21
- Verify Java
bash
java -version
- Install Maven
bash
brew install maven
- Verify Maven
bash
mvn -v
Configuring VS Code
Open VS Code
Hit
Ctrl + Shift + X
to open the Extensions panelSearch for "Extension Pack for Java" and install it
Running your first Java code
- Create a folder to put your code into:
bash
cd Repos
mkdir hello-java
- Make a file called
Main.java
:
bash
cd hello-java
touch Main.java
- Open the folder in VS Code:
bash
code .
- Inside
Main.java
, type the following code:
java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Finally, run the file with
java
:
bash
java Main.java
You should see
Hello, World!
in the terminal.