Java FAQ: How to determine the Java version running your application

A frequently asked Java question is, "How can I tell what version of Java is running my program?"

Answer: Just use this line of source code to determine the version of Java that is running your program:

String javaVersion = System.getProperty("java.version");

More information

Because the capabilities of the JVM/JRE change in each Java version, it can be very important to know which Java version is currently running your program. I find this to be especially true in Swing applications, where an important bug can easily be fixed (or at least changed) in a minor version release.

Here's the source code for a complete Java program that demonstrates how to determine the Java version from within the application: