{"id":54,"date":"2009-02-17T18:12:38","date_gmt":"2009-02-18T01:12:38","guid":{"rendered":"http:\/\/shivdev.com\/blog\/2009\/02\/17\/find-out-what-version-a-java-class-is-compiled-with\/"},"modified":"2011-05-06T07:32:01","modified_gmt":"2011-05-06T07:32:01","slug":"find-out-what-version-a-java-class-is-compiled-with","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2009\/02\/17\/find-out-what-version-a-java-class-is-compiled-with\/","title":{"rendered":"Find out what version a Java Class is compiled with"},"content":{"rendered":"<p>I got an UnsatisfiedLinkError and wanted to find out whether our JDK upgrade had caused it and did some searching and found that <strong>javap -verbose<\/strong> lets you find out the version of a compiled class. So get the class (could be in a JAR file) and then follow this example where I find the version of MyCallback.class<\/p>\n<blockquote><p> C:&gt;c:\\jdk1.6.0_07\\bin\\<strong>javap -verbose<\/strong> MyCallback<br \/>\nCompiled from &#8220;MyCallback.java&#8221;<br \/>\npublic class com.shivdev.MyCallback extends java.lang.Object implements com.shivdev.IFilter<br \/>\nSourceFile: &#8220;MyCallback.java&#8221;<br \/>\n<strong>  minor version: 0<br \/>\nmajor version: 49<\/strong><\/p><\/blockquote>\n<p>Then compare with the following:<\/p>\n<pre name=\"code\" class=\"javascript:nogutter\">\r\nmajor  minor  JDK\r\n45       3    1.0\r\n45       3    1.1\r\n46       0    1.2\r\n47       0    1.3\r\n48       0    1.4\r\n49       0    1.5\r\n50       0    1.6<\/pre>\n<p>Alternatively, you can use this java class to find out the version:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class FindVersion {\r\n\r\n    private static int convert(byte upper, byte lower) {\r\n        int ret =  upper &amp;lt;&amp;lt; 8;\r\n        ret |= lower;\r\n        return ret;\r\n    }\r\n\r\n    public static void main(String[] args) throws Exception {\r\n    \t\tfinal String CLASS = &quot;MyCallback.class&quot;;\r\n        ClassLoader loader = FindVersion.class.getClassLoader();\r\n        java.io.InputStream in = loader.getResourceAsStream(CLASS);\r\n        try {\r\n            byte[] buffer = new byte[8];\r\n            in.read(buffer);\r\n            int minor = convert(buffer[4], buffer[5]);\r\n            int major = convert(buffer[6], buffer[7]);\r\n            System.out.println(major + &quot;.&quot; + minor);\r\n        } finally {\r\n            in.close();\r\n        }\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I got an UnsatisfiedLinkError and wanted to find out whether our JDK upgrade had caused it and did some searching and found that javap -verbose lets you find out the version of a compiled class. So get the class (could be in a JAR file) and then follow this example where I find the version [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/54"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":192,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/192"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}