java
binary in combination with the -version
option. To do so run java -version
on your terminal. $ java -version
Furthermore, execute the following command to check the version of the current default Java compiler
javac
: $ javac -versionIn 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.
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.
CheckJavaVersion.java
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 CheckJavaVersion.java $ 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: