Java Unsupported Major Minor version 51 ERROR

I remember getting this error while running some Java.

Because it is annoying, let’s take a look at this. What does this error mean?
It turns out to be an issue of version incompatibility. First of all, if you don’t know, here is some background on how Java is run.

1. The Java source code (the .java file) is compiled. This step generates a .class file with the same prefix as the .java. In other words, if your source code is, your generated class file is Hello.class. This step is done by a Java compiler. If you run Java from command line, it is javac

2. Next, the .class file (called java bytecode) is run using a Java Virtual Machine (JVM). If you run in from command line, it is java Hello

Ok, back to error message. from Java class file, the number 51.0 is the version of the Java Class file (the ByteCode). 51 is Java 7, 50 is Java 6… The error message means that the Java Class file is compatible with Java 7 but the JVM is not. This happens when your source code was compiled by Java 7 and your run the bytecode with older JVM:

How to fix it (for Linux Ubuntu)?
You can fix this by either compiling your source code with older Java compiler OR running your bytecode with newer Java virtual machine. I will show you the second way: Installing Oracle JDK 7, which includes the JVM into your machine.

READ  Open Graph Protocol & Facebook

1. Download JDK 7 from here. Choose JDK 7. Extract the compressed file.

2. Move the extracted folder into /usr/lib/jvm

3. Install the new Java into system:

The “jdk_verion” is the name of the Jdk folder that you download.

4. Update current version to Java 7:

Choose the new version that you just installed.

5. After installing, Run:

to verify the change.

6. That’s basically it. If you run your Java inside Eclipse, you also need to update your Eclipse setting to make it work. In Eclipse Menu bar, open: Windows/Preference/Java/Installed JREs. Click ‘Add’ and add the path to the JRE 7 in the /usr/lib/jvm/jdk_version/jre. Apply, save and Eclipse should work fine.

Leave a Reply

Your email address will not be published. Required fields are marked *