Check Java Version

There are several ways on how to check what version of Java is installed on your system. Most likely the simplest way is to directly use the java binary in combination with the -version option. To do so run java -version on your terminal.

$ java -version

Check Java Version

Check Java Version

Furthermore, execute the following command to check the version of the current default Java compiler javac:

$ javac -version

In case you are looking for a system agnostic way on how to check the Java version installed on your system attempt to retrieve the Java version programmatically.

This procedure should work with any Java version as well as any operating system. Using any text editor create a new file with the following content:

public class CheckJavaVersion {
   public static void main(String[] args) {
      String javaVersion = System.getProperty("java.version");
      System.out.format("Java Version = '%s'\n", javaVersion);

Once the above file is created compile and execute. For example:

$ javac 
$ java CheckJavaVersion 
Java Version = '11'

The execution of the CheckJavaVersion Java program resulted in java version output. In this case Java Version 11 is installed on our system.

The following figure illustrates the entire procedure on how to check java version programmatically:

How to check java version programmatically

How to check java version programmatically

Comments and Discussions
Linux Forum