Appendix B

Setting Up a Local JDK

Optional — OnlineGDB is the default

Appendix B — Setting Up Your Java Toolchain (Optional)

Read this first. This appendix is optional for Coding 1 and Coding 2. The default workflow for both courses is OnlineGDB in your browser — see Appendix D — The Online Coding Workflow. Most students will never need this page. The rest of this appendix is for students who want to run Java locally — usually because they already have a development habit on their machine, or because Coding 3 is on the horizon and they want a head start.


You need three things on your machine:

  1. A JDK — the Java Development Kit. It includes the javac compiler, the java runtime, and the standard libraries.
  2. A text editor — for writing the code.
  3. A terminal — for running javac and java.

We’re targeting JDK 21 LTS (the current Long-Term Support release; JDK 25 LTS shipped in late 2025 and is also fine). “LTS” means Long-Term Support; pick an LTS version unless you have a specific reason not to. Everything in this course works on JDK 17 LTS as well — that’s the previous LTS — but new installs as of 2026 should default to 21 or 25.

For the JDK itself, we recommend Eclipse Temurin (adoptium.net) — the community-favorite OpenJDK build, free, no Oracle account required. The Microsoft Build of OpenJDK (microsoft.com/openjdk) is also fine, especially on Windows. Either works on any OS. Pick one and stick with it. Don’t install both at oncePATH confusion is the most common setup bug, and having two JDKs makes it twice as easy to create.

Pick your OS below.


Option A: macOS

Step 1 — Install the JDK

The easiest path is Homebrew. If you don’t have Homebrew, install it from brew.sh first.

Then in Terminal (Cmd+Space, type terminal, Enter):

brew install --cask temurin@21

That installs Eclipse Temurin JDK 21 into /Library/Java/JavaVirtualMachines/. (Substitute temurin@25 for the newer LTS if you prefer; both work for this course.)

If you’d rather not use Homebrew, download the .pkg installer for macOS from adoptium.net and double-click it. Same result.

Step 2 — Verify

Close and reopen Terminal (so the new PATH is picked up). Then:

java -version
javac -version

Both should print a version starting with 21 (e.g., openjdk version "21.0.x") — or 25 if you installed JDK 25. If they do, the JDK is installed and on your PATH.

Step 3 — Editor

Open Visual Studio Code (from code.visualstudio.com, same as Appendix A). Skip to “Verification” at the bottom of this page.


Option B: Windows

You have one easy path here. Use it.

Step 1 — Install the JDK

Download the Windows x64 MSI installer for JDK 21 (or 25) from adoptium.net (Eclipse Temurin) or microsoft.com/openjdk. Run the installer. Important: on the “Custom Setup” screen, make sure these two options are enabled:

  • Add to PATH
  • Set JAVA_HOME variable

Both are usually off by default. Click them to On. This saves you from manually editing environment variables later — which is the single most-skipped step on Windows and the single most common reason a “working” install doesn’t actually work.

Finish the installer.

Step 2 — Verify

Open a new PowerShell or Command Prompt window (a new one — the existing windows won’t see the new PATH). Then:

java -version
javac -version

Both should print a 17.x version string.

If they don’t: open System → Advanced system settings → Environment Variables. Confirm there’s a JAVA_HOME variable pointing at your JDK install folder (something like C:\Program Files\Eclipse Adoptium\jdk-21.0.x-hotspot), and confirm that %JAVA_HOME%\bin is in your Path. Reopen the terminal and try again.

Step 3 — Editor

Install Visual Studio Code from code.visualstudio.com. Skip to “Verification” below.


Option C: Linux

Open your terminal.

Step 1 — Install the JDK

Ubuntu / Debian:

sudo apt update
sudo apt install -y openjdk-21-jdk

Fedora:

sudo dnf install -y java-21-openjdk-devel

Arch:

sudo pacman -S jdk21-openjdk

Note the -jdk / -devel suffixes — those are the full development packages. A bare openjdk-21-jre only gives you the runtime, no javac. You want the JDK.

Step 2 — Verify

java -version
javac -version

Both should print 21.x (or whichever LTS you installed). If javac is missing, you installed the JRE instead of the JDK. Re-run the install command with the -jdk / -devel package name.

