Fixing Unsupported Major.Minor Version 52.0 Fault Inwards Java

Unsupported major.minor version 52.0 comes when you lot are trying to run a course of teaching compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to prepare this fault is install the latest Java unloose i.e. Java 8 together with run your program. If upgrading to Java 8 is non an pick thence brand certain you lot role Java compiler's cross compilation characteristic together with compile source code for lower Java version yesteryear using -target pick of javac command. If you lot convey multiple JRE installed brand certain that the latest i comes origin inwards PATH environs variable. You tin post away larn "java.lang.unsupportedclassversionerror unsupported major.minor version 52.0" spell running a Java programme explicitly using java command or running a Java Applet inwards browser or running a Java programme from command trouble simply compiled inwards Eclipse or whatsoever other create tool similar Maven or ANT. Main argue of this fault is that during compilation, you lot convey used a higher version of JDK simply during deployment, you lot convey deployed into a lower version of JDK or JRE. Let's empathize the drive together with solution of Unsupported major.minor version 52.0 Error inwards niggling 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 create you lot larn a version mismatch fault if Java is backward compatible. Well, its truthful that Java is backward compatible, which way you lot tin post away run a Java course of teaching file or Java binary (JAR file) compiled inwards lower version (java 6) into higher version e.g. Java 8, simply it doesn't hateful that you lot tin post away run a course of teaching compiled using Java vii into Java 5, Why? because higher version normally convey features which are non supported yesteryear lower version.


Think about, tin post away you lot run lambda expression or Stream API code inwards Java 5, no right. Anyway, fifty-fifty if you lot are non using features which is non supported inwards lower version, every course of teaching file has a major or nipper version, which is populated yesteryear Java compiler, which is closely related to Java version. Here are the major version of every JRE released thence 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 post away encounter that Java 8 has major version 52, which way if you lot run javac command from Java 8 installation, it volition yesteryear default generate a course of teaching amongst major version 52. If you lot run this class file inwards JRE 7, you lot volition larn "Unsupported major.minor version 52.0". Same is the instance amongst an applet compiled inwards JDK 1.8, running inwards a browser amongst JRE 1.7.

BTW, Java allows you lot to generate course of teaching files supported yesteryear lower version. So, for example, you lot tin post away generate a Java course of teaching file for JDK 1.4 yesteryear running javac command amongst -target pick every bit shown below :

javac -target 1.4 HelloWorld.java

The Helloworld.class file generated yesteryear this command tin post away endure run inwards whatsoever version of Java 1.4 onward e.g. Java 1.4, Java five or Java 6.



Solution of Unsupported major.minor version 52.0 Error inwards Java

As I said earlier, at that topographic point are 2 ways to prepare "Unsupported major.minor version 52.0" error, origin upgrade to higher Java version or compiler Java source files for lower Java version of target environment. If you lot are getting "java.lang.unsupportedclassversionerror HelloWorld unsupported major.minor version 52.0", which way Java version inwards your PATH is lesser than Java 8. If you lot already installed the JDK 1.8 thence its due to wrong PATH setting. If you lot convey multiple JRE version installed thence lower version is coming ahead inwards PATH than higher version. To prepare this, examine your PATH environs variable together with brand certain the latest version of Java comes first. You don't need to deport on your CLASSPATH, because its non a classpath issue. Remember, difference betwixt PATH together with CLASSPATH.

If you lot cannot upgrade to higher Java version e.g. your production is running on JDK 1.6 together with your latest unloose is failing due to "Unsupported major.minor version 52.0" fault thence you lot need to prepare your create environment. Make certain to install the same JDK version for edifice your Java application every bit you lot are going to run inwards production. If that's non possible, role Java compiler's cross compilation pick to generate course of teaching file for your production Java/JRE version using javac -target option. For example, if your create environs is using Java vii together with your production environs is using Java 1.6 thence compile using java -target 1.6 pick to generate course of teaching files for Java 6.


In Applet

If you lot are trying to run an Applet from a website (internal or external) thence you lot don't convey whatsoever command on create or compile step. Your alone pick is to upgrade the JRE plugin of your browser to Java 8. Once you lot done that you lot should endure able to run the Applet compiled inwards whatsoever Java version without whatsoever issue, retrieve Java is backward compatible. BTW, from Java 8 onward safety has been tighten together with you lot cannot run an unsigned or self signed Applet inwards Java, peculiarly if you lot convey HIGH safety setting inwards Java Control Panel. Java 8 has also removed the MEDIUM safety settings, which before shows alert when you lot run such Applets.


In Eclipse

If you lot are compiling your Java programme inwards Eclipse together with running it from command line, thence you lot convey the pick to compile Java files for target environment. This is also necessary if you lot are exporting JARs from Eclipse. You tin post away modify compiler setting inwards Eclipse yesteryear selecting your project, properties, coffee compiler together with unchecked JDK compliance checkbox to modify the Compiler compliance level. By default Eclipse compiles based upon JRE version of the project, which could endure dissimilar inwards Java inwards your PATH, which comes into play when you lot run your Java programme from command line. Here is the screenshot of changing compiler compliance flat inwards Eclipse :
  • Select your project
  • Right click, choose properties
  • Choose Java Compiler
  • Uncheck JDK compilance cheque box

 comes when you lot are trying to run a course of teaching compiled using Java  Fixing Unsupported major.minor version 52.0 Error inwards Java

That's all nigh how to fix Unsupported major.minor version 52.0 Error inwards Java. In short, you lot are getting this fault because it is compiled amongst Java 8, source version 52 corresponds to Java 1.8 unloose simply you lot are trying to run this programme inwards lower JRE e.g. Java vii or Java 6. This way you lot convey 2 solution, origin upgrade to Java 8 or compiler your programme for lower version fifty-fifty if you lot are using Java 8 compiler yesteryear using -target pick of javac command. If you lot are using Maven, ANT or whatsoever other create tool to generate your course of teaching files, brand certain they convey got the right settings too.

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



Sumber https://javarevisited.blogspot.com/

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

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel