devxlogo

Finding out the Java version.

Finding out the Java version.

This is generally useful, specifically if you want to perform some operations based on Java version and so on.

public class JavaVersion
{
   public static void main(String args[])
   {
      JavaVersion javaVersion = new JavaVersion();
      javaVersion.proceed();
   }
   
   private void proceed()
   {
      //This works in Java 8 and prior
      //For Java 9, there is a new api available in Runtime class
      String javaVersion = System.getProperty(“java.version”);
        System.out.println(“Java Version: ” + javaVersion); 
   }
}

/*

Expected output:

[root@mypc]# java JavaVersion
Java Version: 1.8.0_221

*/

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist