Determine the JDK Version Number : OS « Development « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Development » OS 
6.61.5.Determine the JDK Version NumberPrevious/Next
/** Determine the JDK Version Number
 *
 * There is a human readible JDK version number available as a Java property. The property name is called "java.version".
 * Unfortunately it is complicated to parse it mechanically. A somewhat better choice is the Java property called
 * "java.class.version". The property value can be converted to a floating pointer value. JDK 1.1 implies 45.3. JDK 1.2
 * implies 46.0. JDK 1.3 implies 47.0. JDK 1.4 implies 48.0.
 
 * java.class.version property value
 * <ul>
 * <li> JDK 1.1 = 45.3
 * <li> JDK 1.2 = 46.0
 * <li> JDK 1.3 = 47.0
 * <li> JDK 1.4 = 48.0
 * </ul>
 *
 @author Thomas Rischbeck <thomas.rischbeck@arjuna.com>
 @version $Id: VersionCheck.java 2342 2006-03-30 13:06:17Z  $
 */

public class VersionCheck {

   private static final String CLASS_VERSION = System.getProperty("java.class.version","44.0");
   private static final boolean IS_JDK_11 = ("46.0".compareTo(CLASS_VERSION0&& ("45.3".compareTo(CLASS_VERSION<= 0);
   private static final boolean IS_JDK_12 = ("47.0".compareTo(CLASS_VERSION0&& ("46.0".compareTo(CLASS_VERSION<= 0);
   private static final boolean IS_JDK_13 = ("48.0".compareTo(CLASS_VERSION0&& ("47.0".compareTo(CLASS_VERSION<= 0);
   private static final boolean IS_JDK_14 = ("49.0".compareTo(CLASS_VERSION0&& ("48.0".compareTo(CLASS_VERSION<= 0);
   private static final boolean IS_JDK_13_OR_BELOW = IS_JDK_11 || IS_JDK_12 || IS_JDK_13;
   private static final boolean IS_JDK_14_OR_ABOVE = ("48.0".compareTo(CLASS_VERSION<= 0);


   public static final boolean isJDK11only()
   {
     return IS_JDK_11;
   }

   public static final boolean isJDK12only()
   {
     return IS_JDK_12;
   }

   public static final boolean isJDK13only()
   {
     return IS_JDK_13;
   }

   public static final boolean isJDK14only()
   {
     return IS_JDK_14;
   }

   public static final boolean isJDK13orBelow()
   {
      return IS_JDK_13_OR_BELOW;
   }

   public static final boolean isJDK14orAbove()
   {
      return IS_JDK_14_OR_ABOVE;
   }

}
6.61.OS
6.61.1.Condition that tests the OS type.
6.61.2.Class representing a standard operating system platform, WIN, MAC, or POSIX.
6.61.3.Get OS
6.61.4.Class to help determining the OS
6.61.5.Determine the JDK Version Number
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.