dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 12, 2020

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
 
Thanks for your registration, follow us on our social networks to keep up-to-date