The java.lang.unsupportedclassversionerror unsupported major.minor version 60.0 error comes in Java environment when you compile your Java file in a higher Java version like Java 16 and then trying to run the same Java program in lower Java version like Java 11. Java is backward compatible, I mean you can run your Java 15 binary or JAR into Java or JRE 16 but vice-versa is not true. You can not run a Java program that is compiled in a higher Java version into lower JRE. class file version changes between every Java version and class file generated by the javac command of Java 16 installation is not appropriate for JRE of Java 15 Installation.
In order to solve java.lang.unsupportedclassversionerror unsupported major.minor version 49.0, 50.0, 55.0, 57.0, 60.0, 61.0 or 62.0 we need to first understand What is the major and minor version of class file in Java. Every Java release has a major source version as shown in this table
In order to solve java.lang.unsupportedclassversionerror unsupported major.minor version 49.0, 50.0, 55.0, 57.0, 60.0, 61.0 or 62.0 we need to first understand What is the major and minor version of class file in Java. Every Java release has a major source version as shown in this table
Java Version Major Version
Java 4 48.0
Java 5 49.0
java 6 50.0
java 7 51.0
java 8 52.0
java 9 53.0
java 10 54.0
java 11 55.0
java 12 56.0
java 13 57.0
java 14 58.0
java 15 59.0
java 16 60.0
java 17 61.0
java 18 62.0
So if you compile your Java source file with javac of JDK 16 it will create class files with major version 60.0 and if you run those class files with Java 15 it will throw java.lang.unsupportedclassversionerror unsupported major.minor version 59.0 error or java.lang.UnsupportedClassVersionError: Bad version number in .class file.
Similarly if you compile Java program in Java 17 it will create a class file with major version 61.0 and if you run that on the lower java version you will get java.lang.unsupportedclassversionerror unsupported major.minor version 61.0 .
You can also see these free Java courses to learn more about class files in Java.
java.lang.unsupportedclassversionerror unsupported major.minor version Solution:
Fixing java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 error is easy, you just need to run with correct Java version. Always run with either the same version of JDK which is used during compilation or a higher version of JDK if the same version is not available.
Check your PATH environment variable to see if you have the correct Java in your path or not. alternatively, you can run the java -version in your console to check which version of Java comes first in your PATH e.g.
~/java java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
That's all on What is java.lang.unsupportedclassversionerror unsupported major.minor version 49.0 or 50.0 or 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, or 60.0, 61.0, and 62.0 and How to fix java.lang.unsupportedclassversionerror unsupported major.minor version error. Best use the same version of javac and java for compiling and running your Java application.
Other Java debugging and troubleshooting articles
Hello there, I am getting "unsupported major.minor version 51.0" Can you please help?
ReplyDeleteI was also getting same error in my project, which I am trying to run it from Eclipse. It's Maven based project and I am trying to running command Run as - Maven Install. Here is the error :
DeleteCaused by: java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0
In my case it was compiler settings which was wrong. I was using JDK 1.6 as Java library inside Eclipse settings but my build settings for compiler was 1.7 . for example, Java source level as 1.7. Once I change eclise JRE to 1.7 version this issue got resolved.
I think key here to remember that which major minor version for class files belongs to which Java release. Since 51.0 belongs to Java 7, it means class files are created by compiler shipped along with JDK 1.7. Now if you try to run those class files on any JVM other than Java 1.7, you will get that error because each of them will have lower major and minor version for class files.
ReplyDeleteHello Sir, I am getting "java.lang.UnsupportedClassVersionError: HelloWorldApp : Unsupported major.minor version 51.0" error while trying to run my first Java program from command prompt. I am using JDK 1.7 version. Can you please help to resolve this error?
ReplyDeleteHad this error for maven/mvn on my mac, even though I'd installed a newer JDK. The fix appears to be:
ReplyDeleteexport JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
Here are some more practical tips to deal with Unsupported major.minor version 52.0 error in Java.
ReplyDelete