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,051
  • 2
  • 40
  • 64

3 Answers3

10

Use this condition

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

to check the Java version.

Ingo Kegel
  • 44,757
  • 10
  • 67
  • 100
4
String version = System.getProperty("java.specification.version");

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

maba
  • 45,597
  • 10
  • 105
  • 115
3
String version = System.getProperty("java.version");
David Grant
  • 13,603
  • 3
  • 55
  • 63