Skip to the page

JVM, memory and Java versions · senior

Java versions, upgrades and dependency conflicts

Know what Java 17, 21 and 25 added, how to argue for an upgrade, what usually breaks, and how to fix a NoSuchMethodError caused by two library versions.

The notes

What you must know

  • In Java 17 already: text blocks, records, sealed classes, switch expressions, var. Java 21 (LTS): virtual threads, pattern matching for switch, record patterns, sequenced collections. Java 25 (LTS): scoped values, flexible constructor bodies, compact source files, plus faster start with the AOT cache.
  • Free wins with no code change: GC and JIT improvements, no pinning of virtual threads, smaller headers if enabled, faster start.
  • Preview features need --enable-preview at compile and run time and can change between releases. Most teams keep them out of production. Structured concurrency is still a preview; scoped values are final in Java 25.
  • ScopedValue: immutable, bound only for one call, readable by structured child tasks. ThreadLocal values are mutable and live as long as the thread, which leaks in pools.
  • Case for moving off Java 11: support and security updates, frameworks that need Java 17 or later, better GCs and memory use, and developer features. Plan: jdeps --jdk-internals and jdeprscan, upgrade build tools and bytecode libraries first, run CI on both JDKs, canary.
  • Breakages seen on the way to 25: Lombok needs annotationProcessorPaths (JDK 23 stops finding processors on the class path), dynamic agents warn (Mockito as a -javaagent), tools that read bytecode need newer versions (class file version 69 is Java 25), a narrow no-break space before AM/PM in time formats, Security Manager disabled.
  • NoSuchMethodError: a library was compiled against one version and runs with another. The JVM links methods by exact signature at runtime. Find it with mvn dependency:tree -Dverbose and -Xlog:class+load=info.
  • Maven picks the nearest declaration; Gradle picks the highest version by default. Fix: pin in dependencyManagement or a BOM, exclusions, Maven Enforcer rules (dependencyConvergence). ClassNotFoundException: loading by name failed. NoClassDefFoundError: the class existed at compile time but is missing or failed to initialise at runtime. Class loaders delegate to the parent first.

The red pen

Common traps: mistake → fix

  • Mistake: Preview features are fine for production if they work

    Fix: they can change or disappear; use only with a plan.

  • Mistake: Going from 17 to 25 only breaks code

    Fix: usually build tools, agents, bytecode libraries and date text break.

  • Mistake: A green build proves the dependencies fit

    Fix: NoSuchMethodError appears only at runtime.

Easy to hard

Questions interviewers ask, easy to hard

  1. What did Java 21 and 25 add that you would use in a backend?
  2. Your manager asks why to move a service from Java 11 to 25. What do you say?
  3. The build broke after moving from Java 17 to 25. What do you check?
  4. After adding an SDK, the first call fails with NoSuchMethodError. What is going on?
  5. What problems do scoped values solve?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview