KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > util > JavaVersion


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: JavaVersion.java,v 1.1 2004/04/21 19:32:00 slobodan Exp $
23  */

24
25 package com.lutris.util;
26
27 /*
28  * JavaVersion can be used as a standalone main class
29  * to print the major version number of the executing JVM
30  * or it can return the version using the getVersion() method.
31  *
32  * @version $Revision: 1.1 $
33  * @author Shawn McMurdo
34  * @author Jason Hunter (jhunter@hyperreal.org)
35  */

36 public class JavaVersion {
37
38     static {
39     setVersion();
40     }
41     public static String JavaDoc javaVersion;
42
43     public static void main(String JavaDoc argv[]) {
44         System.out.println(javaVersion);
45     }
46
47     public static String JavaDoc getVersion() {
48     return javaVersion;
49     }
50
51     private static void setVersion() {
52     // From Jason Hunter via Jakarta Tomcat
53
// This method includes software developed by the
54
// Apache Software Foundation <http://www.apache.org/>.
55

56         // Determine the Java version by looking at available classes
57
// java.lang.StrictMath was introduced in JDK 1.3
58
// java.lang.ThreadLocal was introduced in JDK 1.2
59
// java.lang.Void was introduced in JDK 1.1
60
// Count up version until a NoClassDefFoundError ends the try
61
try {
62             javaVersion = "1.0";
63             Class.forName("java.lang.Void");
64             javaVersion = "1.1";
65             Class.forName("java.lang.ThreadLocal");
66             javaVersion = "1.2";
67             Class.forName("java.lang.StrictMath");
68             javaVersion = "1.3";
69         }
70         catch (Throwable JavaDoc t) {
71         }
72     }
73 }
74
75
Popular Tags