Fixing Unsupported Major.Minor Version 52.0 Mistake Inwards Java

Unsupported major.minor version 52.0 comes when y'all are trying to run a shape compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to create this mistake is install the latest Java unloosen i.e. Java 8 together with run your program. If upgrading to Java 8 is non an selection thus brand certain y'all purpose Java compiler's cross compilation characteristic together with compile origin code for lower Java version yesteryear using -target selection of javac command. If y'all bring multiple JRE installed brand certain that the latest i comes showtime inwards PATH environs variable. You tin teach "java.lang.unsupportedclassversionerror unsupported major.minor version 52.0" piece running a Java plan explicitly using java command or running a Java Applet inwards browser or running a Java plan from command trace of piece of job merely compiled inwards Eclipse or whatever other create tool similar Maven or ANT. Main argue of this mistake is that during compilation, y'all bring used a higher version of JDK merely during deployment, y'all bring deployed into a lower version of JDK or JRE. Let's sympathize the crusade together with solution of Unsupported major.minor version 52.0 Error inwards footling to a greater extent than detail.

TL:DR; upgrade to Java 8 or compile for lower JRE version using java -target 1.6 option.


Cause of Unsupported major.minor version 52.0 Error inwards Java

Many people think why produce y'all teach a version mismatch mistake if Java is backward compatible. Well, its truthful that Java is backward compatible, which agency y'all tin run a Java shape file or Java binary (JAR file) compiled inwards lower version (java 6) into higher version e.g. Java 8, merely it doesn't hateful that y'all tin run a shape compiled using Java seven into Java 5, Why? because higher version unremarkably bring features which are non supported yesteryear lower version.


Think about, tin y'all run lambda expression or Stream API code inwards Java 5, no right. Anyway, fifty-fifty if y'all are non using features which is non supported inwards lower version, every shape file has a major or youngster version, which is populated yesteryear Java compiler, which is closely related to Java version. Here are the major version of every JRE released thus far :

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

You tin come across that Java 8 has major version 52, which agency if y'all run javac command from Java 8 installation, it volition yesteryear default generate a shape alongside major version 52. If y'all run this class file inwards JRE 7, y'all volition teach "Unsupported major.minor version 52.0". Same is the instance alongside an applet compiled inwards JDK 1.8, running inwards a browser alongside JRE 1.7.

BTW, Java allows y'all to generate shape files supported yesteryear lower version. So, for example, y'all tin generate a Java shape file for JDK 1.4 yesteryear running javac command alongside -target selection every bit shown below :

javac -target 1.4 HelloWorld.java

The Helloworld.class file generated yesteryear this command tin live on run inwards whatever version of Java 1.4 onward e.g. Java 1.4, Java v or Java 6.



Solution of Unsupported major.minor version 52.0 Error inwards Java

As I said earlier, in that place are 2 ways to create "Unsupported major.minor version 52.0" error, showtime upgrade to higher Java version or compiler Java origin files for lower Java version of target environment. If y'all are getting "java.lang.unsupportedclassversionerror HelloWorld unsupported major.minor version 52.0", which agency Java version inwards your PATH is lesser than Java 8. If y'all already installed the JDK 1.8 thus its due to wrong PATH setting. If y'all bring multiple JRE version installed thus lower version is coming ahead inwards PATH than higher version. To create this, examine your PATH environs variable together with brand certain the latest version of Java comes first. You don't necessitate to acquit on your CLASSPATH, because its non a classpath issue. Remember, difference betwixt PATH together with CLASSPATH.

If y'all cannot upgrade to higher Java version e.g. your production is running on JDK 1.6 together with your latest unloosen is failing due to "Unsupported major.minor version 52.0" mistake thus y'all necessitate to create your create environment. Make certain to install the same JDK version for edifice your Java application every bit y'all are going to run inwards production. If that's non possible, purpose Java compiler's cross compilation selection to generate shape file for your production Java/JRE version using javac -target option. For example, if your create environs is using Java seven together with your production environs is using Java 1.6 thus compile using java -target 1.6 selection to generate shape files for Java 6.


In Applet

If y'all are trying to run an Applet from a website (internal or external) thus y'all don't bring whatever command on create or compile step. Your exclusively selection is to upgrade the JRE plugin of your browser to Java 8. Once y'all done that y'all should live on able to run the Applet compiled inwards whatever Java version without whatever issue, yell upwards Java is backward compatible. BTW, from Java 8 onward safety has been tighten together with y'all cannot run an unsigned or self signed Applet inwards Java, particularly if y'all bring HIGH safety setting inwards Java Control Panel. Java 8 has also removed the MEDIUM safety settings, which before shows alarm when y'all run such Applets.


In Eclipse

If y'all are compiling your Java plan inwards Eclipse together with running it from command line, thus y'all bring the selection to compile Java files for target environment. This is also necessary if y'all are exporting JARs from Eclipse. You tin alter compiler setting inwards Eclipse yesteryear selecting your project, properties, coffee compiler together with unchecked JDK compliance checkbox to alter the Compiler compliance level. By default Eclipse compiles based upon JRE version of the project, which could live on unlike inwards Java inwards your PATH, which comes into play when y'all run your Java plan from command line. Here is the screenshot of changing compiler compliance flat inwards Eclipse :
  • Select your project
  • Right click, pick out properties
  • Choose Java Compiler
  • Uncheck JDK compilance banking venture check box

 comes when y'all are trying to run a shape compiled using Java  Fixing Unsupported major.minor version 52.0 Error inwards Java

That's all most how to fix Unsupported major.minor version 52.0 Error inwards Java. In short, y'all are getting this mistake because it is compiled alongside Java 8, origin version 52 corresponds to Java 1.8 unloosen merely y'all are trying to run this plan inwards lower JRE e.g. Java seven or Java 6. This agency y'all bring 2 solution, showtime upgrade to Java 8 or compiler your plan for lower version fifty-fifty if y'all are using Java 8 compiler yesteryear using -target selection of javac command. If y'all are using Maven, ANT or whatever other create tool to generate your shape files, brand certain they bring got the right settings too.

Further Learning
Complete Java MasterClass
Java Memory Management
Understanding the Java Virtual Machine: Class Loading together with Reflection


0 Response to "Fixing Unsupported Major.Minor Version 52.0 Mistake Inwards Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel