CAP477 · Unit 1: Java fundamentals
Java platform: JDK, JRE, JVM and bytecode
8 practice questions
Key points
- javac turns .java into bytecode .class; JVM runs it
- JDK includes JRE which includes JVM
- main is public static void
- Bytecode is platform independent, JVM is not
Java is a compiled and interpreted, object-oriented language designed for "write once, run anywhere".
Flow: source .java -> javac compiler -> bytecode .class -> run by the JVM on any OS. Bytecode is platform independent; the JVM is platform specific.
| Term | Meaning |
|---|---|
| JVM | Virtual machine that loads, verifies and executes bytecode; includes the JIT compiler and garbage collector |
| JRE | JVM + core class libraries needed to run programs |
| JDK | JRE + development tools (javac, jar, javadoc, debugger) to build programs |
Entry point: public static void main(String[] args). It is public so the JVM can call it, static so no object is needed, and void because it returns nothing to the JVM.
Rules: a public class must live in a file with the same name (Main in Main.java). Java is case sensitive. Execution stops at the end of main; the process exit code is 0 unless System.exit(n) or an uncaught exception intervenes.
Features: automatic garbage collection, no pointer arithmetic, strong typing, built-in multithreading, and security through the bytecode verifier.
Exam pitfall: JDK contains JRE contains JVM; the JVM alone cannot compile.
Try two questions
Java achieves 'write once, run anywhere' because:
- Java has no standard library
- Source code is compiled separately for each OS
- Bytecode runs on any platform that has a JVM
- The JVM is identical on all platforms internally
Show the answer
C. The same .class files run on any JVM; each platform supplies its own JVM.
Which tool is part of the JDK but not of the JRE?
- javac
- The garbage collector
- The JVM
- The class libraries
Show the answer
A. Only the JDK ships the compiler and development tools.