How to Install Java on Windows: A Step-by-Step Guide for Beginners

Java is a powerful and versatile programming language used for everything from web applications to Android development. To start coding in Java on a Windows system, you need to install the Java Development Kit (JDK), which provides the tools to write, compile, and run Java programs. For beginners, setting up Java on Windows is a critical first step to kickstart your programming journey. This blog offers a detailed, step-by-step guide to installing Java on Windows, covering the JDK installation, environment variable configuration, and verification process. With clear explanations and practical examples, you’ll be ready to run your first Java program, like the Hello World program, in no time. Let’s get started with installing Java on Windows and setting up your development environment!

Why Install Java on Windows?

Windows is one of the most widely used operating systems, making it a popular choice for learning and developing Java applications. Installing Java on Windows allows you to:

  • Develop Java Programs: Write, compile, and debug code using the JDK’s tools.
  • Run Java Applications: Execute Java-based software, such as IDEs, games, or servers, using the Java Runtime Environment (JRE).
  • Explore Java Ecosystems: Work with frameworks like Spring, Hibernate, or JavaFX for enterprise and desktop applications.
  • Learn Programming: Practice Java fundamentals, from data types to object-oriented programming.

This guide focuses on installing OpenJDK, a free and open-source implementation of the JDK, ideal for most development needs. For a broader overview of Java installation across platforms, see the Java Installation Guide.

Understanding Java Components

Before installing, let’s clarify the key components involved:

  • Java Development Kit (JDK): Includes the Java compiler (javac), Java Virtual Machine (JVM), JRE, and development tools for creating Java applications.
  • Java Runtime Environment (JRE): Contains the JVM and libraries to run Java programs but lacks development tools. The JDK includes the JRE, so installing the JDK is sufficient for development.
  • JVM: Executes Java bytecode, ensuring platform independence.

For coding, you need the JDK. For a detailed comparison, see JVM vs. JRE vs. JDK.

Choosing a JDK Version

Java releases new versions every six months, with Long-Term Support (LTS) versions receiving updates for years. As of June 8, 2025, Java 21 is the latest LTS version, offering stability and modern features like virtual threads. For beginners, an LTS version like Java 21 is recommended for compatibility and support.

You can choose between:

  • OpenJDK: Free, open-source, and community-maintained. Distributions like Adoptium (Temurin) are reliable and widely used.
  • Oracle JDK: The official version, free for development but requiring a commercial license for production use. OpenJDK is sufficient for most purposes.

This guide uses Adoptium’s Temurin OpenJDK 21 for its ease of installation and open-source nature.

Prerequisites

Ensure your Windows system is ready:

  • Windows Version: This guide targets Windows 10 or 11 (64-bit). Most steps apply to older versions, but interface details may differ.
  • Internet Connection: Required to download the JDK installer.
  • Administrative Privileges: Needed to install software and modify system settings.
  • Disk Space: At least 500 MB for the JDK, plus space for your projects.

Installing OpenJDK on Windows

Adoptium provides a user-friendly installer for OpenJDK. Follow these steps to install Java 21 on Windows.

Step 1: Download the JDK

  1. Visit the Adoptium website.
  2. Select Temurin 21 (LTS) from the version options.
  3. Choose Windows as the operating system and x64 as the architecture (most modern PCs are 64-bit).
  4. Click the Download button for the .msi installer (e.g., OpenJDK21U-jdk_x64_windows_hotspot_21.0.1_12.msi).
  5. Save the installer to a known location (e.g., Downloads folder).

Step 2: Run the Installer

  1. Double-click the downloaded .msi file to launch the installer.
  2. Follow the installation wizard:
    • Welcome Screen: Click Next.
    • License Agreement: Accept the terms and click Next.
    • Custom Setup: Choose the default features, including:
      • Java SE Development Kit: Core JDK components.
      • Set JAVA_HOME variable: Automatically configures JAVA_HOME (recommended).
      • Associate .jar files: Optional, allows running .jar files by double-clicking.
    • Installation Path: Accept the default (e.g., C:\Program Files\Eclipse Adoptium\jdk-21.0.1.12-hotspot) or choose a custom location.

3. Click Install to begin installation. Enter your admin password if prompted. 4. Wait for the process to complete, then click Finish to exit the wizard.

Step 3: Verify the Installation

Open a Command Prompt to confirm Java is installed: 1. Press Win + R, type cmd, and press Enter. 2. Run the following commands:

java -version
   javac -version

Expected output:

openjdk 21.0.1 2023-10-10
OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12)
OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12, mixed mode)
javac 21.0.1
  • java -version: Verifies the JRE and JVM.
  • javac -version: Confirms the compiler is installed.
  • If both commands show version details, the installation is successful.

Step 4: Troubleshooting Installation

If the commands fail:

  • “‘java’ is not recognized”: The JDK’s bin folder may not be in the system PATH. Proceed to configure environment variables (below).
  • Installer Failure: Ensure you have admin rights and sufficient disk space. Re-download the installer if corrupted.
  • Wrong Version: Verify you downloaded Java 21 (LTS). Uninstall and reinstall if needed.

Configuring Environment Variables

To run Java commands (java, javac) from any directory, configure JAVA_HOME and update the PATH environment variable. The Adoptium installer may set these automatically, but verifying or manually configuring ensures correctness.

Step 1: Locate the JDK Path

The JDK is typically installed at:

C:\Program Files\Eclipse Adoptium\jdk-21.0.1.12-hotspot

Confirm the path by checking the installation directory in File Explorer.

