How to Check Java Version in Command Prompt (Windows)

Open Windows Command Prompt (Win+R β†’ type cmd β†’ Enter) and run java -version. It prints the installed version in one second.

The command

java -version

Expected output:

openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (mixed mode, sharing)

"java is not recognized" β€” what to do

This error means Java is not installed or not on PATH. Check both:

1. Is Java installed?

dir "C:\Program Files\Java"
dir "C:\Program Files\Eclipse Adoptium"

If these directories exist, Java is installed but not on PATH.

2. Open a new cmd window. If you installed Java while this window was open, it will not see the updated PATH. Always open a fresh Command Prompt after installing.

3. Check PATH manually:

echo %PATH%

Look for a path ending in \bin that points to a JDK directory. If missing, add it.

Add Java to PATH manually

  1. Find the JDK path (e.g. C:\Program Files\Eclipse Adoptium\jdk-21.0.2.13-hotspot)
  2. Open System Properties β†’ Advanced β†’ Environment Variables
  3. Under System variables, find Path and click Edit
  4. Click New and add: C:\Program Files\Eclipse Adoptium\jdk-21.0.2.13-hotspot\bin
  5. Click OK everywhere, then open a new Command Prompt and retry

Check JAVA_HOME

echo %JAVA_HOME%

If it prints nothing, JAVA_HOME is not set. Maven, Gradle, and some IDEs need it. Set it via Environment Variables β†’ System variables β†’ New: name JAVA_HOME, value the JDK directory (without \bin).

Check which java is used

where java

This lists all java.exe files on PATH in priority order. The first one is what runs. If you have multiple JDKs and the wrong one is first, reorder PATH entries in Environment Variables or change JAVA_HOME.

PowerShell alternative

java -version
$env:JAVA_HOME
where.exe java