Get the Java Version at Runtime
Getting the Java Version at Runtime
Many businesses utilize Java as a programming language in order to create application software and web applications. A key factor in running a successful Java-based program is to ensure that the right version of Java is installed on each workstation. As such, it can be important to know how to get the Java version at runtime.
Checking Your Java Version
The easiest way to check your Java version is to open up a terminal window or command prompt and type the following command: “java -version”. This will display the version of Java installed on your system. You should also note that this same command can be used in a script to check the Java version at runtime.
Using System Properties
Another way to get the Java version at runtime is to use system properties. The “java.version” property is particularly useful for this purpose. To access this property from within a Java program, simply use the following code:
String version = System.getProperty("java.version");
System.out.println(version);
This will return the installed version of Java which can then be parsed and checked against the appropriate version requirements.
Conclusion
As you can see, getting the Java version at runtime is not a difficult task. With the two methods discussed here, you should be able to determine the version of Java installed on any computer with relative ease. This information can then be used to make sure that all workstations are running the same version of Java and help to ensure that programs run smoothly.