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:

VersionStatusRecommendation
Java 21LTSRecommended default for this tutorial
Java 17LTSFine if your team or course requires it
Java 8 or olderLegacyAvoid 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

Eclipse Temurin provides free, widely used OpenJDK builds.

  1. Open adoptium.net and download Temurin 21 (LTS) for Windows x64 (.msi installer).
  2. Run the installer.
  3. 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)
  4. Complete installation and close and reopen your terminal (or IDE) so PATH changes take effect.

Default install location (typical):

text
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.

  1. Press Win + S, search Environment Variables, open Edit the system environment variables.
  2. Click Environment Variables…
  3. 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)
  4. Edit Path and add:
    • %JAVA_HOME%\bin
  5. 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

powershell
java -version
javac -version
echo $env:JAVA_HOME

Command Prompt

bat
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 java and javac print version 21 (or your chosen LTS), not “not recognized”
  • JAVA_HOME points to your JDK installation folder

Example output (versions may differ slightly):

text
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 bin is not on PATH, or the terminal was not restarted after install.
  • Fix:
    1. Confirm the JDK is installed under Program Files (or your chosen path).
    2. Add %JAVA_HOME%\bin to PATH (see above).
    3. Close all terminal windows and open a new one.
    4. Run java -version again.

java works but javac is not recognized

  • Likely cause: Only a JRE is installed, or PATH points to the wrong folder.
  • Fix: Install a full JDK 21, ensure %JAVA_HOME%\bin is on PATH, and verify javac.exe exists in %JAVA_HOME%\bin.

Wrong version appears (e.g. Java 8)

  • Likely cause: An older JDK or bundled Java is earlier on PATH.
  • Fix:
    1. Run where java in Command Prompt (or Get-Command java in PowerShell) to see which executable is used.
    2. Remove outdated Java entries from PATH, or move your JDK 21 bin entry above them.
    3. Set JAVA_HOME to JDK 21 explicitly.

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.