JDK
Windows
software installation
programming
Java development

How to find where the JDK is installed on Windows

Codemia Knowledge Hub ·

Open Command Prompt and run where javac. It prints the full path to the Java compiler, and the JDK root is the folder above bin. If that finds nothing, or you have several JDKs, use the other methods below.

Method 1: where javac in Command Prompt

Open Command Prompt (Win + R, type cmd, press Enter) and run:

batch
where javac

Example output:

 
C:\Program Files\Java\jdk-21\bin\javac.exe

The JDK directory is the parent of bin, here C:\Program Files\Java\jdk-21.

"INFO: Could not find files for the given pattern(s)" means javac is not on your PATH. Use one of the other methods.

Check the JDK version:

batch
javac -version
 
javac 21.0.2

And the runtime version:

batch
java -version
 
java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)

Method 2: the JAVA_HOME variable

Maven, Gradle, Tomcat and IntelliJ rely on JAVA_HOME to find the JDK. Check it:

batch
echo %JAVA_HOME%

A path like C:\Program Files\Java\jdk-21 is your JDK location.

To see all Java-related variables:

batch
set | findstr /i java

Example output:

 
JAVA_HOME=C:\Program Files\Java\jdk-21
Path=...;C:\Program Files\Java\jdk-21\bin;...

Setting JAVA_HOME if it is missing

Command Prompt (current session only):

batch
set JAVA_HOME=C:\Program Files\Java\jdk-21

PowerShell (permanent, current user):

powershell
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-21", "User")

System Settings (GUI):

  1. Press Win + S, search for "Environment Variables"
  2. Click "Edit the system environment variables"
  3. Click "Environment Variables"
  4. Under System variables, click "New"
  5. Variable name: JAVA_HOME
  6. Variable value: the path to your JDK (e.g., C:\Program Files\Java\jdk-21)

Method 3: PowerShell registry query

This lists every installed JDK version, whichever one is on PATH:

powershell
1Get-ChildItem "HKLM:\SOFTWARE\JavaSoft\JDK" -ErrorAction SilentlyContinue |
2  ForEach-Object { Get-ItemProperty $_.PSPath } |
3  Select-Object -Property @{N='Version';E={$_.PSChildName}}, JavaHome |
4  Format-Table -AutoSize

Example output:

 
1Version JavaHome
2------- --------
317.0.2  C:\Program Files\Java\jdk-17.0.2
421.0.2  C:\Program Files\Java\jdk-21

Method 4: Registry Editor

Open Registry Editor (Win + R, type regedit, press Enter) and go to:

Oracle JDK:

 
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

Older Oracle JDK (pre-JDK 9):

 
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit

Eclipse Adoptium (Temurin):

 
HKEY_LOCAL_MACHINE\SOFTWARE\Eclipse Adoptium\JDK

Amazon Corretto:

 
HKEY_LOCAL_MACHINE\SOFTWARE\Amazon.com\Corretto

Each version subfolder has a JavaHome value with the install directory.

Method 5: default install folders

For a manually extracted JDK or when nothing else works, list the usual locations:

batch
1dir "C:\Program Files\Java\" /b
2dir "C:\Program Files\Eclipse Adoptium\" /b
3dir "C:\Program Files\Amazon Corretto\" /b
4dir "C:\Program Files\Microsoft\jdk-*" /b
5dir "C:\Program Files\Zulu\" /b

Seeing which JDK is active

With multiple JDKs installed, this diagnostic script shows the active one and what is installed:

batch
1@echo off
2echo === Active Java ===
3where java 2>nul
4java -version 2>&1
5echo.
6echo === Active Javac ===
7where javac 2>nul
8javac -version 2>&1
9echo.
10echo === JAVA_HOME ===
11echo %JAVA_HOME%
12echo.
13echo === Installed JDKs in Program Files ===
14dir "C:\Program Files\Java" /b 2>nul
15dir "C:\Program Files\Eclipse Adoptium" /b 2>nul

Comparing the methods

MethodCommand / LocationFinds All VersionsWorks Without PATH
where javacCommand PromptNo (only first on PATH)No
echo %JAVA_HOME%Command PromptNo (only the configured one)Yes
PowerShell registry queryPowerShellYesYes
Registry EditorregeditYesYes
Directory listingFile Explorer / dirYesYes

Why you find the wrong JDK (or none)

  • Only a JRE is installed. The JRE has java.exe but not javac.exe, so where javac finds nothing. You need the full JDK to compile.
  • JAVA_HOME points to an old or removed version. After an upgrade it may still reference the previous one. Verify with "%JAVA_HOME%\bin\javac" -version.
  • PATH has several Java entries. Windows uses the first match. If C:\Program Files\Java\jdk-17\bin comes before jdk-21\bin, java -version reports 17 even though 21 is installed.
  • 32-bit vs 64-bit installs. On 64-bit Windows, 32-bit JDKs go to C:\Program Files (x86)\Java\. Check both Program Files folders.
  • The IDE uses its own JDK. IntelliJ, Eclipse and VS Code configure the JDK independently of JAVA_HOME. Check the project settings separately.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms