Use the jdkversion. Java file in spring to obtain the JDK version information.
Jdkversion. JavaCode:
Package Org. springframework. core; <br/>/** <br/> * internal helper class used to find the Java/JVM version <br/> * that spring is operating on, to allow for automatically <br/> * adapting to the present platform's capabilities. <br/> * <p> note that spring requires JVM 1.5 or higher, as of spring 3.0. <br/> * @ author rod Johnson <br/> * @ author Juergen hoeller <br/> * @ author Rick Evans <br/> */<br /> public abstract class jdkversion {<br/>/** <br/> * constant identifying the 1.3.x JVM (JDK 1.3 ). <br/> */<br/> Public static final int java_13 = 0; <br/>/** <br/> * constant identifying the 1.4.x JVM (j2se 1.4 ). <br/> */<br/> Public static final int java_14 = 1; <br/>/** <br/> * constant identifying the 1.5 JVM (Java 5 ). <br/> */<br/> Public static final int java_15 = 2; <br/>/** <br/> * constant identifying the 1.6 JVM (Java 6 ). <br/> */<br/> Public static final int java_16 = 3; <br/>/** <br/> * constant identifying the 1.7 JVM (Java 7 ). <br/> */<br/> Public static final int java_17 = 4; <br/> Private Static final string javaversion; <br/> Private Static final int majorjavaversion; <br/> static {<br/> javaversion = system. getproperty ("Java. version "); <br/> // version string shocould look like" 1.4.2 _ 10 "<br/> If (javaversion. contains ("1.7. ") {<br/> majorjavaversion = java_17; <br/>}< br/> else if (javaversion. contains ("1.6. ") {<br/> majorjavaversion = java_16; <br/>}< br/> else {<br/> // else leave 1.5 as default (it's either 1.5 or unknown) <br/> majorjavaversion = java_15; <br/>}< br/>/** <br/> * return the full Java version string, as returned by <br/> * <code> system. getproperty ("Java. version ") </code>. <br/> * @ return the full Java version string <br/> * @ see system # getproperty (string) <br/> */<br/> Public static string getjavaversion () {<br/> return javaversion; <br/>}< br/>/** <br/> * Get the major version code. this means we can do things like <br/> * <code> If (getmajorjavaversion () <java_14) </code>. <br/> * @ return a code comparable to the java_xx codes in this class <br/> * @ see # java_13 <br/> * @ see # java_14 <br/> * @ see # java_15 <br/> * @ see # java_16 <br/> * @ see # java_17 <br/> */<br/> Public static int getmajorjavaversion () {<br/> return majorjavaversion; <br/>}< br/>/** <br/> * convenience method to determine if the current JVM is at least Java 1.4. <br/> * @ return <code> true </code> if the current JVM is at least Java 1.4 <br/> * @ deprecated as of spring 3.0 which requires Java 1.5 + <br/> * @ see # getmajorjavaversion () <br/> * @ see # java_14 <br/> * @ see # java_15 <br/> * @ see # java_16 <br/> * @ see # java_17 <br/> */<br/> @ deprecated <br/> Public static Boolean isatleastjava14 () {<br/> return true; <br/>}< br/>/** <br/> * convenience method to determine if the current JVM is at least <br/> * Java 1.5 (Java 5 ). <br/> * @ return <code> true </code> if the current JVM is at least Java 1.5 <br/> * @ deprecated as of spring 3.0 which requires Java 1.5 + <br/> * @ see # getmajorjavaversion () <br/> * @ see # java_15 <br/> * @ see # java_16 <br/> * @ see # java_17 <br/> */<br/> @ deprecated <br/> Public static Boolean isatleastjava15 () {<br/> return true; <br/>}< br/>/** <br/> * convenience method to determine if the current JVM is at least <br/> * Java 1.6 (Java 6 ). <br/> * @ return <code> true </code> if the current JVM is at least Java 1.6 <br/> * @ deprecated as of spring 3.0, in favor of reflective checks for <br/> * The specific Java 1.6 classes of interest <br/> * @ see # getmajorjavaversion () <br/> * @ see # java_16 <br/> * @ see # java_17 <br/> */<br/> @ deprecated <br/> Public static Boolean isatleastjava16 () {<br/> return (majorjavaversion> = java_16); <br/>}< br/>
Getjdkversion. Java code:
Public class getjdkversion {<br/> @ suppresswarnings ("static-access") <br/> Public static void main (string [] ARGs) {<br/> jdkversion = new jdkversion () {<br/>}; <br/> system. out. println (jdkversion. getjavaversion (); <br/>}< br/>}
Test information: 1.6.0 _ 23