How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version


I am trying to use Notepad++ as my all-in-one tool edit, run, compile, etc.

I have JRE installed, and I have setup my path variable to the .../bin directory.

When I run my "Hello world" in Notepad++, I get this message:

java.lang.UnsupportedClassVersionError: test_hello_world :
 Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)

I think the problem here is about versions; some versions of Java may be old or too new.

  1. How do I fix it?
  2. Should I install the JDK, and setup my path variable to the JDK instead of JRE?
  3. What is the difference between the PATH variable in JRE or JDK?
3/23/2019 6:42:00 AM

Accepted Answer

The version number shown describes the version of the JRE the class file is compatible with.

The reported major numbers are:

Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

(Source: Wikipedia)

To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.

For example, in order to generate class files compatible with Java 1.4, use the following command line:

javac -target 1.4

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath.

4/3/2020 3:14:07 PM

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.


In Eclipse, I just went to menu command Window -> Preferences -> Java -> Compiler and then set "Compiler compliance level" to 1.6.


Don't worry, I got it solved.

It is actually simple - you need to install BOTH JRE / JDK with the same version.

JRE 6 -> JDK 6

JRE 7 -> JDK 7

And so on.


This error means you're trying to load a Java "class" file that was compiled with a newer version of Java than you have installed.

For example, your .class file could have been compiled for JDK 7, and you're trying to run it with JDK 6.

So the solution is to either:

  • Upgrade your Java runtime or
  • Recompile the class if you have the source, using your local Java compiler (if you have one).


For developers, this can happen if another developer checks in a .class file, and they've got a newer version of java than you have!


You are trying to run your program with a Java version that does not support the version in which the code was compiled. So basically you must have compiled your code with a higher version and trying to run it using a lower version.

As you are getting

Unsupported major.minor version 51.0

and version 51.0 corresponds to J2SE 7 you have most probably compiled your code in Java 7 and trying to run it using a lower version. Check what java -version displays. It should be the Java 7 version. If not make appropriate changes in the PATH/JAVA_HOME. Or you can compile with the same version you are trying to run the code. If the configurations are confusing you can always give absolute path /home/user/jdk1.7.0_11/bin/javac and /home/user/jdk1.7.0_11/bin/java.