JDK
Windows
software installation
programming
Java development

How do I find where JDK is installed on my windows machine?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

To find where JDK is installed on Windows, the fastest method is to open Command Prompt and run where javac. This returns the full path to the Java compiler, and the JDK root is one directory above the bin folder. Below are all the reliable methods, including what to do when you have multiple JDK versions installed.

Method 1: Command Prompt (Fastest)

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 installation directory is the parent of bin, so in this case: C:\Program Files\Java\jdk-21

If you get "INFO: Could not find files for the given pattern(s)", it means javac is not on your system PATH, and you need to use one of the other methods below.

To check the version of the JDK you found:

batch
javac -version
 
javac 21.0.2

And to check 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: Check JAVA_HOME Environment Variable

Many Java tools (Maven, Gradle, Tomcat, IntelliJ) rely on JAVA_HOME to locate the JDK. Check if it is set:

batch
echo %JAVA_HOME%

If it returns a path like C:\Program Files\Java\jdk-21, that is your JDK location.

To see all Java-related environment variables at once:

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

Via Command Prompt (current session only):

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

Via PowerShell (permanent, for current user):

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

Via 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 One-liner

PowerShell can query the registry directly to find all installed JDK versions:

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

This method finds all JDK installations regardless of which one is on your PATH.

Method 4: Windows Registry (Manual)

Open Registry Editor (Win + R, type regedit, press Enter) and navigate 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 contains a JavaHome value pointing to the installation directory.

Method 5: Check Common Installation Directories

If the above methods do not work (e.g., a manually extracted JDK), check these default 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

Finding All Installed JDK Versions

When multiple JDKs are installed, it is important to know which one is active. Here is a quick diagnostic script you can run in Command Prompt:

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

Summary of 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

Common Pitfalls

  • where javac returns the JRE, not the JDK. If you only have a JRE installed, javac will not be found. The JRE contains java.exe but not javac.exe. You need the full JDK for compilation.
  • JAVA_HOME points to an old or uninstalled version. After upgrading Java, the environment variable may still reference the previous version. Always verify: "%JAVA_HOME%\bin\javac" -version.
  • PATH has multiple Java entries. Windows uses the first match. If C:\Program Files\Java\jdk-17\bin appears before jdk-21\bin in your PATH, java -version reports version 17 even though 21 is installed.
  • Confusing 32-bit and 64-bit installs. On 64-bit Windows, 32-bit JDKs install to C:\Program Files (x86)\Java\. If tools report an unexpected architecture, check both Program Files directories.
  • IDE uses a different JDK than the command line. IntelliJ, Eclipse, and VS Code each have their own JDK configuration that is independent of JAVA_HOME. Check your IDE's project settings separately.

Summary

  • The fastest way to find your JDK is where javac in Command Prompt, then look one directory above bin.
  • Check JAVA_HOME with echo %JAVA_HOME% since most build tools depend on it.
  • Use the PowerShell registry query to discover all installed JDK versions at once, regardless of which one is on PATH.
  • After finding your JDK, verify the version with javac -version to confirm it is the version you expect.
  • When multiple JDKs are installed, remember that PATH order determines which one java and javac resolve to by default.

Related reading
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
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.