Question

How do I determine the version of the Java Virtual Machine from an applet or application?

Answer

You can determine the JVM version and vendor by accessing system properties. If you're not familiar with Java Properties, a Properties object contains a mapping between string keys and string values. The JVM version is stored in the system properties object, accessible via the static System.getProperties() method. The Java API documentation lists the following keys and descriptions

Key Description of Associated Value
java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX)
user.name User's account name
user.home User's home directory
user.dir User's current working directory

Not every JVM is guaranteed to support these properties. For example, the Microsoft JVM will return null values for a request to get the 'java.vm.vendor' property. It will, however, return a value for 'java.vendor'. It may be better to check for these values instead, to guarantee compatibility. An example of this is as follows:-

import java.util.Properties;
public class jvm_version
{
	public static void main(String args[])
	{
		Properties prop = System.getProperties();
		System.out.println ("JVM Vendor : " + prop.getProperty("java.vendor") );
		System.out.println ("JVM Version: " + prop.getProperty("java.version") );
	}
}


Back