Deals with the different version of the Java Virtual Machine. : JDK « Development « Java Tutorial

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
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Development » JDK 
6. 60. 2. Deals with the different version of the Java Virtual Machine.
/*
 * $Id: JVM.java,v 1.3 2009/02/22 02:01:04 kschaefe Exp $
 *
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library 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 library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 * Deals with the different version of the Java Virtual Machine. <br>
 */
public class JVM {

  public final static int JDK1_0 = 10;
  public final static int JDK1_1 = 11;
  public final static int JDK1_2 = 12;
  public final static int JDK1_3 = 13;
  public final static int JDK1_4 = 14;
  public final static int JDK1_5 = 15;
  public final static int JDK1_6 = 16;
  public final static int JDK1_6N = 1610;
  public final static int JDK1_7 = 17;

  private static JVM current;
  static {
    current = new JVM();
  }

  /**
   @return the current JVM object
   */
  public static JVM current() {
    return current;
  }

  private int jdkVersion;

  /**
   * Creates a new JVM data from the <code>java.version</code>
   * System property
   *  
   */
  public JVM() {
    this(System.getProperty("java.version"));
  }

  /**
   * Constructor for the OS object
   */
  public JVM(String p_JavaVersion) {
    if (p_JavaVersion.startsWith("1.7.")) {
      jdkVersion = JDK1_7;
    else if (p_JavaVersion.startsWith("1.6.")) {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
          if ("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel".equals(info.getClassName())) {
              jdkVersion = JDK1_6N;
              break;
          }
      }
      
      jdkVersion = jdkVersion == ? JDK1_6 : jdkVersion;
    else if (p_JavaVersion.startsWith("1.5.")) {
      jdkVersion = JDK1_5;
    else if (p_JavaVersion.startsWith("1.4.")) {
      jdkVersion = JDK1_4;
    else if (p_JavaVersion.startsWith("1.3.")) {
      jdkVersion = JDK1_3;
    else if (p_JavaVersion.startsWith("1.2.")) {
      jdkVersion = JDK1_2;
    else if (p_JavaVersion.startsWith("1.1.")) {
      jdkVersion = JDK1_1;
    else if (p_JavaVersion.startsWith("1.0.")) {
      jdkVersion = JDK1_0;
    else {
      // unknown version, assume 1.3
      jdkVersion = JDK1_3;
    }
  }

  public boolean isOrLater(int p_Version) {
    return jdkVersion >= p_Version;
  }

  public boolean isOneDotOne() {
    return jdkVersion == JDK1_1;
  }

  public boolean isOneDotTwo() {
    return jdkVersion == JDK1_2;
  }

  public boolean isOneDotThree() {
    return jdkVersion == JDK1_3;
  }

  public boolean isOneDotFour() {
    return jdkVersion == JDK1_4;
  }

  public boolean isOneDotFive() {
    return jdkVersion == JDK1_5;
  }

  public boolean isOneDotSix() {
    return jdkVersion == JDK1_6;
  }

    /**
     * Determines if the version of JDK1_6 has Nimbus Look and Feel installed.
     
     @return {@code true} if Nimbus is available and the version is 1.6;
     *         {@code false} otherwise
     */
  public boolean isOneDotSixUpdateN() {
      return jdkVersion == JDK1_6N;
  }
  
  public boolean isOneDotSeven() {
      return jdkVersion == JDK1_7;
  }

}
6. 60. JDK
6. 60. 1. Provides common access to specifics about the version of Java that a virtual machine supports.
6. 60. 2. Deals with the different version of the Java Virtual Machine.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.