How to Check Java Version: Verify JDK, Java and javac Commands

0

After installing Java and configuring JAVA_HOME and PATH, the next step is simple but extremely important: verify that Java is actually working.

Checking the Java version is one of the first troubleshooting steps developers use when setting up a new machine, opening an existing project, or investigating a Java-related error.

Quick idea: Use java -version to check the Java runtime and javac -version to check the Java compiler.

Why Should You Check the Java Version?

Imagine that a project requires one Java version, but your computer is using another version. The project may fail to compile, behave differently, or refuse to start.

Before troubleshooting complicated Java errors, developers often begin with a very simple question:

Which Java version is currently being used?

The answer can be obtained directly from the command line.

Using java -version

Open Command Prompt or another terminal and run:

java -version

The command displays information about the Java runtime available through your current environment.

The exact output depends on the installed JDK distribution and Java version, so you should focus on the version information rather than memorizing a particular output format.

java -version

If Java is correctly available through PATH, the command should return Java version information instead of a command-not-found error.

Checking the Java Compiler

Checking the runtime alone is not enough when you are setting up a development environment. You should also verify that the Java compiler is available.

Run:

javac -version

The javac command belongs to the JDK and is responsible for compiling Java source code into bytecode.

Remember: java is used to run Java applications, while javac is used to compile Java source code.

java vs javac

Command Purpose What It Checks
java -version Checks the Java runtime. Whether the Java runtime command is available.
javac -version Checks the Java compiler. Whether the JDK compiler is available.

Checking JAVA_HOME

If you configured JAVA_HOME earlier, you can also verify its current value.

On Windows Command Prompt, use:

echo %JAVA_HOME%

This displays the JDK directory stored in the JAVA_HOME environment variable.

JAVA_HOME
    ↓
JDK installation directory

If the displayed location is incorrect, JAVA_HOME may need to be corrected.

Finding the Java Executable

When several Java versions are installed, knowing the version is useful, but knowing which executable is being used can be even more useful.

On Windows, use:

where java

You can also check the compiler:

where javac

These commands show the executable locations that Windows can find for those commands.

Troubleshooting tip: If java -version shows an unexpected version, use where java to investigate which Java executable is being selected.

Checking a Complete Java Setup

When setting up Java for development, you can perform a quick verification using these commands:

java -version
javac -version
echo %JAVA_HOME%
where java
where javac

Each command answers a different question.

Command Question It Answers
java -version Which Java runtime version is available?
javac -version Which Java compiler version is available?
echo %JAVA_HOME% Where does JAVA_HOME point?
where java Which Java executable can Windows find?
where javac Which compiler executable can Windows find?

What If Java Is Not Recognized?

A common error looks similar to this:

'java' is not recognized as an internal or external command

This generally means the terminal cannot find the Java executable through the current PATH configuration.

First, check whether JAVA_HOME has a value:

echo %JAVA_HOME%

Then verify whether the Java executable can be found:

where java

If Java cannot be found, review your PATH configuration and make sure the JDK's bin directory is correctly available.

What If java Works but javac Does Not?

This is an interesting situation because it can provide a clue about your installation.

If this works:

java -version

but this fails:

javac -version

you should investigate which Java installation your PATH is using and whether the JDK compiler is available.

The key distinction is that javac is a development tool supplied with the JDK. Therefore, a working runtime command does not by itself prove that your development environment is correctly configured.

Checking Java Before Starting a Project

Professional developers often check the Java version before working with an unfamiliar project. This is especially useful when a project has a specific Java requirement.

For example, before building a project, you might run:

java -version
javac -version

Then compare the reported version with the project's required Java version.

Industry habit: When something suddenly fails after switching projects or machines, checking the Java version is often one of the fastest diagnostic steps.

Checking Multiple Java Installations

It is possible to have more than one JDK installed on the same computer. This can happen when working with older projects and newer projects at the same time.

For example:

JDK 17
JDK 21
JDK 25

The important question is not simply whether these versions are installed. The important question is which one your current environment is actually using.

Use:

java -version
where java

Together, these commands tell you the version and help identify the executable location being selected.

Small Learning Checkpoint

Try answering these without looking back:

  • Which command checks the Java runtime version? java -version
  • Which command checks the Java compiler version? javac -version
  • Which command displays JAVA_HOME? echo %JAVA_HOME%
  • Which command helps locate the Java executable on Windows? where java

Common Beginner Mistakes

  • Checking only java -version and assuming the complete JDK development setup is working.
  • Ignoring the Java version required by a project.
  • Forgetting that multiple JDK versions can exist on the same computer.
  • Changing environment variables but not opening a new terminal.
  • Seeing an unexpected Java version and immediately reinstalling Java without checking PATH first.

Interview Insight

An interviewer may ask, "How do you check whether Java is installed on a system?"

A simple answer is: "I can run java -version from the command line to check the installed Java runtime. For development, I can also run javac -version to verify that the JDK compiler is available."

This answer demonstrates that you understand the difference between checking the runtime and checking the development environment.

Quick Revision

Command Purpose
java -version Checks the Java runtime version.
javac -version Checks the Java compiler version.
echo %JAVA_HOME% Displays the configured JDK location.
where java Finds Java executable locations on Windows.
where javac Finds compiler executable locations on Windows.

Checking the Java version is a small habit with a surprisingly large payoff. It confirms that your environment is working, helps identify the active JDK, and gives you an immediate starting point when troubleshooting Java projects. Once you can confidently verify your Java installation, the next step is understanding the development tools that come with the JDK.

Post a Comment

0Comments
Post a Comment (0)