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

Updated 26 Nov 20266 min read
JDK (Java Development Kit): Components, Compile-to-Run Workflow and Exam Traps

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 .class files plus runtime data

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

javac

compile .java source into .class files

javac -d out src/demo/ScoreTool.java

java

start a class, module, JAR or supported source-file launch

java -cp out demo.ScoreTool

jar

create, list, update or extract JAR archives

create score-tool.jar

javadoc

generate API documentation from declarations and documentation comments

javadoc -d docs src/demo/ScoreTool.java

javap

inspect or disassemble class files

javap -classpath out -c demo.ScoreTool

jshell

evaluate Java snippets interactively

test 32.0 / 3

jdb

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

Java source compiles to out/demo/ScoreTool.class, then runs with java -cp out to print total 32 and average 10.67.

Start with src/demo/ScoreTool.java, empty out, and a JDK whose java and javac report major version 21:

java
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:

Code
javac -d out src/demo/ScoreTool.java

javac selects the compiler; -d out sets the output root. Package demo creates out/demo/ScoreTool.class. Source stays unchanged.

Run:

Code
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:

Code
Total=32, Average=10.67
JDK workflow diagram showing ScoreTool.java compiled to ScoreTool.class, totals 32 and average 10.67, with direct JVM and executable JAR paths producing the same output.

Package the class as a JAR and inspect it

Package the already-compiled class as an executable archive:

Code
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:

Code
Total=32, Average=10.67

A 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:

Code
javac --release 17 -d out src/demo/ScoreTool.java

Oracle'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

UnsupportedClassVersionError

the class file targets a newer Java release than the selected runtime supports

align the runtime version or recompile with javac --release 17 when Java 17 is the required target

Could not find or load main class demo.ScoreTool after compilation

the classpath root or fully qualified binary name is wrong

run java -cp out demo.ScoreTool from the project root

public class ScoreTool is in another filename

the public class and source filename do not match

rename the file to ScoreTool.java

no main manifest attribute, in score-tool.jar

the archive has no Main-Class entry

recreate it with jar --create --file score-tool.jar --main-class demo.ScoreTool -C out .

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:

  1. Which tool turns ScoreTool.java into a class file?

  2. What exact class file does -d out create for package demo?

  3. Which command runs that class from out?

  4. What are total and the two-decimal average?

  5. Which tool supplies the executable-JAR manifest and archive?

  6. 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.