0

I'm looking for a way to check which java version my software is running under.

I'd like to verify during load time my software is running on at least

asked Jun 26, 2013 at 20:12
3
  • 2
    System.getProperty("java.version") Commented Jun 26, 2013 at 20:16
  • Can you finish your last sentence. Commented Jun 26, 2013 at 20:21
  • How many duplicate answers do we need? Commented Jun 26, 2013 at 20:59

4 Answers 4

5

To get the java version you can use any of these depending on the version you want:

java.specification.version
java.version 
java.vm.version 
java.runtime.version 

However, note that java versions are not equivalent between operative systems. So Java 6 on OSX does not mean the same thing as Java 6 on Windows. So, I would recommend you to also get the OS where the application is running, if you wish to determine if a given feature is available:

System.getProperty("os.name")

As a general guideline, all of this stuff is in the System package. A trick I use is iterate through all the available fields to have an idea of what I can use:

import java.util.Map;
class ShowProperties {
 public static void main(String[] args) {
 for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
 System.out.println(e);
 }
 }
}
answered Jun 26, 2013 at 20:19
Sign up to request clarification or add additional context in comments.

Comments

3

Use java.version property to retrieve the jre version.

 String javaVersion = System.getProperty("java.version");
if ((!javaVersion.startsWith("1.6")) && (!javaVersion.startsWith("1.7")) && (!javaVersion.startsWith("1.8")) && (!javaVersion.startsWith("1.9")))
{
 // error
}
sharakan
6,9212 gold badges38 silver badges63 bronze badges
answered Jun 26, 2013 at 20:15

1 Comment

You've got extra parentheses
1

You can use System.getProperty:

System.out.println(System.getProperty("java.version"));
1.7.0_21
answered Jun 26, 2013 at 20:15

Comments

0
java.lang.System.getProperty("java.version")
answered Jun 26, 2013 at 20:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.