4

Possible Duplicate:
How to know JDK version from within Java code

In my java code I want to check jdk version. If it is 1.5 or above than & than only I want to go ahead with further execution. How to get the jdk version ?

Community
  • 1
  • 1
hemu
  • 3,199
  • 3
  • 44
  • 66

3 Answers3

10

Use this condition

Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) >= 5

to check the Java version.

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
4
String version = System.getProperty("java.specification.version");

That will give you the string 1.5 for example. Easy to parse.

maba
  • 47,113
  • 10
  • 108
  • 118
3
String version = System.getProperty("java.version");
David Grant
  • 13,929
  • 3
  • 57
  • 63