JDK (Java Development Kit): Components, Compile-to-Run Workflow and Exam Traps
Follow one Java class from source to bytecode, exact output and executable JAR. Along the way, learn what each JDK tool does and how to diagnose common launch and version errors.
KnowledgeGate Team
Exam prep & CS education

JDK, runtime environment and JVM often appear as nested boxes. Then javac, java, bytecode, classpaths and JAR files seem disconnected, so knowing that the JDK is "for development" does not explain why a compiled program can still fail. The JDK's tools connect source code to program output. ScoreTool.java stores 7, 11 and 14; javac creates out/demo/ScoreTool.class; the launcher prints Total=32, Average=10.67; and jar packages the same runnable class without changing that result. See Coding & DSA Courses for Placements for the broader programming path.
JDK, runtime environment and JVM are different layers
The JVM is the abstract execution machine for valid class files. A runtime environment combines it with standard libraries and supporting files for an already-built application. The JDK adds tools for compiling, packaging, documenting, inspecting, debugging and launching code. This is a responsibility model, not a promise of literal jdk/jre/jvm folders.
term | principal job | consumes or provides |
|---|---|---|
JVM | load, verify and execute class-file bytecode | valid |
runtime environment | provide the JVM and standard runtime libraries | what an already-built application needs |
JDK | build, inspect, package and also run Java programs | developer tools plus runtime capability |
Java is the language and platform; the JDK is a tool distribution, javac its compiler, and a JVM is not a compiler. Use Java JDK Setup: Install, Verify and Run Your First Program for installation, PATH configuration and an unpackaged first program. JRE and JVM Explained: How Java Loads and Executes Bytecode follows class loading, linking, initialization and runtime memory after launch. The JDK responsibility between source and launch is compiler output, packaging, inspection and compatibility.
Important JDK components and their development jobs
tool or area | exact role | illustrative use |
|---|---|---|
| compile |
|
| start a class, module, JAR or supported source-file launch |
|
| create, list, update or extract JAR archives | create |
| generate API documentation from declarations and documentation comments |
|
| inspect or disassemble class files |
|
| evaluate Java snippets interactively | test |
| debug a running Java program | set breakpoints and inspect state |
Specialised tools extend the kit: jdeps analyses dependencies, jlink builds a custom runtime image from modules, and jpackage creates application packages. Standard libraries and modules belong to the platform although they are not commands. This release-specific inventory and its command specifications follow the Oracle JDK 21 documentation. Vendors and releases need not share a directory layout.
Compile and run a packaged Java class

