1

I need to validate java version. I use

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

How to simple parse that to know for example that installed JRE is in min. 1.6.0_18 version ? I wonder is that naming convention of java version is standard.

Nishant
56.1k13 gold badges119 silver badges132 bronze badges
asked Aug 28, 2012 at 7:20
3
  • 4
    This has already been answered: stackoverflow.com/questions/2591083/… Commented Aug 28, 2012 at 7:25
  • That answer is about check main version 1.5 vs 1.6. I need to validate more (.0_18, .0-beta1 etc) Commented Aug 28, 2012 at 7:54
  • @marioosh i guess my answer will do what you want, just leave a comment if unclear or something Commented Aug 28, 2012 at 8:02

2 Answers 2

2

Yes, there is naming convention. You can find it from here. And more fresh information about version 6 can be found from here.

answered Aug 28, 2012 at 7:24
Sign up to request clarification or add additional context in comments.

2 Comments

Oh. Thanks. I see that is more complicated. Do You have some idea how to parse that to verify installed version ?
@marioosh take a look at my answer
0

yes, this is as far as i know the naming convention of java Versions, so just use the System.getProperty("java.version") as you are already doing, and check the String by using stringTokenizer if the minimum required jre is installed.

Edit: i wrote Stringbuilder in the beginning, of cource i meant stringtokenizer.

With the Stringtokenizer you can get Substrings of a String separated by a defined Symbol, and kind of iterate through the String. You may need a second stringtokenizer, the first separating the Strting by "." and than for the last Substring one separating by "_". Take a lool here.

You could do it like this: (of cource you could also do it over a loop, an checking with hasMoreTokens() and so on, but you dont need in this case, because you know exactly what the string looks like)

String[] versionArray = new String[4];
String version = System.getProperty("java.version"); 
StringTokenizer st1 = new StringTokenizer(version,".");
versionArray[1] = st1.nextToken();
versionArray[2] = st1.nextToken();
StringTokenizer st2 = new StringTokenizer(st1.nextToken(),"_");
versionArray[3] = st2.nextToken();
versionArray[4] = st2.nextToken();

After it in the versionArray would be with your example ["1"]["6"]["0"]["18"] and you can do your comparison on this...

answered Aug 28, 2012 at 7:28

2 Comments

Do u mean System.getPerperty("java.version").Please make it correct.
@JDeveloper uhm, no i mean public static String getProperty(String key) as specified here

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.