Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Mar 12, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Find Out the Java Version

This is generally useful, specifically if you want to perform some operations based on the version of Java you are using.

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

*/
M S Sridhar
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
javascriptkit.com
htmlandcssbook.com