Start with src/demo/ScoreTool.java, empty out, and a JDK whose java and javac report major version 21:
package demo;
public class ScoreTool {
public static void main(String[] args) {
int[] scores = {7, 11, 14};
int total = 0;
for (int score : scores) {
total += score;
}
double average = (double) total / scores.length;
System.out.printf(
java.util.Locale.ROOT,
"Total=%d, Average=%.2f%n",
total,
average);
}
}Compile:
javac -d out src/demo/ScoreTool.javajavac selects the compiler; -d out sets the output root. Package demo creates out/demo/ScoreTool.class. Source stays unchanged.
Run:
java -cp out demo.ScoreTool-cp out names the classpath root, not demo or the class file. demo.ScoreTool is the fully qualified binary name. The loop gives 7 + 11 + 14 = 32; length 3; (double) 32 / 3 = 10.666...; %.2f under Locale.ROOT displays 10.67:
Total=32, Average=10.67
Package the class as a JAR and inspect it
Package the already-compiled class as an executable archive:
jar --create --file score-tool.jar --main-class demo.ScoreTool -C out .--create selects creation mode, --file names score-tool.jar, and --main-class records demo.ScoreTool in the manifest. -C out . changes into out before adding contents. The archive stores demo/ScoreTool.class, not out/demo/ScoreTool.class.
Use jar --list --file score-tool.jar to inspect it. The listing includes META-INF/MANIFEST.MF and demo/ScoreTool.class, with possible directory entries, but no particular order is guaranteed. Running java -jar score-tool.jar prints the same line:
Total=32, Average=10.67A JAR is a container, and its manifest supplies the entry class. Packaging does not recompile the arithmetic. Finally, javap -classpath out -c demo.ScoreTool disassembles the unarchived class. Look for bytecode operations corresponding to integer addition, array length, conversion to double and floating-point division, such as iadd, arraylength, i2d and ddiv. Exact instruction offsets are unnecessary; the useful connection is from source constructs to class-file instructions.
Java portability still depends on compatibility
Three facts condition Java portability. A JDK download targets an operating system and processor architecture. The .class format is hardware and operating-system independent. Execution still needs a compatible JVM, required libraries and a suitable environment. "Compile once, run anywhere" is conditional.
JDK 21's default target produces class-file major version 65. A Java 17 runtime supports level 61, so loading that output reports UnsupportedClassVersionError. On JDK 21, this targets the Java 17 language and documented API surface, producing version 61:
javac --release 17 -d out src/demo/ScoreTool.javaOracle's JDK 21 compiler documentation defines --release. It compiles with the selected language rules and documented API surface, and --release 17 emits Java 17-compatible class-file version 61. It does not turn JDK 21 into JDK 17 or bundle third-party dependencies. Java 8 to Java 21 Features Interviewers Actually Ask covers language and library evolution, while target selection controls the generated class format.
Diagnose JDK mistakes from the symptom
symptom | cause | repair |
|---|---|---|
| the class file targets a newer Java release than the selected runtime supports | align the runtime version or recompile with |
| the classpath root or fully qualified binary name is wrong | run |
| the public class and source filename do not match | rename the file to |
| the archive has no | recreate it with |
Supported source-file launch lets java SomeFile.java appear to skip javac, but compilation still occurs inside the launcher. The two-command model exposes artefacts; modern JDKs also launch supported source directly.
JDK questions test roles, artefacts, commands and outputs
Exam-style questions distinguish JDK, runtime environment and JVM; match javac, java, jar, javadoc, javap and jshell to their roles; order source, compiler, class file, launcher and JVM; choose a classpath root; trace output; and detect version mismatches.
Try six checks before the answers:
Which tool turns
ScoreTool.javainto a class file?What exact class file does
-d outcreate for packagedemo?Which command runs that class from
out?What are
totaland the two-decimal average?Which tool supplies the executable-JAR manifest and archive?
Can a Java 17 JVM load a default Java 21 class file?
Answers: (1) javac; (2) out/demo/ScoreTool.class; (3) java -cp out demo.ScoreTool; (4) 32 and 10.67; (5) jar; (6) no, class-file 65 exceeds supported level 61.
The short version and the next JDK step
Use this chain: install and select one JDK; write source in its package path; compile with javac; run the fully qualified class with java; package deployable classes with jar; diagnose failures through versions, classpaths and binary names. The worked path is {7, 11, 14} -> total 32 -> average 10.67 -> out/demo/ScoreTool.class -> score-tool.jar.
Replace the array with {9, 12, 15, 18}. Predict total = 54, length 4 and average 13.50, then rebuild and rerun the JAR. Continue with the Java Course: Concepts, MCQs & Coding Questions for structured practice.
Keep learning
Java JDK Setup: Install, Verify and Run Your First Program
Install Java with proof that your compiler and runtime agree. This tutorial separates JDK, JRE and JVM, then traces one program from source to exact output.
Static vs Dynamic Binding: Compile-Time Selection and Runtime Dispatch with a Worked Java Trace
See exactly what the Java compiler selects and what the runtime receiver can change. One program, six outputs, and declared-type variations make the two stages visible.
Java GUI Programming with Swing and AWT: Components, Events and Exam Traps
Learn one reliable way to read Java GUI code: map the container and layout, place each component, then trace the listener on the EDT. A complete Swing marks calculator connects the model to common objective and code-trace traps.
e-Governance Portals Explained: Service Models, Workflow and Worked Metrics
Learn how portals fit within e-governance, classify G2C, G2B, G2G and G2E interactions, trace a certificate workflow and calculate service metrics.





