How to Check Current JDK Version installed in Your System Using CMD?
There are different versions of Java is available. Some of the applications generally require different version because of compatibility problems. In this section, we will learn how to check the Java version in Windows using CMD.
A version string contains a version number optionally followed by pre-release and build information. The first number in Java version represents the major version and the second number represents the release. Java provides -version option to find the current Java version.
There are following ways to find the Java version in Windows:
Note: Before checking the Java version, ensure that Java is installed and the path is properly set.
Using Command Prompt
By using the Command Prompt, we can easily find the Java version. The Java provides -version option to check the Java version. It prints the product version. To find the Java version in CMD, follow the steps given below:
Step 1: Open the Command Prompt by pressing Windows Key + R, type cmd and press enter key or click on the Ok button. It opens the Command Prompt window.
Step 2: Type the following command in the prompt window and press enter key. It shows the Java version.
If the above command shows 'java' is not recognized, it means the path is not properly set. To resolve this problem, we must add the Java path to the system environment variable.
Using Java System Class
Another way to find the Java version is to use the System class. It provides the getProperty() method that finds the Java version. The getProperty() method accepts a key as an argument. A key is the name of the system property.
The method returns the String value of the system property, or null if there is no property with that key. It throws NullPointerException if the key is null and IllegalArgumentException if the key is empty.
Let's find Java version through a program.
We can also find the Java version by using the Control Panel.
Step 1: Open the Control Panel and click on the Java icon. It shows the Java Control Panel.
Step 2: In the Java Control Panel, click on the About button.
When we click on the About button, the About Java dialog box appears that shows the Java version.