Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Java builds (Maven, Gradle, JAR, WAR)

A Java app fails at startup with UnsupportedClassVersionError. What does it mean and how do you fix it?

IntermediateTroubleshootingJava builds (Maven, Gradle, JAR, WAR)
Answer

Short answer

It means the code was compiled with a newer Java version than the one running it. For example, built with Java 21 (class file version 65) but started on Java 17 (supports up to 61). Fix it by running on the same or newer Java version, or compile for the older target.

The error

java.lang.UnsupportedClassVersionError: com/shop/OrdersApplication has been compiled by a
more recent version of the Java Runtime (class file version 65.0), this version of the
Java Runtime only recognizes class file versions up to 61.0

Class file versions to remember

Java Class file version
8 52
11 55
17 61
21 65

How to fix

  1. Check the runtime: java -version on the server, or the base image tag in the Dockerfile (eclipse-temurin:17-jre).
  2. Check the build target in pom.xml: <java.version>21</java.version> or <maven.compiler.release>21</maven.compiler.release>.
  3. Make them match — usually by upgrading the runtime image to eclipse-temurin:21-jre.

Prevention

Pin the same Java version in three places: pom.xml, the CI setup-java step and the Dockerfile base image.

What to say in the interview

"UnsupportedClassVersionError means a build/runtime Java mismatch — compiled on a newer JDK than the runtime. I compare the class file version in the error with java -version, then align the runtime image with the compile target."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

More on Java builds (Maven, Gradle, JAR, WAR)