Version migration strategy
What you will learn
A migration changes a system that already works. Preserve its behavior while changing one compatibility boundary at a time: the JDK, build tools, dependencies, framework, or deployment environment. Compile success is one gate, not evidence that the whole application still works.
- Create a migration compatibility matrix.
- Distinguish source, binary and runtime compatibility.
- Use local dependency and class-file analysis before a runtime upgrade.
Plain Java 21: save each example as Main.java in a fresh directory, compile with javac --release 21 Main.java, then run java Main. Trusted local fixtures only. No network or third-party dependency is needed.
A simplified migration gate
public class Main { static boolean gate(int target,int runtime,boolean dependencies,boolean tests) { if(target<8 || runtime<8) throw new IllegalArgumentException("unsupported model input"); return target<=runtime && dependencies && tests; } public static void main(String[] args) throws Exception { System.out.println(gate(17,21,true,true)); System.out.println(gate(21,17,true,true)); System.out.println(gate(17,21,false,true)); }}Expected output:
truefalsefalseAn older classfile target is only one prerequisite; dependency and test evidence are separate. Preview features and actual runtime API compatibility are outside this model.
Build the matrix before changing versions
Record old and target JDK vendor/build, compiler release, classfile target, Maven/Gradle and plugin versions, framework BOM, database driver/server, native libraries and OS. Check vendor support, release notes, deployment flags, removed modules and security policies. Do not select an arbitrary newest release of each component. Baseline tests on the old environment first; run the unchanged artifact on the candidate runtime, then rebuild and retest. Retain the old artifact and compatible data backup; schema changes may block rollback.
Investigate with tools
javac --release 17 restricts language and documented platform APIs and generates class files for Java 17. -source and -target alone do not ensure the API baseline. Java 17 uses major version 61; Java 21 uses 65; Java 25 uses 69. javap -verbose inspects class metadata. jdeps --jdk-internals identifies static references to internal JDK APIs; jdeps --multi-release 21 --class-path ... can help analyze a multi-release JAR with its dependencies. jdeprscan --release 21 inspects deprecated Java SE API use. Reflection, service loading, configuration and native dependencies may escape static analysis. Inspect dependency trees for version conflicts and verify actual integration. The companion lab tests the local tools, not JDK 25.
Rollout and namespace boundaries
Upgrade compatible libraries before switching framework majors where possible. Jakarta EE 9 changed many enterprise package names, requiring compatible app server, libraries and descriptors. Java SE packages such as javax.crypto, javax.sql and javax.xml.parsers remain valid. Avoid global replacements. Test configuration binding, authorization, serialization contracts, transaction behavior and recovery against representative data.
Read a classfile major version
public class Main { public static void main(String[] args) throws Exception { try(var in=new java.io.DataInputStream(Main.class.getResourceAsStream("Main.class"))) { if(in.readInt()!=0xCAFEBABE) throw new IllegalArgumentException(); int minor=in.readUnsignedShort(); int major=in.readUnsignedShort(); System.out.println(minor); System.out.println(major); } }}Expected output:
065The fixture is compiled with --release 21 without preview features. The version identifies the classfile format, not all libraries it needs.
Identify packages by ownership
public class Main { public static void main(String[] args) throws Exception { System.out.println(javax.crypto.Cipher.class.getModule().getName()); System.out.println(javax.sql.DataSource.class.getModule().getName()); }}Expected output:
java.basejava.sqlBoth javax packages belong to Java SE. A blanket namespace replacement would break these imports.
Common mistakes
Do not confuse a classfile target with a fully compatible runtime, or fix missing classes by adding unreviewed dependencies. Do not change production flags or migrate data without a tested recovery plan.
Practice
Extend the migration gate to reject a compatible runtime if the dependency check fails. Print false then true for target 17/runtime 21, with the dependency flag false then true and tests passing.
Expected output:
falsetrueCompare with the manual review criteria.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Version migration strategy — knowledge check
Java maintenance and ecosystem reasoning.
What does --release 17 control?
Which tool inspects classfile metadata?
Why run existing tests on the old runtime first?
Which package remains Java SE?
Can jdeps discover every reflective dependency?