Java: Check Class Version
By admin on Sep 22, 2008 in Java, Programming
Here is a simple piece of code to check your Java class version, whether is it is compiled with JDK 4, JDK 5 or JDK 6, etc…
1: try {
2: String filename = "C:\\MyClass.class";
3: DataInputStream in = new DataInputStream
4: (new FileInputStream(filename));
5:
6: int magic = in.readInt();
7: if (magic != 0xcafebabe) {
8: log.info(filename + " is not a valid class!");
9: }
10: int minor = in.readUnsignedShort();
11: int major = in.readUnsignedShort();
12: log.info(filename + ": " + major + " . " + minor);
13: in.close();
14: } catch (IOException e) {
15: log.info("Exception: " + e.getMessage(), e);
16: }
major minor Java platform version
45 3 1.0
45 3 1.1
46 0 1.2
47 0 1.3
48 0 1.4
49 0 1.5
50 0 1.6
Sorry, comments for this entry are closed at this time.