by BehindJava

How to check the version of java installed on my computer

Home » java » How to check the version of java installed on my computer

In this tutorial, we are going to learn about checking the Java version through command prompt and programmatic way.

To Check the Java version through windows Command Prompt CMD

C:\Users\cldee>java -version
java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

To Check the Java Compiler Version

C:\Users\cldee>javac -version
javac 16.0.1

To check the Java version in programmatic way

There are two ways to read system attributes in the Java System class:

  • getProperty: There are two iterations of getProperty in the System class. Both methods return the value of the specified property from the argument list. The less complex getProperty function only needs one argument.
  • getProperties: The current system properties are determined via the java.lang.System.getProperties() function.

Method Descriptions: The value of the property is returned in a string by the getProperty(String key) function of the Java.lang.System class. This iteration of getProperty returns null if the property is nonexistent. The key-value pair described in the table below serves as the foundation for this.

Syntax: public static String getProperty(String key)
Parameters :
key : key whose system property we want
Returns :
System property as specified the key
Null : if there is no property present with that key.

// Printing 'JAVA Runtime version'
	        System.out.print("Java Version: "+System.getProperty("java.runtime.version" ));