JDK diagnostics tools
What you will learn
JDK tooling helps inspect compiled artifacts before running them and investigate owned JVMs during execution. Choose the tool according to the evidence needed; a dependency report cannot replace a runtime trace.
- Select javap, jdeps, jdeprscan and javadoc for artifact inspection.
- Separate runtime observations from static analysis.
- Document a reproducible diagnostic workflow on an owned project.
Each example is a complete Main.java file. Use a fresh lab-owned directory: javac --release 21 -proc:none Main.java, then java Main. Use only trusted local classes and fixed synthetic data. For module commands use the companion lab described below. Never load unknown native code or attach to another process. The runner enforces a process deadline.
Inspect the current JDK feature version
public class Main {
public static void main(String[] args) throws Exception { System.out.println(Runtime.version().feature() >= 21); System.out.println(!System.getProperty("java.vendor").isBlank()); }}Expected output:
truetrueThe test asserts a lower bound and presence of vendor information, not a fixed vendor string.
Static inspection workflow
Compile the companion project, run javap -p -c -classpath mods/lab.app lab.app.Main to inspect declarations and bytecode, and jdeps --module-path jars --module lab.app for dependencies. jdeprscan --release 21 jars/lab.app.jar looks for uses of deprecated Java SE APIs; it does not scan all third-party deprecations. javadoc -d docs --module-source-path src --module lab.api generates API documentation for the service contract. Review the output and exit status; warnings vary by version. Do not run tools on arbitrary archives or annotation processors.
Runtime diagnosis
For a test-owned JVM, use its exact PID and jcmd PID VM.version or jcmd PID Thread.print for version and thread evidence. JFR and jfr summary provide recorded event evidence; see Chapter 38 for the validated JFR and owned-process labs. jstack, jstat, jmap and GUI tools can have distribution, attach and permission limitations. Diagnostic output can contain private paths or data. Do not assume a tool is available just because the JDK version is known.
Make reports reproducible
Record JDK version/vendor, OS, tool flags, build revision and observed behavior. Keep the synthetic inputs and sanitized logs with the lesson. Distinguish a missing dependency from a deprecation warning and a runtime linkage failure. Fix public API usage or the declared dependency graph before considering override flags. Avoid treating lack of warnings as proof of security or compatibility.
Discover a documented tool provider
public class Main {
public static void main(String[] args) throws Exception { var tool = java.util.spi.ToolProvider.findFirst("jar"); System.out.println(tool.isPresent()); System.out.println(tool.orElseThrow().name()); }}Expected output:
truejarA full JDK has the jar provider; a minimal runtime image may omit jdk.jartool.
Inspect a method descriptor
public class Main {
public static void main(String[] args) throws Exception { var type = java.lang.invoke.MethodType.methodType(int.class, String.class); System.out.println(type.toMethodDescriptorString()); }}Expected output:
(Ljava/lang/String;)IThe JVM descriptor encodes the String parameter and int return. javap -s can show descriptors for classfiles.
Common mistakes
Do not confuse javap output with Java source, assume jdeps is an exhaustive runtime dependency tracer, or attach diagnostics to unrelated processes.
Practice
Find the jdeps ToolProvider in a full JDK and print its name. Then inspect lab.app.Main with javap and explain why the classfile does not contain every runtime service provider.
Expected output:
jdepsCompare your answer with the manual practice criteria.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JDK diagnostics tools — knowledge check
Original module, packaging and native-interface questions.
Which tool disassembles bytecode?
What does jdeprscan detect?
Which tool generates API documentation?
Which process is appropriate for diagnostic attachment?
What should accompany a diagnostic report?