Find your Java version in three commands

The fastest way to check your Java version is to open a terminal or command prompt and run a single command. Java stores its version information where your system can read it instantly, so you do not need to dig through settings or files. The command you use depends on what you need to know — whether you want the version number alone or more detailed information about your installation.

Most people need just one command: java -version. This works on Windows, Mac, and Linux, and it shows you the version number in the first line of output. If you are working with Java development tools, you might also need to check the compiler version separately using javac -version.

Key Takeaways

  • Run java -version in your terminal or command prompt to see which Java runtime version is installed on your computer.
  • The output shows the version number in the first line, usually formatted as something like "java version 17.0.1" or "openjdk version 11.0.13".
  • If you develop Java programs, run javac -version separately to check your compiler version, which may differ from your runtime version.
  • On Windows, you may need to use the full path to Java or add it to your system PATH before the command works.
  • Different Java distributions (Oracle JDK, OpenJDK, Amazon Corretto) display version information slightly differently but all respond to the same commands.

Running the command on Windows

Open Command Prompt by pressing the Windows key, typing cmd, and pressing Enter. Type java -version and press Enter. If Java is installed and set up correctly, you will see output that starts with a line like "java version 17.0.1" or "openjdk version 11.0.13".

If you see an error message saying "java is not recognized as an internal or external command", Java is either not installed or not added to your system PATH. You can still check by typing the full path to Java. On most Windows systems, this is C:\Program Files\Java\jdk-17\bin\java -version (replace the version number with whatever you have installed). If that works, you know Java is installed but your PATH needs updating.

Running the command on Mac and Linux

Open Terminal. On Mac, press Command + Space, type terminal, and press Enter. On Linux, use your system's application menu or press Ctrl + Alt + T. Type java -version and press Enter. The output appears immediately below your command.

If you see "command not found", Java is not installed or not in your PATH. You can check common installation locations by typing which java, which shows the full path to the Java executable if it exists. On Mac, Java is often installed in /Library/Java/JavaVirtualMachines/ if you installed it manually.

Understanding the version output

The first line of output tells you the version number. You might see "java version 17.0.1" (Oracle JDK), "openjdk version 11.0.13" (OpenJDK), or "amazon-corretto-17.0.1" (Amazon Corretto). The number after "version" is what matters — in these examples, that is 17.0.1, 11.0.13, and 17.0.1 respectively.

The second and third lines show the vendor (who built this Java distribution) and the build number. The vendor line tells you whether you have Oracle's official JDK, the open-source OpenJDK, or a third-party build like Amazon Corretto or Azul Zulu. If you are troubleshooting a problem, the vendor and build number help you find the right documentation or support resources.

Checking your compiler version separately

If you write Java code, you also have a compiler called javac (Java compiler). The compiler version can differ from your runtime version, and sometimes you need to know both. Run javac -version in the same terminal where you checked java -version.

If javac -version returns "command not found" but java -version worked, you have the Java runtime but not the development kit. The runtime lets you run Java programs; the development kit (JDK) lets you write and compile them. If you need to develop Java code, you will need to install the JDK, not just the runtime (JRE).

What to do if Java is not installed

If both commands return "not found" or "not recognized", Java is not installed on your computer. You can download it from the official Java website or use a package manager. On Mac, you can run brew install openjdk if you have Homebrew installed. On Linux, most distributions have Java in their package manager — for example, apt install default-jdk on Debian or Ubuntu.

Before installing, decide whether you need just the runtime (JRE) to run existing Java programs, or the full development kit (JDK) to write and compile Java code. Most people who are checking their Java version already have a reason to use it, so if you are unsure, the JDK is the safer choice — it includes the runtime and the compiler.

Checking Java version in an IDE or text editor

If you use an IDE like Eclipse, IntelliJ IDEA, or VS Code, you can often check your Java version without opening a terminal. In Eclipse, go to Help > About Eclipse > Installation Details > Configuration and look for "java.version" in the list. In IntelliJ IDEA, go to File > Project Structure > Project and look at the Project SDK dropdown.

VS Code does not show Java version in the interface by default, but the Extension Pack for Java shows it in the output panel when you open a Java file. If you prefer the command line, it is usually faster than hunting through menus, but the IDE method works if you are already working in one.

Frequently Asked Questions

Why do I have two different Java versions?

You might have both a runtime version (java) and a compiler version (javac) from different installations, or you might have multiple JDK versions installed at once. This is common when you upgrade Java or install a specific version for a project. Run both java -version and javac -version to see which is which, then uninstall the one you do not need.

Does the version number matter for running programs?

Yes. A Java program compiled for version 11 might not run on version 8, and a program written for version 17 will not run on version 11. If a program fails to start, check its documentation for the minimum Java version required, then compare it to your version number. The first number (8, 11, 17) is usually what matters most.

What is the difference between Oracle JDK and OpenJDK?

Both are Java distributions that do the same job. Oracle JDK is the official version from Oracle and requires a license for commercial use. OpenJDK is free and open-source. For most people, the difference does not matter — your code runs the same way on both. Check which one you have by looking at the vendor line in your version output.

Can I have Java installed but the command still not work?

Yes, if Java is installed but not added to your system PATH. The PATH tells your terminal where to find programs. You can either add Java to your PATH or use the full path to the Java executable every time. On Windows, search for "Environment Variables" in Settings and add your Java bin folder to the PATH list.

Do I need to update Java after checking the version?

That depends on what you are using Java for. If you are just running a program that works fine, you do not need to update. If you are developing code or using Java for security-sensitive work, check whether your version is still receiving updates from the vendor. Older versions like Java 8 still work but no longer receive security patches.