What Version of Java Do I Have?

Run java -version in any terminal — it works on Windows, Mac and Linux. The first number in the output is your major Java version.

One-command answer

java -version

Reading the output

Output starts withJava versionStatus (2026)
java version "1.8.x"Java 8Extended support ends 2030 (Oracle). Free LTS from some vendors.
openjdk version "11.x"Java 11End of most free support 2027. Migrate.
openjdk version "17.x"Java 17LTS, actively supported until 2029+.
openjdk version "21.x"Java 21Current recommended LTS. Full support to 2031+.
openjdk version "25.x"Java 25Newest LTS (Sept 2025).

Why does it say "1.8" instead of "8"?

Java 8 and older used a 1.x versioning scheme: Java 1.0, 1.1, …, 1.4, 1.5, 1.6, 1.7, 1.8. Starting with Java 9 (2017), Oracle switched to simple major version numbers: 9, 10, 11, 17, 21. So 1.8.x is Java 8, and any version number above 8 is what it says.

What if java -version fails?

  • "command not found" / "not recognized" — Java is not installed or not on PATH. Install Java.
  • Wrong version prints — multiple JDKs are installed. Run where java (Windows) or which java (Mac/Linux) to see which one is active. Change JAVA_HOME and PATH to switch.

Check the Java version from inside a Java program

// Works in any Java version:
System.out.println(System.getProperty("java.version"));
// Java 9+:
System.out.println(Runtime.version().feature()); // prints just the major version (21)

Check the version your build tool expects

Your code's minimum Java version is declared in the build file:

<!-- Maven pom.xml -->
<properties>
  <maven.compiler.source>21</maven.compiler.source>
  <maven.compiler.target>21</maven.compiler.target>
</properties>
// Gradle build.gradle
java {
    toolchain { languageVersion = JavaLanguageVersion.of(21) }
}