Concept Explanation
You cannot bake without an oven. Before writing a single line of Java, your machine needs the JDK (Java Development Kit) — the toolset that both compiles and runs your code.
A fresh computer has no idea what Java is. Installing the JDK gives you two command-line tools you will use constantly:
javac— the compiler, which turns.javasource files into.classbytecode.java— the launcher, which runs that bytecode on the JVM.
Always pick an LTS (Long Term Support) release — Java 17 or Java 21. LTS versions receive security patches for years, which is exactly why companies standardise on them.
Installation by Platform
Windows — download the .msi installer from Adoptium (Eclipse Temurin) and tick "Set JAVA_HOME variable" during setup.
macOS — one line with Homebrew:
brew install --cask temurin@21
Linux (Debian / Ubuntu):
sudo apt update
sudo apt install openjdk-21-jdk
Verifying the Install
Open a brand new terminal and run both commands:
java -version # the launcher
javac -version # the compiler
You should see matching version numbers, such as openjdk 21.0.2. If java works but javac reports "command not found", you installed the JRE (runtime only) rather than the full JDK.
Common Mistakes
- Reusing an old terminal: PATH changes only reach terminals opened after installation. Close it and open a fresh one.
- Installing the JRE: The JRE can run Java but cannot compile it. You need the JDK.
- Several versions fighting: If
java -versionprints an unexpected number, an older Java sits earlier in your PATH.
Best Practices
- Choose LTS: Java 21 today. Skip non-LTS releases for anything you intend to maintain.
- Set JAVA_HOME: Maven, Gradle, and most IDEs read this variable to locate your JDK.
- Remember your version: Language features are version-gated — records need 16+, virtual threads need 21+.
Practice Exercises
- The Version Check: Install a JDK, then save the output of
java -versionandjavac -versioninto a note. - Find JAVA_HOME: Print it with
echo $JAVA_HOME(macOS/Linux) orecho %JAVA_HOME%(Windows CMD). If it is empty, set it. - The Manual Compile: Save a tiny class as
Hi.java, then runjavac Hi.javafollowed byjava Hi. You just did by hand what an IDE does for you.