Tuesday, December 29, 2015

Resolving Unsupported major.minor version 51.0 error

Have came across this error on number of occasions.

Unsupported major.minor version 51.0 error

The reported major numbers are:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
(Source: http://en.wikipedia.org/wiki/Java_class_file)



This java error comes, if you are compiling your code in java 1.7 and running it in JRE of lower version. To fix this, either you run the java class in a higher version (1.7 in this case) or instruct the compiler to create a 1.6 complaint byte code.

So, major number's represent the compiler version of the compiled bytecode here. And, may be, minor means, the JRE version you are trying to execute it in. (That's my analogy, I may not precise here, but it works for me, to recall.)
 
Fixing it in Ecplise project:
This can be done in eclipse , by right click the on the Project folder => Properties. Then choose compiler option => choose 1.6.

Fixing it in ItelliJIdea project:
File => Settings->Compiler => Java Compiler => Choose 1.6 under the Project byte code version drop down

There is a interesting story behind the convention of these numbers. If you are interested to read about it, you can find it here : James Gosling private communication to Bill Bumgarner (Source Wikipedia)





No comments:

Post a Comment

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...