Quick revision
The short answer
jshell is an interactive shell for trying Java code and APIs in seconds, javadoc turns doc comments into HTML API documentation, jar creates and inspects archives, and jdeps analyses which packages, modules and JDK internals a jar depends on. Each has one or two commands worth knowing by heart, and all of them ship with the JDK, not with a runtime-only image.
What to remember
In this answer, we went through four JDK tools: jshell for trying APIs interactively, javadoc for generating API documentation and checking doc comments, jar for creating and inspecting archives, and jdeps for finding dependencies and JDK internal API usage. We also saw that they ship with the JDK, not with runtime-only images.
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.
jshell is an interactive shell for trying Java code and APIs in seconds, javadoc turns doc comments into HTML API documentation, jar creates and inspects archives, and jdeps analyses which packages, modules and JDK internals a jar depends on. Each has one or two commands worth knowing by heart, and all of them ship with the JDK, not with a runtime-only image.
Why this question is asked
Build tools and IDEs hide most JDK tools from us, so many developers never run them directly. But each of these four tools answers a question faster than anything else: what does this API return, what will our published docs look like, what is actually inside this jar, and what will break on the next JDK. Interviewers ask this to see whether we can work below the build tool when we need to. In this answer, we will take each tool in turn, see a practical use and a command, and finish with where the tools are available.
1Jshell: Trying Code Without a Project
jshell, added in JDK 9, is a REPL, a read-eval-print loop: we type a Java expression or statement, and it runs it immediately and prints the result. There is no class to write, no main method and no compile step. It is ideal for checking how an API behaves before using it in real code, such as date arithmetic, regular expressions or string formatting.
Notice that each result gets a name such as $2, which we can use in the next line. Commands that start with a slash control the shell itself: /imports, /vars, /methods, /edit to change an earlier snippet, /save to keep snippets in a file and /exit to quit. jshell also completes names with the Tab key, which makes it a quick way to explore an unfamiliar class.
2Javadoc: Documentation From Doc Comments
javadoc reads the special /** ... */ comments in our source code and generates HTML documentation for every public class and method, the same format as the JDK's own API docs. It matters most for shared libraries, where other teams need to know how to call our code without reading it.
In practice, the Maven javadoc plugin or Gradle's javadoc task runs this for us and packages a -javadoc.jar for publishing. The tool also includes doclint, which checks doc comments for problems such as a missing @param or broken HTML; -Xdoclint:all turns on every check, and a build that publishes libraries should fail on these so the docs never rot.
3Jar: Creating and Inspecting Archives
A jar is a zip file with an optional manifest, META-INF/MANIFEST.MF, that holds metadata such as the main class. The jar tool creates them, but its most useful job in daily work is looking inside one, for example when we suspect a class is missing or a library is a fat jar with other libraries bundled in.
The -C classes . part means change into the classes directory and add everything there, so the package folders start at the root of the jar. --main-class writes the Main-Class line into the manifest, which is what java -jar reads. Older short options such as jar tf app.jar and jar cfe still work and appear in many scripts.
4Jdeps: Analysing Dependencies
jdeps reads class files and reports what they depend on: which packages, which JDK modules, and, most usefully, which JDK internal APIs. Internal APIs are classes such as sun.misc.BASE64Encoder or sun.security.* that were never meant for applications. Since JDK 16 and 17, they are strongly encapsulated, so code that uses them can fail on a newer JDK.
| Tool | Question it answers | Command to remember |
|---|---|---|
| jshell | what does this API do? | jshell, then type an expression |
| javadoc | what will callers see? | javadoc -d docs -sourcepath src ... |
| jar | what is inside this archive? | jar --list --file app.jar |
| jdeps | what does this code depend on? | jdeps --jdk-internals app.jar |
The first command is the one to run before any JDK upgrade, because it lists the exact calls that will break and suggests replacements. The second produces a module list that jlink can use to build a small runtime image containing only those modules. Running jdeps with -summary or -s gives a short overview of which jar depends on which.
5Where the Tools Come From
All four tools are part of the JDK, the Java Development Kit, in its bin directory. A runtime-only image does not have them. That includes the slim JRE builds some vendors ship and any jlink image that does not include the modules jdk.jshell, jdk.javadoc, jdk.jartool and jdk.jdeps. So a production container built on a JRE image cannot run jdeps or jshell; we run them in CI or on a developer machine against the same artifacts, or temporarily in a JDK-based debug image.
6Follow-up questions
How would you load a project jar into jshell?
Start it with the class path: jshell --class-path target/classes:target/lib/a.jar:target/lib/b.jar, then import the packages we want. To get the dependency list from Maven, run mvn dependency:build-classpath -Dmdep.outputFile=cp.txt and pass its content after target/classes. Inside a running session, /env --class-path changes the class path, which resets the session state.
Why use jar --describe-module?
To see whether a jar is a real module with a module-info, what name it has and what it exports and requires. For a plain jar it reports the automatic module name it would get on the module path, which tells us how other modules must refer to it.
Is jdeps useful if we do not use modules?
Yes. Its most common use, finding JDK internal API usage before an upgrade, has nothing to do with our own modules, and its module list output helps build smaller runtimes for class-path applications too.
7Conclusion
In this answer, we went through four JDK tools: jshell for trying APIs interactively, javadoc for generating API documentation and checking doc comments, jar for creating and inspecting archives, and jdeps for finding dependencies and JDK internal API usage. We also saw that they ship with the JDK, not with runtime-only images.
Open with
jshell is the REPL that came with JDK 9. I use it to check an API before writing code: for example LocalDate.of(2026, 1, 31).plusMonths(1) prints 2026-02-28, which settles the question of how month arithmetic clamps.
Then, if they want more
Commands like /imports, /vars and /exit control the shell, and Tab completion helps explore classes. javadoc generates HTML documentation from the doc comments, for example javadoc -d build/docs -sourcepath src/main/java -subpackages com.acme.api.
Usually the Maven or Gradle plugin runs it, and doclint, with -Xdoclint:all, catches missing @param tags and broken HTML, which matters for shared libraries. jar creates and inspects archives. jar --list --file app.jar shows what is inside, jar --describe-module shows a module's name, exports and requires, and jar --create --file app.jar --main-class com.acme.App -C classes . builds a runnable jar. jdeps analyses dependencies. jdeps --jdk-internals legacy.jar lists every use of JDK internal APIs, like sun.misc.BASE64Encoder, with suggested replacements, which is the first thing I run before a JDK upgrade, and jdeps --print-module-deps gives the list of JDK modules for jlink.
One practical point: these tools ship with the JDK, so a runtime-only or jlink image without their modules does not have them, and I run them in CI instead.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 16, Java 9
- 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 "Give a practical use for each of these JDK tools in a Java project: jshell, javadoc, jar...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/0b4bb1ae10/