Install the JDK, Not the JRE
The first decision is which of the two downloads you need, and the naming is genuinely confusing the first time. The JRE (Java Runtime Environment) can only run Java programs. The JDK (Java Development Kit) contains the entire JRE plus the compiler and the developer tools. You are learning to write Java, so you need the JDK. Installing only a JRE gives you a working java command and no javac, which produces a very confusing hour.
The second decision is which build to download, and here the many names hide a simple truth. Java itself is open source, under the project name OpenJDK. Several organisations package that same source into installers: Eclipse Temurin, Amazon Corretto, Azul Zulu, Microsoft Build of OpenJDK, and Oracle's own JDK. They compile the same code and run this course identically. Temurin from adoptium.net is a good default because it is free for any use, has installers for every platform, and its Windows installer offers to set up your environment variables for you.
The third decision is the version. Pick a long-term support release — Java 17 or Java 21 — rather than the newest number available. LTS releases are what companies deploy and what interview questions assume. This course targets Java 17 and above.
- JDK = compiler + runtime + library + tools. This is what you install.
- JRE = runtime only. Enough to run someone else's program, not enough to write your own.
- OpenJDK is the source; Temurin, Corretto, Zulu and Oracle JDK are builds of it.
- Choose an LTS version — 17 or 21 — over the newest release.
- A 64-bit build is what you want on any machine bought in the last decade.
- Oracle's own JDK has had its licence changed more than once. Temurin, Corretto and Zulu avoid the question entirely — they are free for personal, academic and commercial use with no registration. If you are unsure, take Temurin.
Installing on Windows, macOS and Linux
On Windows, download the Temurin MSI installer for JDK 17 or 21 and run it. On the components screen, turn on the option to add Java to the PATH and to set JAVA_HOME — both are off or partly off by default in some installers, and turning them on now saves the most common setup problem later. After the installer finishes, close every open terminal window and open a new one, because a terminal reads the environment once when it starts and will not see the change otherwise.
On macOS, the simplest route is Homebrew with the cask: brew install --cask temurin. This drops a normal macOS JDK package into place and the java and javac commands work immediately. You can also download the .pkg installer from adoptium.net and double-click it, which does the same thing.
On Linux, your distribution's package manager already has OpenJDK. On Ubuntu or Debian, sudo apt install openjdk-17-jdk installs both the compiler and runtime — note the -jdk at the end, because openjdk-17-jre is the runtime-only package. On Fedora the equivalent is sudo dnf install java-17-openjdk-devel, where -devel plays the same role as -jdk.
Whatever route you took, verify with the two commands below. Both must print a version. If java prints a version and javac says the command is not found, you have a JRE and not a JDK, or your PATH points at an old runtime.
# Windows: download the Temurin MSI from adoptium.net and run it.
# Tick "Set JAVA_HOME variable" and "Add to PATH".
# macOS (Homebrew)
brew install --cask temurin
# Ubuntu / Debian — note the -jdk suffix, not -jre
sudo apt update
sudo apt install openjdk-17-jdk
# Fedora / RHEL
sudo dnf install java-17-openjdk-devel
# Verify — BOTH of these must print a version
java --version
# openjdk 17.0.10 2026-01-16
javac --version
# javac 17.0.10 java -versionwith one dash also works and is what older tutorials use. The two-dash formjava --versionwas added in Java 9 and is the modern spelling. Either is fine.
PATH and JAVA_HOME — the Two Variables That Break Setups
Almost every "Java isn't working" question on the internet comes down to one of two environment variables, so it is worth understanding what each one is for instead of copying commands blindly.
PATH is a list of folders your operating system searches when you type a command name. When you type javac, the shell walks that list looking for a program with that name. If the JDK's bin folder is not on the list, you get 'javac' is not recognized as an internal or external command on Windows, or javac: command not found on macOS and Linux. The fix is to add the JDK's bin folder to PATH, not to reinstall Java.
JAVA_HOME points at the JDK folder itself — the folder that contains bin, not bin itself. Your own typing does not need it, but build tools do: Maven, Gradle, Android Studio and Tomcat all read JAVA_HOME to decide which JDK to use. Setting it wrong, or pointing it one level too deep at the bin folder, is a classic mistake that produces an error from Maven rather than from Java, which is why it is hard to trace.
On Windows you set both through Settings, in "Edit the system environment variables". On macOS and Linux you add the two lines below to your shell profile — ~/.zshrc for the default macOS shell, ~/.bashrc on most Linux systems — and then either restart the terminal or run source on that file.
# ---- macOS / Linux: add to ~/.zshrc or ~/.bashrc ----
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 # folder that CONTAINS bin
export PATH=$JAVA_HOME/bin:$PATH
# reload without restarting the terminal
source ~/.zshrc
# check
echo $JAVA_HOME
which java
# ---- Windows (PowerShell) — check what is currently set ----
$env:JAVA_HOME
# C:\Program Files\Eclipse Adoptium\jdk-17.0.10-hotspot
$env:PATH -split ';' | Select-String java
# WRONG — a very common mistake. JAVA_HOME must NOT include \bin
# JAVA_HOME = C:\Program Files\Eclipse Adoptium\jdk-17.0.10-hotspot\bin - If you have installed several JDKs over the years, PATH may still be finding an old one.
where javaon Windows andwhich -a javaon macOS or Linux list every match in order — the first one wins. Removing stale entries fixes more problems than reinstalling.
Proving the Install Works End to End
A version number tells you the tools exist. It does not tell you that compiling and running actually work in your folder. Do the full loop once, deliberately, so that when something breaks in a later lesson you know your setup is not the cause.
Create a folder for your practice code — avoid folder names with spaces or non-English characters while you are learning, since they occasionally confuse command-line tools. Inside it, create App.java with the code below, and note that the class is App so the file must be App.java. Then compile and run from that same folder.
The most common failure here is running java App from the wrong directory. The launcher looks for App.class in the current folder by default, so if you have moved elsewhere you get Error: Could not find or load main class App. Check with dir on Windows or ls elsewhere that App.class is really sitting where you are standing.
// File: App.java
public class App {
public static void main(String[] args) {
System.out.println("Java is running!");
System.out.println("Version: " + System.getProperty("java.version"));
// args holds whatever you typed after the class name
System.out.println("You passed " + args.length + " argument(s).");
for (String arg : args) {
System.out.println(" " + arg);
}
}
}
// javac App.java
// java App hello world
//
// Java is running!
// Version: 17.0.10
// You passed 2 argument(s).
// hello
// world Choosing an Editor, and Reading the Errors You Will Hit
You can write Java in Notepad, and doing it once is educational. For daily work use an editor that understands the language, because it will underline your mistakes as you type instead of making you run the compiler to find them. IntelliJ IDEA Community Edition is free and is what most Java teams use; Eclipse is free and common in colleges; VS Code with the Extension Pack for Java is lighter and fine for a course like this. Whichever you pick, the JDK still has to be installed separately — an editor does not include one.
Finally, the four errors below account for the large majority of setup problems. Learning to read them saves hours. Notice that each one names a different cause, so the message tells you exactly which of the earlier sections to go back to.
'javac' is not recognized/command not found— the JDK'sbinfolder is not on PATH, or you installed a JRE instead of a JDK.class App is public, should be declared in a file named App.java— your filename and public class name differ, including capitalisation.Error: Could not find or load main class App— you are in the wrong folder, or you typedjava App.classinstead ofjava App.UnsupportedClassVersionError ... class file version 61.0 ... recognizes up to 55.0— the code was compiled by a newer JDK than the one running it. Version 55 is Java 11 and 61 is Java 17. Either upgrade the runtime or compile withjavac --release 11.error: ';' expected— a missing semicolon, usually on the line above the one the compiler names.
- Compiler errors cascade: one missing brace can produce twenty error messages. Always fix the first error in the list and recompile before reading the rest, because the others are often only consequences of it.
