Install Java on Windows
Introduction
This chapter walks you through installing the JDK (Java Development Kit) on Windows in a clean, repeatable way. You will download a modern LTS release, configure JAVA_HOME and PATH, and verify that both java and javac work. Getting this right early prevents many “command not found” and version-mismatch problems in later chapters.
Prerequisites
- Windows 10 or Windows 11
- Local administrator permissions (recommended for system-wide install)
- Basic familiarity with PowerShell or Command Prompt
- Stable internet connection to download the installer
JDK vs JRE: What You Need
- JDK (Java Development Kit): includes the compiler (
javac), standard libraries, and tools to build and run Java programs. Install this for learning and development. - JRE (Java Runtime Environment): can run Java applications but does not include
javac. A JDK already includes a runtime; you do not need a separate JRE for this tutorial.
If java -version works but javac is not recognized, you likely installed a runtime-only package or an incomplete setup.
Choose the Right Java Version
For new learning projects, use a modern LTS (Long-Term Support) release:
| Version | Status | Recommendation |
|---|---|---|
| Java 21 | LTS | Recommended default for this tutorial |
| Java 17 | LTS | Fine if your team or course requires it |
| Java 8 or older | Legacy | Avoid for new installs unless you have a specific compatibility requirement |
Match your team or textbook version when working on shared projects. Installing an old JDK “because a blog said so” often causes unnecessary confusion when examples use newer language features.
Install JDK 21 on Windows
Option A: Eclipse Temurin (Adoptium) — Recommended
Eclipse Temurin provides free, widely used OpenJDK builds.
- Open adoptium.net and download Temurin 21 (LTS) for Windows x64 (
.msiinstaller). - Run the installer.
- On the setup screen, enable options such as:
- Set JAVA_HOME variable
- Add to PATH (or “JavaSoft registry keys” / PATH integration, depending on installer version)
- Complete installation and close and reopen your terminal (or IDE) so PATH changes take effect.
Default install location (typical):
C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot\Option B: Oracle JDK — Alternative
Download JDK 21 from Oracle Java downloads if your organization standard requires Oracle’s distribution. Follow the Windows installer and note the installation directory for JAVA_HOME.
Configure JAVA_HOME and PATH (If Not Set by Installer)
Some installers set everything automatically. If javac is still not found, configure environment variables manually.
- Press
Win + S, search Environment Variables, open Edit the system environment variables. - Click Environment Variables…
- Under System variables (or User variables for a per-user setup), click New:
- Variable name:
JAVA_HOME - Variable value: your JDK root folder, e.g.
C:\Program Files\Eclipse Adoptium\jdk-21.0.6.7-hotspot(use your actual path)
- Variable name:
- Edit Path and add:
%JAVA_HOME%\bin
- Click OK on all dialogs, then open a new terminal window.
Tip
Best Practice
Point JAVA_HOME at the JDK root directory (the folder that contains bin, lib, etc.), not at bin itself. Tools such as Maven and Gradle expect this convention.
Verify Installation
PowerShell
java -version
javac -version
echo $env:JAVA_HOMECommand Prompt
java -version
javac -version
echo %JAVA_HOME%If echo %JAVA_HOME% prints %JAVA_HOME% unchanged, the variable is not set—revisit the environment variable steps above and open a new terminal.
Expected outcome:
- Both
javaandjavacprint version 21 (or your chosen LTS), not “not recognized” JAVA_HOMEpoints to your JDK installation folder
Example output (versions may differ slightly):
openjdk version "21.0.6" 2025-01-21 LTS
OpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing)Common Issues and Fixes
java is not recognized
- Likely cause: JDK
binis not onPATH, or the terminal was not restarted after install. - Fix:
- Confirm the JDK is installed under
Program Files(or your chosen path). - Add
%JAVA_HOME%\bintoPATH(see above). - Close all terminal windows and open a new one.
- Run
java -versionagain.
- Confirm the JDK is installed under
java works but javac is not recognized
- Likely cause: Only a JRE is installed, or
PATHpoints to the wrong folder. - Fix: Install a full JDK 21, ensure
%JAVA_HOME%\binis onPATH, and verifyjavac.exeexists in%JAVA_HOME%\bin.
Wrong version appears (e.g. Java 8)
- Likely cause: An older JDK or bundled Java is earlier on
PATH. - Fix:
- Run
where javain Command Prompt (orGet-Command javain PowerShell) to see which executable is used. - Remove outdated Java entries from
PATH, or move your JDK 21binentry above them. - Set
JAVA_HOMEto JDK 21 explicitly.
- Run
Installer succeeded but IDE still uses old Java
- Likely cause: The IDE was open during install, or it has its own JDK setting.
- Fix: Restart the IDE. In IntelliJ IDEA, check File → Project Structure → SDK after you install an editor in a later chapter.
What’s Next
With JDK 21 installed and verified, you can compile and run Java from the terminal. The next chapters cover installation on macOS and Linux, then your first Hello World program without an editor.
FAQ
Should I install Java from random download sites?
No. Prefer Adoptium or Oracle’s official downloads. Unofficial bundles may bundle unwanted software or outdated runtimes.
Is Java 21 safe to use for learning if my school teaches Java 8?
For new personal practice, Java 21 is a better default. For graded coursework, follow your instructor’s required version. Core syntax is largely the same; differences appear mainly in newer APIs and language features introduced after Java 8.
Do I need to set JAVA_HOME on Windows?
Many installers set it for you. Setting it manually is still useful: build tools and IDEs read JAVA_HOME to locate the JDK consistently.
Can I have multiple Java versions installed?
Yes. Use JAVA_HOME and PATH to select which JDK is active, or rely on IDE/project settings per project. Avoid mixing global CLASSPATH hacks unless you know why you need them.
What is the difference between java and javac?
javac compiles .java source files into .class bytecode. java runs bytecode on the JVM. You need both for the compile-then-run workflow in the next Hello World chapter.