Step 3 — Editor

Install VS Code from code.visualstudio.com or your distro’s package manager.


Verification

Regardless of OS, everyone does this last step. It’s how you know the toolchain works together.

1. Make a folder for your code

mkdir -p ~/code/coding1-java
cd ~/code/coding1-java

(On native Windows: mkdir C:\code\coding1-java and cd C:\code\coding1-java.)

2. Write Hello.java

Open VS Code. File → Open Folder → select the folder you just made. Create a new file named Hello.java — the capital H matters; the filename must match the class name. Paste:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, world.");
    }
}

Save the file.

3. Compile

In your terminal (still inside the folder containing Hello.java):

javac Hello.java

If the command finishes with no output, the compile succeeded. No output is good output. You should now also see a Hello.class file appear in the folder — that’s the compiled bytecode.

If you see errors, read them. Most beginner errors are typos. Compare your file letter-by-letter to the version above. The public class Hello line is case-sensitive; so is the filename.

4. Run

java Hello

Note: no .java, no .class, no ./. Just the class name. You’re telling the JVM “load and run the class named Hello.”

You should see:

Hello, world.

If you do: you’re done. The toolchain works. Close this page and head back to Chapter 13.


”What’s the classpath?”

Short answer: don’t worry about it yet. By default, the java command treats your current working directory as the classpath — meaning it looks in the folder you’re standing in for .class files. If Hello.class is in the folder and you ran java Hello from that folder, it works. That’s all you need for Coding 1 and Coding 2.

You’ll meet the formal -cp / -classpath flag in Coding 3 when projects start spanning multiple folders and using external libraries. Until then, keep your .java files in one folder, compile them in that folder, run them from that folder. The classpath takes care of itself.

Coach’s Note — The classpath is one of those concepts that looks intimidating from the outside and dissolves into “oh, that’s it?” once you’ve seen it work. The fact that “current directory” is the default behavior is a kindness. Don’t go reading Stack Overflow threads about classpath manipulation until you need to.


When Things Go Wrong

If java -version failed: the JDK isn’t installed or isn’t on your PATH. On macOS, re-run the brew install step and reopen Terminal. On Windows, re-check that Add to PATH and Set JAVA_HOME were enabled in the installer — re-run it if not. On Linux, re-run the package-install command and verify the package name had -jdk or -devel.

If java -version works but javac -version doesn’t: you installed the JRE (just the runtime) instead of the JDK. Re-install with the JDK package.

If javac Hello.java failed with error: class Hello is public, should be declared in a file named Hello.java: your filename and class name don’t match. Rename the file (capital H, exact case) or rename the class. They must match.

If javac succeeded but java Hello printed Error: Could not find or load main class Hello: you’re probably running from the wrong folder, or you typed java Hello.class (don’t include the extension). Run ls (Mac/Linux) or dir (Windows) to confirm Hello.class is in the current folder, then run java Hello — no extension.

If java Hello printed something other than Hello, world.: you compiled a different file than you saved. Open Hello.java in your editor, confirm it matches the version above, save, then run javac Hello.java again before running java Hello.

If you’re stuck for more than 20 minutes: stop. Open Appendix D and use OnlineGDB. The local toolchain is a convenience, not a requirement — there is no merit badge for fighting PATH variables alone.


Optional: A Slightly Nicer Editor Experience

Once everything above works, you can optionally install the Extension Pack for Java in VS Code (Microsoft’s official bundle). It adds Java-tuned syntax highlighting, autocomplete, click-to-definition, a test runner, and a debugger. In VS Code: Extensions panel (the four-squares icon on the left) → search “Extension Pack for Java” → Install. This is the Java analog to the C/C++ extension recommended in Appendix A.

If VS Code isn’t your style, IntelliJ IDEA Community Edition (free, full-featured, very popular for Java specifically) and Eclipse (the longtime Java standard, battle-tested) are both fine. The course doesn’t care which editor you use; it only cares that javac and java work from your terminal.


Up next: Back to Chapter 13. And remember — if any of this stops working on the day a project is due, fall back to Appendix D and submit an OnlineGDB link. The local setup is a privilege, not a requirement.