The java.lang.UnsupportedClassVersionError in Java happens when your code is compiled with one Java version but runs with another. This error means that the Java versions do not match, and your program won’t run.
In this blog, we will discuss how to fix the java.lang.UnsupportedClassVersionError in Java with examples, version mapping table, and best practices.
Table of Contents:
What is java.lang.UnsupportedClassVersionError?
java.lang.UnsupportedClassVersionError in Java occurs when a Java program is compiled with one version but executed with another.
For example, if you compile a Java program with JDK 17 and try to run it using JRE 11, a Java version mismatch error will occur because JRE 11 does not understand the bytecode generated by JDK 17. To fix this Java version mismatch error, ensure that your JRE version matches or is higher than the JDK version used for compilation, allowing the Java Virtual Machine to properly execute the code..
What Causes the UnsupportedClassVersionError in Java?
This Java version mismatch error mainly occurs when the Java versions are not the same, like when the program is compiled with different Java versions and executed in different versions.
Java is a backward-compatible programming language, which means a Java class file or binary file (JAR file) compiled on a lower version of Java can be executed on a higher version. However, the opposite is not true, i.e., a class compiled on a higher version of Java cannot be executed on a lower version. This is because the higher version contains features that are not present in the lower versions. Due to this, the java.lang.UnsupportedClassVersionError in Java occurs.
Master Java Today - Accelerate Your Future
Enroll Now and Transform Your Future
Understanding Java Version Compatibility
Let us discuss some of the Java versions that are required to see when the java.lang.UnsupportedClassVersionError in Java occurs.
The following table shows the Java versions and their class file versions:
Java Version |
Class File Version |
Java 1.1 |
45 |
Java 1.2 |
46 |
Java 1.3 |
47 |
Java 1.4 |
48 |
Java 5 |
49 |
Java 6 |
50 |
Java 7 |
51 |
Java 8 |
52 |
Java 9 |
53 |
Java 10 |
54 |
Java 11 |
55 |
Java 12 |
56 |
Java 13 |
57 |
Java 14 |
58 |
Java 15 |
59 |
Java 16 |
60 |
Java 17 |
61 |
Java 18 |
62 |
Java 19 |
63 |
Java 20 |
64 |
Java 21 |
65 |
Java 22 |
66 |
Java 23 |
67 |
Java 24 |
68 |
With the help of the above table, you will get to know about Java version in which your code was compiled. After which, you can install the dedicated Java version on your system.
How to Fix java.lang.UnsupportedClassVersionError (7 Methods)
To fix UnsupportedClassVersionError, also known as the Java version mismatch error, you should make sure that the Java version with which you are compiling the project is the same as the version with which you are executing your project.
Method 1: Check Java Version
You can run the following commands to check the Java version
java -version
or
javac -version
Method 2: Compile for an Older Java Version
If the above JRE is not possible, you can downgrade the JDK to the same version as the production. Use the following command to compile the Java program to a specific version
javac --release X YourFile.java
where,
X is the Java version
YourFile is the name of the Java file
Method 3: Set JAVA_HOME and PATH Correctly
The JAVA_HOME environment variable tells your system where Java is installed, while the PATH variable ensures that the Java commands like java and javac can be executed from any location in the terminal or command prompt.
If these are not set correctly for your system, it can use another Java version or will fail to understand the Java commands altogether. Hence, set JAVA_HOME to the correct JDK location.
Method 4: Update or Switch Java Runtime
The JRE version must be upgraded to the latest release or should be the same as the build environment. If multiple Java versions are installed on your system, then the default version used for execution and compilation can be changed. To ensure the correct version of the Java Virtual Machine, which is used to properly execute the code. is used, you need to update the default Java version on your system.
Method 5: Recompile with -target and -source
The Java compiling option can also be used to generate the .class file by using the javac-target command. For example, if the Java environment is using Java 1.8 for compiling and production is using Java 1.7, the following command can be used to generate a class file of Java 1.7.
javac -source 1.7 -target 1.7 <path-to-java-class>
Unlock Your Future in Java
Start Your Java Journey for Free Today
If your IDE is not using the correct Java version, it can cause issues and runtime errors. You should configure your IDE to one Java version.
Steps to Configure Java Version in Different IDEs
IntelliJ IDEA
- Check and Set up the JDK:
- Open File > Project Structure > Project.
- Under Project SDK, select the Java version or click Add JDK to add a new one.
- Check Compiler Settings:
- Go to File > Settings > Build, Execution, Deployment > Compiler > Java Compiler.
- Set the Target bytecode version to be the same as your Java version.
- Check the Run Configuration:
- Open Run > Edit Configurations.
- Ensure the correct JDK is selected.
Eclipse
- Check Installed JREs:
- Go to Window > Preferences > Java > Installed JREs.
- Add the JDK if it’s not listed and select it as the default.
- Set JDK for a Specific Project:
- Right-click the project, select Properties > Java Build Path.
- Under the Libraries tab, remove the old JDK and add the correct one.
- Configure the Compiler Level:
- Go to Window > Preferences > Java > Compiler.
- Set the Compiler level to your JDK version.
VS Code
- Ensure Java Extension is Installed:
- Install the Java Extension Pack from the VS Code marketplace.
- Set Java Home in VS Code Settings:
- Open Settings (Ctrl +, or Cmd +, on macOS).
- Search for Java: Home.
- Set it to the correct JDK path (e.g., C:Program FilesJavajdk-17).
NetBeans
- Check and Set JDK for NetBeans:
- Open Tools > Java Platforms.
- Add and select the JDK version.
- Set Java Version for a Project:
- Right-click the project and go to Properties > Libraries.
- Select the Java platform.
After the above steps, verify the IDE configuration using the following command.
java -version
javac -version
Method 7: Set the Correct Java Version in Maven
When using Maven, to fix the java.lang.UnsupportedClassVersionError: Unsupported major.minor version error, you should ensure that the Java version used to compile the code matches the runtime version of Java.
Also, the dependencies in the Maven are properly added as per the correct Java version.
Add the following dependencies to the pom.xml file of your Maven project.
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version> <!-- Use latest -->
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
Note: Replace the 11 with your Java version.
Now, run the Clean and Rebuild Command at the top right in your IDE for the Maven project.
Get 100% Hike!
Master Most in Demand Skills Now!
Java Version vs Class File Version Mapping Table
Here is a Java Version vs Class File Version mapping table that shows which class file version corresponds to each Java version:
Java Version |
Class File Version |
Decimal |
Hex |
Java 1.0 |
45.0 |
45 |
0x2D |
Java 1.1 |
45.3 |
45 |
0x2D |
Java 1.2 |
46.0 |
46 |
0x2E |
Java 1.3 |
47.0 |
47 |
0x2F |
Java 1.4 |
48.0 |
48 |
0x30 |
Java 5 |
49.0 |
49 |
0x31 |
Java 6 |
50.0 |
50 |
0x32 |
Java 7 |
51.0 |
51 |
0x33 |
Java 8 |
52.0 |
52 |
0x34 |
Java 9 |
53.0 |
53 |
0x35 |
Java 10 |
54.0 |
54 |
0x36 |
Java 11 |
55.0 |
55 |
0x37 |
Java 12 |
56.0 |
56 |
0x38 |
Java 13 |
57.0 |
57 |
0x39 |
Java 14 |
58.0 |
58 |
0x3A |
Java 15 |
59.0 |
59 |
0x3B |
Java 16 |
60.0 |
60 |
0x3C |
Java 17 |
61.0 |
61 |
0x3D |
Java 18 |
62.0 |
62 |
0x3E |
Java 19 |
63.0 |
63 |
0x3F |
Java 20 |
64.0 |
64 |
0x40 |
Java 21 |
65.0 |
65 |
0x41 |
Java 22 |
66.0 |
66 |
0x42 |
Best Practices to Prevent Version Conflicts
- Write the version number of every library you use in your build configuration so it doesn’t change.
- Lock the versions so your project always works in the same way, and do not give any Java version mismatch error.
- Be careful with big version changes, because they might break your code.
- Update libraries slowly and test after each update to make sure nothing has changed in your code.
- Use tools like Maven, Gradle, or npm to help manage your libraries.
- Check if any libraries are conflicting with each other or not.
- Split your project into small parts so problems in one part don’t create problems in your whole code.
- Don’t use test or unfinished versions of libraries in real projects.
- Use your own copy of libraries if you’re working with a team.
- Make simple rules for versions and share them with your team.
Conclusion
The java.lang.UnsupportedClassVersionError in Java occurs when Java compiles a program with a newer version, but runs it on an older one. To fix UnsupportedClassVersionError, you should use the same or a higher JRE, set the correct JAVA_HOME, or compile the program with an older version. Also, update your IDE settings to match the right Java version.
To know more about this topic, you can refer to our Java Course.
How to Fix java.lang.UnsupportedClassVersionError in Java – FAQs
Q1. How to fix the java.lang.UnsupportedClassVersionError version mismatch error?
This Java version mismatch error can be fixed by running the application on the same (or higher) JRE version as the JDK.
Q2. What is the major.minor version in Java?
A major.minor version error occurs when the Java Runtime Environment (JRE) that is used to run a program is older than the Java Development Kit (JDK) version that is used to compile its code.
Q3. How do I check the Java version?
You can check the Java version with the following command in your command prompt
java -version
Q4. What is the latest version of Java?
As of April 2, 2025, the latest version of Java is Java 24 (JDK 24), which was released on March 18, 2025. Check the official Oracle website for the latest updates, as Java versions are released regularly.
Q5. What is the difference between JRE and JDK?
The Java Development Kit (JDK) is used to develop Java applications, while the Java Runtime Environment (JRE) provides class libraries and other things that are needed to run Java applications on the Java Virtual Machine (JVM).