Step 2: Set JAVA_HOME

  1. Open the System Properties:
    • Right-click This PC (or My Computer) in File Explorer and select Properties.
    • Click Advanced system settings (on the left).
    • In the System Properties window, click the Environment Variables button.

2. Create or edit JAVA_HOME:


  • Under System Variables, click New (or select JAVA_HOME and click Edit if it exists).
  • Set Variable name: JAVA_HOME
  • Set Variable value: C:\Program Files\Eclipse Adoptium\jdk-21.0.1.12-hotspot
  • Click OK.

3. Click OK to close the Environment Variables window.

Step 3: Update PATH

Add the JDK’s bin folder to the PATH: 1. In the Environment Variables window, under System Variables, find and select Path, then click Edit. 2. Click New and add:

%JAVA_HOME%\bin
  1. Click OK to close all dialogs.

Step 4: Verify Configuration

Open a new Command Prompt (close any open ones to apply changes) and run:

echo %JAVA_HOME%
java -version
javac -version

Expected output for JAVA_HOME:

C:\Program Files\Eclipse Adoptium\jdk-21.0.1.12-hotspot

If java or javac still fail, double-check:

  • The JAVA_HOME path is correct (no trailing spaces or typos).
  • %JAVA_HOME%\bin is in the Path variable.
  • Restart the Command Prompt or your computer to apply changes.

Step 5: Troubleshooting Environment Variables

  • Incorrect JAVA_HOME: If echo %JAVA_HOME% shows a wrong path, re-edit the variable in System Properties.
  • PATH Issues: Ensure %JAVA_HOME%\bin is listed exactly, without quotes or extra characters.
  • Multiple JDKs: If another Java version is detected, remove conflicting paths from Path or uninstall old versions via Settings > Apps.

Testing Your Installation with a Hello World Program

To confirm your setup, write and run a simple Java program.

Step 1: Create the Program

  1. Create a project directory:
    • Open File Explorer, create a folder (e.g., C:\JavaProjects).
    • Navigate to it:
    • cd C:\JavaProjects

2. Create a file named HelloWorld.java:


  • Open a text editor (e.g., Notepad, VS Code).
  • Paste the following code:
  • public class HelloWorld {
             public static void main(String[] args) {
                 System.out.println("Hello, Java on Windows!");
             }
         }
  • Save the file as HelloWorld.java in C:\JavaProjects. Ensure the extension is .java, not .txt.

3. For a detailed explanation, see Hello World Program.

Step 2: Compile and Run

In Command Prompt, navigate to the project directory:

cd C:\JavaProjects

Compile the program:

javac HelloWorld.java

This creates HelloWorld.class in the same directory.

Run the program:

java HelloWorld

Output:

Hello, Java on Windows!

Step 3: Troubleshooting

  • “File not found”: Ensure you’re in C:\JavaProjects and HelloWorld.java exists (dir to list files).
  • “Main class not found”: Verify the class name matches (java HelloWorld, not java helloworld).
  • Compilation Errors: Check for typos (e.g., missing semicolon, incorrect class name).

Setting Up a Development Environment

With Java installed, choose a tool for coding:

  • Text Editors: Notepad++, VS Code with the Java Extension Pack, or Sublime Text.
  • IDEs: IntelliJ IDEA Community Edition, Eclipse, or NetBeans provide code completion, debugging, and project management.

To install VS Code: 1. Download from code.visualstudio.com. 2. Run the installer and follow the prompts. 3. Open VS Code, go to Extensions (Ctrl+Shift+X), and install the Java Extension Pack. 4. Open your C:\JavaProjects folder in VS Code to start coding.

For IntelliJ IDEA: 1. Download the Community Edition from jetbrains.com. 2. Install and create a new Java project, pointing to your JDK path.

Managing Multiple Java Versions (Optional)

If you need multiple JDKs (e.g., Java 17 and 21): 1. Install additional versions via separate installers. 2. Update JAVA_HOME and Path to point to the desired version. 3. Use tools like SDKMAN! (via WSL) or manually switch paths in System Properties.

To check installed versions:

dir "C:\Program Files\Eclipse Adoptium"

Uninstalling Java (Optional)

To remove Java: 1. Go to Settings > Apps > Installed Apps. 2. Search for “Temurin” or “OpenJDK,” select it, and click Uninstall. 3. Remove JAVA_HOME and %JAVA_HOME%\bin from Environment Variables if set manually.

FAQ

Do I need both JDK and JRE on Windows?

No, the JDK includes the JRE. Installing the JDK provides all tools for development and running Java programs.

Which Java version should I install on Windows?

Choose an LTS version like Java 21 for stability and support. Java 17 is also viable for compatibility with older tools.

Why is javac not recognized after installation?

The JDK’s bin folder may not be in the Path. Add %JAVA_HOME%\bin to the system Path in Environment Variables and restart the Command Prompt.

Can I use Oracle JDK instead of OpenJDK?

Yes, but OpenJDK is free and sufficient for most development. Oracle JDK requires a commercial license for production use. Download it from oracle.com.

What if I have multiple Java versions installed?

Set JAVA_HOME and Path to the desired version in System Properties. Remove conflicting paths to avoid version mismatches.

Conclusion

Installing Java on Windows is a straightforward process that prepares you to develop and run Java applications. By installing OpenJDK (Temurin), configuring environment variables, and testing with a Hello World program, you’ve established a robust development environment. Continue your learning by exploring Java concepts like variables, control flow statements, or arrays. With Java set up on your Windows system, you’re ready to code, experiment, and build exciting Java projects!