I've been trying to find a function that returns the version number of the JVM. I found this website that does it, so I know it can be done:


Can anyone help me out?

"java -version" from the command line or System.getProperty("java.specification.version"); From the docs on this system property

The requirement to identify the Java Runtime is already partially met via the properties specified by the Java Language Specification, §20.18.7 using java.lang.System.getProperties.

  • java.version i.e. Solaris 1.2
  • java.vendor i.e. Sun Microsystems Inc.

Currently these identify the implementation of the Java runtime and the core classes that are available. These properties do not identify the Java Language Specification version that this JDK implements.
Additional properties are needed to identify the version of the Java Runtime Environment specification that this implementation adhere’s to. The properties are:

  • java.specification.version i.e. 1.1
  • java.specification.name i.e. Java™ Language Specification
  • java.specification.vendor i.e. Sun Microsystems Inc.

These properties are accessed using the method java.lang.System.getProperty and return their values as strings.