Java Environment Setup on Windows – Install the JDK Step by Step
Before you can write and run Java programs, you need to install the Java Development Kit (JDK) and tell Windows where to find it. This guide walks you through every step on Windows 10 and Windows 11: downloading the JDK, installing it, setting the JAVA_HOME and PATH environment variables, verifying the installation, and running your first program.
The whole process takes about 10 minutes. The screenshots show an older JDK installer, but the steps are the same for current versions such as JDK 21 and JDK 25.
1. Choose a JDK
Java is free and open source (OpenJDK), and several vendors publish ready-to-install builds. Any of these works for learning and for production:
| Distribution | Provided by | Notes |
|---|---|---|
| Eclipse Temurin | Adoptium (Eclipse Foundation) | Popular, free, community-backed. A good default. |
| Oracle JDK | Oracle | Free under Oracle's licence terms for current releases. |
| Amazon Corretto | Amazon | Free, long-term support. |
| Microsoft Build of OpenJDK | Microsoft | Free, also available through winget. |
| Azul Zulu | Azul | Free community builds. |
Pick the latest LTS (Long-Term Support) version, such as JDK 21 or JDK 25, and the x64 MSI installer for Windows (or aarch64 on ARM laptops).
2. Download the Installer
- Open the download page of your chosen distribution, for example
adoptium.netfor Temurin. - Select Windows, your architecture (x64 for most PCs), package type JDK and the version.
- Download the
.msiinstaller and save it to your computer.
3. Install the JDK
- Double-click the downloaded installer. The setup wizard opens.
- Click Next on the welcome screen.
- Keep the default folder, usually
C:\Program Files\Java\jdk-21orC:\Program Files\Eclipse Adoptium\jdk-21…, or choose another one. Remember this path. - Temurin and some other installers offer to set JAVA_HOME and add to PATH for you. Enable both options; you can then skip the JAVA_HOME and PATH sections below.
- Click Install, wait, and then click Close.
4. Set the JAVA_HOME Variable
JAVA_HOME tells tools such as Maven, Gradle and IDEs where the JDK lives.
- Open File Explorer, go to the JDK folder and copy its path, for example
C:\Program Files\Java\jdk-21(the folder that containsbin). - Press Windows, type environment variables, and open Edit the system environment variables.
- Click Environment Variables….
- Under System variables, click New….
- Variable name:
JAVA_HOME. Variable value: the JDK path you copied. Click OK.
5. Add Java to the PATH
The PATH variable lets you run java and javac from any folder in the command prompt.
- In the same System variables list, select Path and click Edit….
- Click New and enter
%JAVA_HOME%\bin. - Use Move Up to place it above any other Java entries (for example, an old
javapathentry), so this JDK is found first. - Click OK in all open windows.
6. Verify the Installation
Open a new Command Prompt (Windows + R, type cmd, press Enter) and run:
java -version
javac -version
echo %JAVA_HOME%
You should see output similar to this (vendor and version numbers will differ):
openjdk version "21.0.7" 2025-04-15 LTS OpenJDK Runtime Environment Temurin-21.0.7+6 (build 21.0.7+6-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.7+6 (build 21.0.7+6-LTS, mixed mode, sharing) javac 21.0.7 C:\Program Files\Java\jdk-21
7. Compile and Run Your First Program
- Create a folder such as
C:\java-practice. - Create a file named
SetupCheck.javawith this code (the file name must match the class name):
public class SetupCheck {
public static void main(String[] args) {
System.out.println("Java is installed and working!");
System.out.println("Running on Java " + Runtime.version().feature());
}
}
cd C:\java-practice
javac SetupCheck.java # creates SetupCheck.class
java SetupCheck # runs the program
java SetupCheck.java # Java 11+: compile and run in one step
Java is installed and working! Running on Java 21
The second line shows the feature version of your JDK, so it may print 25 or another number on your computer.
8. Faster Option: Install with winget
Windows 10 (1809+) and Windows 11 include the winget package manager. One command installs a JDK and sets up the paths:
winget search "JDK"
winget install EclipseAdoptium.Temurin.21.JDK
Open a new terminal afterwards and run java -version to confirm.
9. Installing on macOS and Linux
| System | Command |
|---|---|
| macOS (Homebrew) | brew install --cask temurin@21 |
| Ubuntu / Debian | sudo apt install openjdk-21-jdk |
| Fedora / RHEL | sudo dnf install java-21-openjdk-devel |
| Any OS (SDKMAN!) | sdk install java 21-tem, which can also switch between versions |
10. Install an IDE (Optional)
You can write Java in any text editor, but an IDE adds auto-completion, error highlighting, debugging and one-click running:
- IntelliJ IDEA Community Edition: the most popular Java IDE, free.
- Eclipse IDE for Java Developers: free and open source.
- Visual Studio Code with the "Extension Pack for Java": lightweight and free.
Most IDEs detect your JDK automatically through JAVA_HOME, and some can download a JDK for you.
11. Troubleshooting Common Problems
| Problem | Cause and fix |
|---|---|
'javac' is not recognized as an internal or external command | %JAVA_HOME%\bin is missing from PATH, or the terminal was opened before you changed it. Fix the path and open a new terminal. |
java -version shows an old version | Another Java entry appears earlier in PATH (often C:\Program Files\Common Files\Oracle\Java\javapath). Move %JAVA_HOME%\bin to the top. |
JAVA_HOME points to the wrong folder | It must point to the JDK root folder (the one containing bin), not to bin itself. |
Error: Could not find or load main class | Run java from the folder containing the .class file, and use the class name without .class. |
class X is public, should be declared in a file named X.java | Rename the file to match the public class name exactly, including capital letters. |
UnsupportedClassVersionError | The class was compiled with a newer JDK than the one running it. Run it with the same or a newer Java version. |
12. Summary
- Download a JDK (for example Eclipse Temurin, latest LTS) as an x64 MSI installer.
- Install it and note the folder.
- Set
JAVA_HOMEto the JDK folder and add%JAVA_HOME%\bintoPATH. - Open a new terminal and check
java -versionandjavac -version. - Compile with
javac, run withjava, or usejava File.javafor single files.
Related Tutorials
Reference: Eclipse Adoptium: Installation on Windows
Frequently Asked Questions (FAQ)
Q1. Which Java version should I install?
Install the latest Long-Term Support (LTS) release, such as JDK 21 or JDK 25. LTS versions receive updates for years and are what most companies and courses use.
Q2. Do I need the JDK or the JRE?
To write and compile programs you need the JDK, which includes the compiler javac. Since Java 11 there is no separate JRE download; the JDK contains everything needed to run programs too.
Q3. Is Java free to download?
Yes. OpenJDK builds such as Eclipse Temurin, Amazon Corretto, Microsoft Build of OpenJDK and Azul Zulu are free for any use. Oracle JDK is also free under its current licence terms for recent releases.
Q4. What is JAVA_HOME and why do I need it?
JAVA_HOME is an environment variable that points to the JDK installation folder. Build tools such as Maven and Gradle, application servers and IDEs use it to find Java.
Q5. What is the difference between JAVA_HOME and PATH?
JAVA_HOME points to the JDK root folder for tools that need to know where Java is. PATH lists folders Windows searches for commands; adding %JAVA_HOME%\bin lets you type java and javac anywhere.
Q6. Why do I get "'javac' is not recognized"?
Windows cannot find javac.exe. Either %JAVA_HOME%\bin is not in PATH, JAVA_HOME points to the wrong folder, or you are using a terminal opened before you made the changes. Fix the variables and open a new terminal.
Q7. How do I check if Java is installed on Windows?
Open Command Prompt and run java -version and javac -version. If both print a version number, the JDK is installed and on your PATH.
Q8. Do I need to restart my computer after setting environment variables?
No. You only need to close and reopen your terminal or IDE so that it reads the new values.
Q9. Should I choose the x64 or x86 installer?
Choose x64 for almost all modern Windows PCs. Use the aarch64 (ARM64) build for ARM-based Windows laptops. 32-bit (x86) builds are only needed for very old systems.
Q10. Can I install more than one Java version?
Yes. Install each JDK in its own folder and point JAVA_HOME and PATH to the one you want to use. Tools such as SDKMAN! (on macOS/Linux/WSL) or IDE settings make switching easier.
Q11. What is the classpath, and do I need to set it?
The classpath tells the JVM where to find your compiled classes and libraries. You usually do not need to set a CLASSPATH variable; Java uses the current folder by default, and build tools manage dependencies for you.
Q12. How do I uninstall an old Java version?
Open Settings → Apps → Installed apps, find the old Java or JDK entry and uninstall it. Then remove any outdated entries from the PATH variable.
Q13. Why does java -version show a different version from javac -version?
Two different Java installations are being found. An older java.exe (often from a javapath folder) appears earlier in PATH. Move %JAVA_HOME%\bin to the top of the list.
Q14. Can I run a Java file without compiling it first?
Yes, since Java 11 you can run a single-file program with java MyProgram.java. Java compiles it in memory and runs it. Larger projects still use javac or a build tool.
Q15. What does "Could not find or load main class" mean?
The JVM could not find the class you named. Make sure you are in the folder containing the .class file, that the name matches exactly (case-sensitive), that you did not add .class, and that you include the package name if the class is in a package.
Q16. Do I need an IDE to learn Java?
No, a text editor and the command line are enough, and they help you understand compiling and running. An IDE such as IntelliJ IDEA, Eclipse or VS Code becomes very useful as programs grow.
Q17. How do I install Java with winget?
Run winget install EclipseAdoptium.Temurin.21.JDK (or another JDK package found with winget search JDK) in a terminal, then open a new terminal and check java -version.
Q18. What is UnsupportedClassVersionError?
It means the class file was compiled for a newer Java version than the JVM running it. Run it with a newer JDK, or compile with javac --release <version> to target an older one.
Q19. Where is Java installed on Windows by default?
Usually under C:\Program Files\Java\, or under the vendor's folder such as C:\Program Files\Eclipse Adoptium\ for Temurin. Each version gets its own subfolder.
Q20. Does Java work on Windows 11?
Yes. All current JDK builds support Windows 11, and the installation steps are exactly the same as on Windows 10.