Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Java
Stage 5: Specialization

Part 01 / Topic 2 of 7

Installing JDK 21 LTS

Download a JDK 21 build and install it, then check it from a terminal.

Real-world example: your laptop is new and you want to compile your first .java file today.

OS How to install Command to check
macOS brew install --cask corretto21 (Homebrew), or download the .pkg from Amazon Corretto's site java --version
Windows Download the .msi installer from Corretto's site and run it. ✅ Let it add Java to PATH on the install screen. java --version
Linux (Ubuntu) sudo apt install openjdk-21-jdk (or use Corretto's .deb/.rpm package) java --version

Open a terminal and check both tools — java runs programs, javac compiles them:

$ java --version
openjdk 21.0.11 2026-04-21 LTS
OpenJDK Runtime Environment Corretto-21.0.11.10.1 (build 21.0.11+10-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.11.10.1 (build 21.0.11+10-LTS, mixed mode, sharing)

$ javac --version
javac 21.0.11

(Exact build numbers vary by machine and update; what matters is that both commands print 21, not an error.)

PATH tip: PATH is a list of folders where your computer looks for commands. If you see 'java' is not recognized (Windows) or command not found: java (macOS/Linux), the JDK's bin folder is not on PATH — re-run the installer and tick the "add to PATH" option, or add the JDK's bin folder to PATH by hand.

🔍 Going deeper: JDK versions ending in an even number every two years (17, 21, 25, ...) are LTS; the odd ones in between (22, 23, ...) get only six months of updates. For learning and for real projects, pick the latest LTS — JDK 21 at the time this course was written.

Done here? The practice set for Part 1 — including the solutions — is on the part page.

Search the guide