Lesson 2 of 20
Installing Java and the JDK
Install a Java Development Kit, verify the compiler and runtime, and run a small program from the terminal.
Learning objectives
- Choose an appropriate JDK for learning Java.
- Install the JDK on Windows, macOS, or Linux.
- Verify the
javaandjavaccommands. - Understand the purpose of
JAVA_HOMEandPATH. - Compile and run a verification program.
1. Choosing a JDK in 2026
As of 2026, Java 26 is the current feature release and Java 25 is the latest Long-Term Support (LTS) release. For this beginner tutorial, JDK 25 LTS is a sensible baseline because it is stable and intended for longer support. You may also use another compatible modern JDK if required by your school or workplace.
Download Java from a trusted distribution such as Oracle JDK or a reputable OpenJDK distribution. Avoid unknown third-party download sites.
2. Install the JDK
On Windows, run the installer and accept the default development tools. On macOS, use the package installer provided by your JDK distribution. On Linux, you may use your distribution's package manager or a vendor package.
Example: verify the installation
java -version
javac -version
The first command checks the Java launcher. The second checks the Java compiler. Both should report an installed version instead of an error such as 'java' is not recognized.
3. Understanding PATH and JAVA_HOME
PATH tells your operating system where to find commands such as java and javac. JAVA_HOME is an environment variable that many Java tools use to locate the JDK installation directory.
Example: inspect JAVA_HOME
// Windows Command Prompt
echo %JAVA_HOME%
// PowerShell
$env:JAVA_HOME
// macOS or Linux shell
echo $JAVA_HOME
4. Test the complete toolchain
Create a folder named java-practice. Inside it, create JdkCheck.java.
public class JdkCheck {
public static void main(String[] args) {
System.out.println("The Java development kit is working.");
System.out.println("Java version: " + System.getProperty("java.version"));
System.out.println("Operating system: " + System.getProperty("os.name"));
}
}
Compile and run
javac JdkCheck.java
java JdkCheck
Expected output
The Java development kit is working.
Java version: 25...
Operating system: Windows 11
Your exact version and operating-system text may differ. The important result is that the program compiles and runs successfully.
Common installation problems
| Problem | Why it happens | How to fix it |
|---|---|---|
java works but javac does not | A runtime or incorrect PATH may be installed instead of a full JDK. | Install a JDK and ensure its bin folder is on PATH. |
| Terminal still reports the old Java version | The terminal inherited an older PATH. | Close and reopen the terminal, then run where java on Windows or which java on macOS/Linux. |
JAVA_HOME points to bin | JAVA_HOME should normally point to the JDK root folder. | Set JAVA_HOME to the JDK folder, not the bin subfolder. |
Practice task
Modify JdkCheck.java to also print user.name and user.dir using System.getProperty.
Summary
You now have the compiler and runtime needed for the rest of the course. You also know how to verify Java from the terminal and diagnose the most common PATH problems. In Lesson 3, you will configure Visual Studio Code for Java development.