How to find the version of Java using command line?

Java 8Object Oriented ProgrammingProgramming

You can find the version of the Java software currently installed in your system using Programs and using Command prompt.

Using Command prompt

The -version command of the java command prompt gives you the current version of the Java software installed in your system.

Therefore, open command prompt and type the command java -version to get the version of Java installed in your system.

Java Command Line

Using the Java program

The System class of java.lang package provides a method named getProperty() this method accepts one of the following string parameters an returns the respective property.

To get the version of the java installed in the system, invoke the getProperty() method by passing the value "" to it, as shown in the following sample code.


Live Demo

public class Test {
   public static void main(String args[]) {
      Test obj = new Test();    
      String os = System.getProperty("java.version");
      System.out.println("Current Java version is: "+os);    


Current Java version is: 1.8.0_101
Updated on 30-Jul-2019 22:30:20