JAVA - Zero to Hero / Getting Started with JAVA

Installing Java on Your Computer

Windows – Java 21 (Oracle) + VS Code Setup

1️⃣ Step 1: Download and Install Oracle JDK 21

  1. Go to the official Oracle page:

    🔗 https://www.oracle.com/java/technologies/javase/jdk21-archive-downloads.html

  2. Scroll down → Under Windows x64 Installer, click:

    jdk-21_windows-x64_bin.exe
  3. Sign in or create an Oracle account to download.

  4. Run the .exe installer → Click Next → Finish.

2️⃣ Step 2: Set Environment Variables

  1. Press Windows key → Search Environment Variables → Open.

  2. Under System Variables:

    • Click New

      • Name: JAVA_HOME

      • Value: C:\\Program Files\\Java\\jdk-21 (or your JDK 21 path)

    • Select Path → Click Edit → Click New → Add:

      %JAVA_HOME%\\bin

3️⃣ Step 3: Verify Installation

Open Command Prompt and type:

java -version
javac -version
java version "21.0.3"  (or similar)

4️⃣ Step 4: Install VS Code

  1. Download from:

    🔗 https://code.visualstudio.com/

  2. Install using default settings → Open VS Code.

5️⃣ Step 5: Install Java Extensions in VS Code

  1. Press Ctrl + Shift + X to open Extensions.

  2. Search: Java Extension Pack

  3. Click Install.

6️⃣ Step 6: Create and Run Java Program

  1. Create a folder → Open it in VS Code.

  2. Create a file: Hello.java

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from Java 21 on Windows!");
    }
}

Click Run at the top or press Ctrl + F5.


macOS – Java 21 (Oracle) + VS Code Setup

1️⃣ Step 1: Download and Install Oracle JDK 21

  1. Go to:

    🔗 https://www.oracle.com/java/technologies/javase/jdk21-archive-downloads.html

  2. Scroll to macOS x64 or macOS AArch64 (for Apple M1/M2)

    • Download .dmg file (e.g., jdk-21_macos-aarch64_bin.dmg)

  3. Open .dmg → Drag and drop Java into Applications → Done.

2️⃣ Step 2: Set JAVA_HOME

Open Terminal and run:

/usr/libexec/java_home -V

Copy the path for JDK 21, then add it to your profile (.zshrc or .bash_profile):

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH=$JAVA_HOME/bin:$PATH

Then apply it:

source ~/.zshrc

3️⃣ Step 3: Verify Installation

In Terminal, type:

java -version
javac -version
java version "21.0.3"

4️⃣ Step 4: Install VS Code

  1. Download from:

    🔗 https://code.visualstudio.com/

  2. Drag to Applications → Open VS Code.

5️⃣ Step 5: Install Java Extensions

  1. Open VS Code → Press Cmd + Shift + X

  2. Search: Java Extension Pack

  3. Click Install

6️⃣ Step 6: Create and Run Java Code

  1. Create a folder → Open in VS Code.

  2. Create Hello.java:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from Java 21 on Mac!");
    }
}

Click Run or press Cmd + Fn + F5