HOW TO FIX Java.Lang.UnsupportedClassVersionError: Unsupported Major Minor Version

Опубликовано: 02 Октябрь 2024
на канале: Begin Secure
3,265
7

In this video, we show you how to fix java.lang.UnsupportedClassVersionError version 51 (or some other number). What does the error mean, how can you prevent it and what version of the JDK or JRE should I be using? All these questions and more will be answered.

Check out the companion video that shows you how to determine the version of Java used to compile your class files here    • How To DETERMINE the JAVA VERSION Use...  

#IT #Development #SoftwareDevelopment #JavaProgramming #JavaTutorial #AppplicationSecurity #AppSec #appsecurity #informationsecurity #infosec

▬▬▬▬▬▬ T I M E S T A M P S ⏰ ▬▬▬▬▬▬

00:00 Introduction
00:16 Overview
01:25 Runtime error major.minor version xx explained
02:59 Java class file structure explained
03:16 Java version codes
04:19 Coding section - reproduce the problem
06:39 Show how to fix the problem with a new version of Java at runtime
09:05 Security Perspective on Java runtime environment

So the question we address in this video is, how can you fix the unsupported class version error exception when you run Java code?

Sometimes when you execute a Java application, whether it's code that you wrote, your team wrote, or someone else provided to you, you sometimes get the following error: Unsupported major dot minor version x, where x x is some decimal number.

What does this mean and how can you fix it? It means that you're attempting to run a class file that was compiled with the newer version of Java than you're using to execute the code.

The exception is thrown is java.lang.unsupportedclassversionerror, and it's a subclass of the java.lang.error class.

java.lang.error always indicates a serious problem in an application that should not be caught, and its subclasses are considered unchecked exceptions that are not checked during compilation.

So in that sense, they're equivalent to a runtime exception.

Let's say that you compiled your code with Java SE 11.

The version of the compiler used you stored in the class files.

If you try to run your code with Java SE version eight runtime, the unsupported class version error will be thrown indicating the incompatibility was detected.

Let's take a look at the problem in more detail by looking at the format of a Java class.

As you know, Java class files have a class extension. class files contain bytecode and this bytecode is executed by the Java Virtual Machine or JVM.

JVM is are available on many different platforms.

And a class file generated on one platform will execute on another JVM running on a different platform.
The ability to run code across platforms like this is one of the best features of Java.

In order to support this, the class files have to be well defined and maintained metadata to run properly.

There are 10 sections in a Java class file structure the section we're interested in is called the version of class file format.

It's two bytes long and located starting at byte offset six.

This is where we found the bytes the representative version of the file are used.

We see a list of the versions of Java over the years up to the current version of Java which is 17.

In the code column, we see the decimal and hex representation of the numbers