Java Unsupported Major Minor version 51 ERROR

I remember getting this error while running some Java.

error Unsupported major.minor version 51.0

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 Hello.java, 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 Hello.java

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:

 *.java --(Java compiler 7 ) --> *.class --> ( Older Java virtual machine)
 

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.

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:

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk_version/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk_version/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk_version/bin/javaws

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

4. Update current version to Java 7:

sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws

Choose the new version that you just installed.

5. After installing, Run:

java -version

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.

Read More Post

STAY CONNECTED

Most Popular

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know
17 Dec

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know

If you’re heading to Singapore for a few weeks or many months, maybe for work or study or just to

Manifesting Your Dream Career: Finding Your Passion And Purpose
01 Aug

Manifesting Your Dream Career: Finding Your Passion And Purpose

Are you passionate about finding your dream career? Manifesting can help you align your career with your passions and purpose.

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service
27 Feb

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service

Finding a reliable auto service provider is paramount in the bustling world of vehicle maintenance and repair. That's where Carolina

Floratam: The Robust Grass Solution From Council Growers SOD
25 Jan

Floratam: The Robust Grass Solution From Council Growers SOD

Floratam grass, a popular St. Augustine variety, has become a go-to choice for homeowners and landscapers seeking a lush, durable

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair
25 Jan

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair

For vehicle owners, the braking system is among the most critical components for safety and performance. Carolina Mobile Autoservice, a

Safeguarding Your Property: Expert Water Damage Services By MBC Capital
24 Jan

Safeguarding Your Property: Expert Water Damage Services By MBC Capital

Water damage can significantly impact homes and businesses, often leaving a trail of destruction and disruption in its wake. Understanding