Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.osgi.framework.util;

Provides common access to specifics about the version of Java that a virtual machine supports.

Determines the version of the Java Virtual Machine by checking for the availablity of version specific classes.

Classes are loaded in the following order:

  1. java.lang.Void was introduced in JDK 1.1
  2. java.lang.ThreadLocal was introduced in JDK 1.2
  3. java.lang.StrictMath was introduced in JDK 1.3
  4. java.lang.StackTraceElement was introduced in JDK 1.4
  5. java.lang.Enum was introduced in JDK 1.5
  6. java.lang.management.LockInfo was introduced in JDK 1.6

Author(s):
Jason Dillon
Dimitris Andreadis
Version:
$Revision: 2240 $
 
 public final class Java {

    
Prevent instantiation
 
     private Java() {
     }

    
Java version 1.0 token
 
     public static final int VERSION_1_0 = 0x01;

    
Java version 1.1 token
 
     public static final int VERSION_1_1 = 0x02;

    
Java version 1.2 token
 
     public static final int VERSION_1_2 = 0x03;

    
Java version 1.3 token
 
     public static final int VERSION_1_3 = 0x04;

    
Java version 1.4 token
 
     public static final int VERSION_1_4 = 0x05;

    
Java version 1.5 token
 
     public static final int VERSION_1_5 = 0x06;

    
Java version 1.6 token
 
     public static final int VERSION_1_6 = 0x07;

    
Private to avoid over optimization by the compiler.

See also:
getVersion() Use this method to access this final value.
 
     private static final int VERSION;

    
Initialize VERSION.
 
     static {
         // default to 1.0
         int version = ;
 
         try {
             // check for 1.1
             Class.forName("java.lang.Void");
             version = ;
 
             // check for 1.2
             Class.forName("java.lang.ThreadLocal");
             version = ;
 
             // check for 1.3
             Class.forName("java.lang.StrictMath");
             version = ;
 
             // check for 1.4
            Class.forName("java.lang.StackTraceElement");
            version = ;
            // check for 1.5
            Class.forName("java.lang.Enum");
            version = ;
            // check for 1.6
            Class.forName("java.lang.management.LockInfo");
            version = ;
        } catch (ClassNotFoundException ignore) {
        }
         = version;
    }

    
Return the version of Java supported by the VM.

Returns:
The version of Java supported by the VM.
    public static int getVersion() {
        return ;
    }

    
Returns true if the given version identifer is equal to the version identifier of the current virtuial machine.

Parameters:
version The version identifier to check for.
Returns:
True if the current virtual machine is the same version.
    public static boolean isVersion(final int version) {
        return  == version;
    }

    
Returns true if the current virtual machine is compatible with the given version identifer.

Parameters:
version The version identifier to check compatibility of.
Returns:
True if the current virtual machine is compatible.
    public static boolean isCompatible(final int version) {
        // if our vm is the same or newer then we are compatible
        return  >= version;
    }
New to GrepCode? Check out our FAQ X