Quick revision
The short answer
We run jdeps --jdk-internals on the application and every dependency jar to find calls to encapsulated JDK internals, with suggested replacements, and we look for the Java EE modules removed in Java 11, such as JAXB, JAX-WS and javax.activation, replacing them with Jakarta artifacts. Then jdeps --print-module-deps gives the list of JDK modules the application needs, and jlink builds a small runtime with just those modules for the container. Because reflection, service loading, JDBC drivers, crypto and locale data are not always detected, we test the image thoroughly and add modules such as jdk.crypto.ec or jdk.localedata as needed.
What to remember
In this answer, we used jdeps to find JDK internal API usage and removed Java EE modules when moving from Java 8 to 25, computed the required JDK modules with --print-module-deps, and built a small runtime with jlink. We also saw that reflection, service loading, drivers, crypto and locale data escape static analysis, so the image needs extra modules and thorough testing.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We run jdeps --jdk-internals on the application and every dependency jar to find calls to encapsulated JDK internals, with suggested replacements, and we look for the Java EE modules removed in Java 11, such as JAXB, JAX-WS and javax.activation, replacing them with Jakarta artifacts. Then jdeps --print-module-deps gives the list of JDK modules the application needs, and jlink builds a small runtime with just those modules for the container. Because reflection, service loading, JDBC drivers, crypto and locale data are not always detected, we test the image thoroughly and add modules such as jdk.crypto.ec or jdk.localedata as needed.
Why this question is asked
Upgrading from Java 8 straight to Java 25 crosses seventeen releases of changes: the module system, removed Java EE APIs, strong encapsulation of internals, and many smaller removals. Doing it blind means discovering problems one stack trace at a time in test environments. jdeps finds most of them statically, before we run anything, and jlink turns the result into a lean container runtime. Interviewers ask this scenario to see whether we know how to plan such a migration with the JDK's own tools. In this answer, we will scan for internal APIs, deal with removed modules, compute the module list, build the runtime with jlink, and then look at what static analysis misses.
1Scan for JDK Internal APIs
Java 8 code and old libraries often call JDK internals: sun.misc.BASE64Encoder, sun.misc.Unsafe, com.sun.* classes, or private fields of JDK classes through reflection. Since JDK 16 these internals are strongly encapsulated by default, and since JDK 17 there is no switch to turn that off globally, so such code fails with IllegalAccessError or InaccessibleObjectException, or with NoClassDefFoundError when the class was removed entirely. We run jdeps over the application and all its dependencies.
The report shows each class and the internal API it uses, and the table at the end suggests replacements. Removed APIs must be replaced now. sun.misc.Unsafe is still reachable through the jdk.unsupported module, but its memory-access methods are deprecated for removal and print warnings in recent JDKs, so we plan to replace them with VarHandle or the Foreign Function and Memory API. For third-party jars, the fix is usually upgrading to a version that supports modern JDKs, which is a good moment to list every dependency's minimum supported Java version.
2Replace the Removed Java EE Modules
Java 8 included several Java EE APIs inside the JDK: JAXB (javax.xml.bind), JAX-WS (javax.xml.ws), javax.activation, CORBA and common annotations. They were deprecated in Java 9 and removed in Java 11 by JEP 320. Code that uses them compiles and runs on Java 8 but fails on 11 and later with NoClassDefFoundError: javax/xml/bind/JAXBContext, or does not compile.
jdeps reports these as missing dependencies, and a search of the code and dependency tree for javax.xml.bind and javax.xml.ws finds the rest. The replacement is a separate library. For a modern stack, that means the Jakarta versions, jakarta.xml.bind-api with the Glassfish JAXB runtime, and Jakarta XML Web Services, which use the jakarta.* package names, so code and generated classes need their imports changed. Where the APIs were only used by an old dependency, upgrading or removing that dependency is often simpler. Other removals to check on the way to 25 include the Nashorn JavaScript engine (removed in 15) and the Security Manager, which can no longer be enabled since JDK 24.
3Compute the Module List
Once the code runs on Java 25, we ask jdeps which JDK modules the application actually needs. The options matter: --ignore-missing-deps stops it failing on optional dependencies that are not present, --multi-release 25 tells it which versioned classes to analyse in multi-release jars, and -cp gives it the dependency jars.
java.desktop often appears because some library uses java.beans, which lives in that module, so it stays even in a server application. The list is the starting point for jlink, not the final answer, as we will see.
4Build the Runtime With jlink
jlink assembles a custom runtime image that contains only the listed modules, plus the java launcher. The flags remove what a production container does not need.
- jdeps --jdk-internals on app and libsreplace removed and encapsulated APIs
- Remove or replace Java EE modulesJAXB, JAX-WS, activation -> Jakarta
- jdeps --print-module-depsstatically required modules
- Add dynamic-use modulescrypto, locales, JFR, naming, charsets
- jlink the runtimestrip debug, no headers, no man pages
- Full test suite passes on the image?YesShip the imageNoAdd the missing module and rebuild
6 steps in order. Play them, or step through them one at a time.
--strip-debug removes debug information, --no-header-files and --no-man-pages drop development files, and --compress shrinks the module data; the accepted compression values have changed across releases, so check your version. The image must be built with a JDK of the same version and platform as the target, and the base image's C library must match the JDK build, so an Alpine image needs a musl-based JDK.
5What Static Analysis Misses
jdeps sees direct references in bytecode. It cannot see code that finds classes by name at run time. ServiceLoader providers, JDBC drivers found through DriverManager, JNDI providers, charsets, locale data and security providers are all loaded that way, so the modules that provide them may be missing from the computed list. Typical additions are jdk.crypto.ec for elliptic-curve TLS on older JDKs (in recent JDKs its code moved into java.base, so check your version), jdk.crypto.cryptoki for PKCS11, jdk.localedata for locales other than English, jdk.charsets for extra character sets, jdk.naming.dns for DNS lookups through JNDI, jdk.zipfs for the zip file system, and jdk.jfr, jdk.management and jdk.jcmd if we want diagnostics in the container.
So we treat the image as untested until the full test suite and a realistic smoke test run against it, not against the build JDK. TLS connections to real endpoints, every database driver, date formatting in each supported locale and the JFR recording all need checking.
6Follow-up questions
What can break if a jlink image omits a module used only by reflection?
The application starts normally and fails later on the first use: a ClassNotFoundException or NoClassDefFoundError when the class is loaded by name, a ServiceLoader that silently finds no provider so a feature falls back or reports nothing available, TLS handshakes failing because a cipher suite or curve provider is missing, an UnsupportedCharsetException, or dates formatted in English instead of the user's locale. These failures are easy to miss in tests that do not exercise those paths, which is why the image needs a broad smoke test.
Should we jlink at all, or just use a vendor JRE image?
A vendor JRE image is simpler and already includes every runtime module, so nothing dynamic is ever missing, at the cost of a bigger image. jlink pays off when image size, attack surface or startup matter, or across many services where a curated runtime saves real storage and transfer. Many organisations jlink one shared runtime for all services rather than one per service.
Do we need to move to the module path to use jlink?
No. jlink builds the JDK part of the image from JDK modules, and our application can stay on the class path, as in the Dockerfile above. Only if the application itself is fully modular can jlink include it in the image too.
7Conclusion
In this answer, we used jdeps to find JDK internal API usage and removed Java EE modules when moving from Java 8 to 25, computed the required JDK modules with --print-module-deps, and built a small runtime with jlink. We also saw that reflection, service loading, drivers, crypto and locale data escape static analysis, so the image needs extra modules and thorough testing.
Open with
I would start with jdeps --jdk-internals over the application and every dependency jar. It lists each use of JDK internals, such as sun.misc.BASE64Encoder, which is removed, or sun.misc.Unsafe, which still exists in jdk.unsupported but is being phased out, and suggests replacements like java.util.Base64.
Then, if they want more
Since Java 17 strong encapsulation cannot be switched off globally, so these must be fixed or the libraries upgraded. Next, the Java EE modules: JAXB, JAX-WS, javax.activation and CORBA were removed in Java 11, so I replace them with the Jakarta artifacts, which also means the jakarta package names, or drop the old dependency that needed them.
Once it runs on 25, I compute the module list with jdeps --print-module-deps --ignore-missing-deps --multi-release 25 -cp 'lib/*' app.jar, and feed it to jlink with --strip-debug, --no-header-files and --no-man-pages, which gives a runtime well under a third of a full JDK. The catch is that jdeps only sees static references.
Anything loaded by name, like JDBC drivers, ServiceLoader providers, security providers, charsets and locale data, can be missing, so I add modules like jdk.crypto.ec on older JDKs, jdk.localedata, jdk.charsets and jdk.jfr as needed.
Then I run the full test suite and a smoke test with real TLS connections against the image itself, because missing modules only show up when that path runs.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 8, Java 11, Java 25, Java 16
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "You must upgrade a legacy application from Java 8 to Java 25 and build a small container...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/5c68c47995/