UnsupportedClassVersionError is a runtime error thrown when Java code is compiled and run with incompatible and unsupported versions.
UnsupportedClassVersionError extends ClassFormatError which is a sub class of LinkageError.
This is not compiled time error but runtime error thrown when JVM tries to run a java class file with major and minor version are not supported.
error stack trace contains a message like an Unsupported major.minor version x.x.
x.x is a number corresponding the version of your installed java version.
The simple fix is first to make sure that you install JDK and JRE with the same version.
JDK 10 – JRE 10, not JRE 8 or JRE 9 and not other versions
JDK 9 – JRE 9, not JRE 10 or JRE 9 and not other versions This error comes when running java programs with an incompatible version of compile and running program. This is an error case. java file was compiled with JDK 10 Run the java code using JDK 1.8
Please check below table for major.minor version for different java versions.
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
Both have different versions. This error comes when running java code. First, upgrade either JDK or JRE to the same version Once the same version is set, compile again and run the code
This error will come in the following cases 1. Compilation of code runs different higher java version 3. Execution of your code runs with lower java version This error comes in eclipse as well as command line
When you run java code, First change your project settings point to JDK, Next set java compiler to specific java version. Here are steps
Please check below to do eclipse configuration
provide source and target options with your version as specified
javac -source 1.8 -target 1.8 javafile.java This code is compatible with backward versions
Fix for UnsupportedClassVersionError in maven project is add source and target options for maven compiler plugin. This compiles and runs your project with the same version.