Java source compiles to bytecode—platform-neutral instructions for the JVM. That indirection is why the same JAR can run on macOS dev machines and Linux servers without recompiling source for each OS.
Key pieces
- JDK — Java Development Kit: compiler (
javac), tools, and a JRE - JRE — Java Runtime Environment: JVM + core libraries (mostly superseded by modular JDK images)
- JVM — loads classes, verifies bytecode, executes with interpreter + JIT
- .class files — one per class; packaged into JARs for deployment
Class loading and execution
- Class loader finds
Main.classon the classpath - Bytecode verifier checks safety constraints
- JVM invokes
Main.mainas the entry point - Hot methods get JIT-compiled to native code for speed
Important interview questions and answers
- Q: JDK vs JRE?
A: JDK includes development tools (compiler); JRE is runtime-only—modern deployments often use jlink/custom JDK images. - Q: What is bytecode?
A: Intermediate instructions for the JVM—not machine code for a specific CPU. - Q: Can other languages run on the JVM?
A: Yes—Kotlin, Scala, Clojure compile to bytecode and interoperate with Java libraries.
Self-check
- Which tool compiles
.javato.class? - Why does bytecode help portability?
Interview prep
- JDK vs JRE?
JDK includes development tools like
javac; JRE is runtime-only. Modern deployments often ship trimmed JDK images in containers.