Installing the JDK: Setting Up Your Workshop

Installing the JDK: Setting Up Your Workshop in Java: You cannot bake without an oven. Before writing a single line of Java, your machine needs the JDK (Java…

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 .java source files into .class bytecode.
  • 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

  1. Reusing an old terminal: PATH changes only reach terminals opened after installation. Close it and open a fresh one.
  2. Installing the JRE: The JRE can run Java but cannot compile it. You need the JDK.
  3. Several versions fighting: If java -version prints 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

  1. The Version Check: Install a JDK, then save the output of java -version and javac -version into a note.
  2. Find JAVA_HOME: Print it with echo $JAVA_HOME (macOS/Linux) or echo %JAVA_HOME% (Windows CMD). If it is empty, set it.
  3. The Manual Compile: Save a tiny class as Hi.java, then run javac Hi.java followed by java Hi. You just did by hand what an IDE does for you.