How to Fix java.lang.UnsupportedClassVersionError in Java?
Last Updated :
28 Jan, 2021
The UnsupportedClassVersionError is a sub-class of the LinkageError and thrown by the Java Virtual Machine (JVM). When a class file is read and when major and minor version numbers are not supported, this error is thrown, and especially during the linking phase, this error is thrown
A sample snapshot of UnsupportedClassVersionError
Situations when the error is thrown :
When we tried to compile a program using a higher version of Java and execute it using a JVM of a lower version, this error is thrown. But the reverse case is not true.
Hence, it is important to note the java versions

Get the installed java version :
java –version (In command prompt(windows), we can give)
Check java version
Fixing the program via command line :
In order to overcome the UnsupportedClassVersionError, we can either compile our code for an earlier version of Java or run our code on a newer Java version. It is about our choice of decision only. If a third-party library is used then, it is better to run on a newer java version and if it is for distribution, it is best to compile to an older version.
Using JAVA_HOME Environment Variable :

While doing Java programs, always it is good to set JAVA_HOME and setting that value in path
We can check that in command prompt in the below way also
C:\Windows\system32>echo %JAVA_HOME%
C:\Program Files\Java\jdk-9.0.4
Requirements to run a java program on a new JRE:
Move to the directory and locate the bin directory. For example, if the JRE is in location like
C:\Program Files\Java\jdk-11.0.2, then navigate till C:\Program Files\Java\jdk-11.0.2\bin
Execute the program as
java <filename> // Even we can give filename with full package
Requirements to run a java program on an older JRE :
Example :
C:\Program Files\Java\jdk1.8.0_31\bin\javac <filename along with package>
In order to ensure compatibility, we can point “-bootclasspath” at the rt.jar of the targeted JRE:
javac -bootclasspath "C:\Program Files\Java\jdk1.8.0_31\jre\lib\rt.jar"
\ -source 1.8 -target 1.8 <filename>
[Applicable mainly to JDK 8 and lower]
But in JDK 9, the “–release” parameter was added to replace “-source” and “-target”.
The “–release” option supports targets 6, 7, 8, 9, 10, and 11. As an example, let us use “–release” to target Java 8:
javac --release 8 <filename>
There are many IDEs are available for Java development
Let us see how we can overcome “UnsupportedClassVersionError” in Eclipse
Selecting JRE using Java Build Path->Installed JREJava compiler level selection :
Java compiler selectionMaven
We can control the version of Java when we build and package a file in Maven. When using Java 7 or older, we set the source and target for the compiler plugin.
Let's set the source and target using compiler plugin properties:

–release option added in Java 9

Conclusion :
By setting the environment changes either via command-line way or via IDE way or via Maven way, we can overcome "unsupportedclassversion".
Similar Reads
Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s
10 min read
Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
15+ min read
Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it,
13 min read
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me
15+ min read
Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an
13 min read
Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac
15+ min read
Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt
10 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read