2.4 Java Platform Features & Architecture
Key Takeaways
javacproduces platform-neutral class files. A compatible JVM and runtime libraries let the same class files run on different systems.In Oracle’s Java 8 distribution the JDK includes runtime components and development tools. The JRE includes the JVM, runtime libraries, and supporting files.
Java combines object orientation and encapsulation (private state behind public methods) with strong static typing checked at compile time
Automatic garbage collection reclaims unreachable heap objects without manual free/delete calls, while System.gc() is only a hint to the JVM
Java rejects raw pointer arithmetic, checks array indices at run time, and verifies class file constraints before a class is initialized.
Java Platform Features & Architecture
Domain 1 of the 1Z0-808 exam concludes with a conceptual objective: comparing and contrasting the features and components of Java—including platform independence, object orientation, encapsulation, strong typing, memory management, and runtime safety. Exam questions on this topic often mix accurate Java architecture facts with subtle myths (such as claiming that the JVM itself is platform-independent or that System.gc() forces immediate memory reclamation).
Platform Independence: "Write Once, Run Anywhere"
Traditional compiled languages such as C and C++ compile source code directly into CPU- and OS-specific machine instructions. A binary compiled for Linux x86-64 will not execute natively on Windows ARM64.
Java takes a two-stage approach often summarized as Write Once, Run Anywhere (WORA):
- Compile time: The
javaccompiler translates human-readable.javasource code into Java bytecode (.classfiles)—a compact, platform-neutral intermediate instruction set. - Runtime: A Java Virtual Machine (JVM) installed on the target operating system loads the
.classfiles, verifies them, and executes them. A JVM implementation such as HotSpot can use an interpreter and a just-in-time (JIT) compiler, which translates selected bytecode into native machine instructions.
Important
Distinguish the artifact from the engine: Java bytecode (.class) is platform-independent, whereas the JVM implementation itself is platform-dependent. You download a Windows JVM for Windows and a Linux JVM for Linux so both can run compatible class files. Native libraries, file paths, and other platform dependencies may still affect a whole application.
Comparing JDK, JRE, and JVM
Candidates frequently confuse the three core acronyms of the Java SE 8 platform. Each forms a concentric layer around the execution engine:
| Component | Full Name | Contains | Primary Purpose | Includes javac? |
|---|---|---|---|---|
| JVM | Java Virtual Machine | Classloader, bytecode verifier, execution engine (may use interpretation or JIT compilation), garbage collector | Executes .class bytecode and manages runtime memory | No |
| JRE | Java Runtime Environment | JVM + standard runtime libraries (including java.lang and java.util) + runtime config | End-user environment to run compiled Java programs | No |
| JDK | Java Development Kit | JRE + development tools (javac, jar, javadoc, jdb) | Developer environment to write, compile, debug, and run Java programs | Yes |
In short: . An end user who only runs existing Java applications needs a JRE; a developer writing and compiling .java files needs a JDK.
Object Orientation & Encapsulation
Java is an object-oriented language built around classes (blueprints) and objects (runtime instances holding state and behavior). Four pillars shape Java design:
- Encapsulation: Hiding internal object state (
privatefields) behind controlledpublicmethods (getters, setters, or domain operations). Encapsulation prevents callers from putting an object into an invalid state—for example, settingbalance = -500directly—and allows internal representation changes without breaking callers. - Inheritance: Allowing a subclass to reuse and specialize a superclass (
extends), sharing common contracts across related types. - Polymorphism: Allowing a single supertype or interface reference to invoke overridden behavior dynamically based on the actual runtime object.
- Abstraction: Exposing essential operations (via
abstractclasses andinterfacecontracts) while hiding implementation details.
public class Thermostat {
private int targetTemp = 72; // encapsulated state
public int getTargetTemp() {
return targetTemp;
}
public void setTargetTemp(int temp) {
if (temp >= 50 && temp <= 90) { // enforces valid invariant
this.targetTemp = temp;
}
}
}
Note that Java is primarily object-oriented rather than "purely" object-oriented because it retains eight built-in primitive types (boolean, byte, short, char, int, long, float, double) alongside its reference types.
Comparing Key Language & Runtime Features
| Feature | How Java Implements It | Exam Contrast / Trap |
|---|---|---|
| Strong Static Typing | A variable has a compile-time type checked by javac. Some types are inferred, such as for implicitly typed lambda parameters. | Assigning "abc" to an int variable fails at compile time, not runtime |
| Automatic Memory Management | Objects are allocated on the heap; the Garbage Collector (GC) reclaims unreachable objects | No manual free()/delete; System.gc() only suggests collection and never guarantees timing |
| Robustness & Safety | No raw pointer arithmetic; automatic array bounds checking (ArrayIndexOutOfBoundsException); checked/unchecked exceptions | A Java array read outside its valid bounds throws instead of reading neighboring storage |
| Security | Bytecode verifier validates .class stack/type integrity before execution; ClassLoader isolates namespaces | Verification checks class-file constraints, including correct operand types. Running untrusted code also requires appropriate controls. |
| Architecture Neutrality | Primitive widths are fixed by the JLS (int is always 32-bit, long is always 64-bit) | Unlike C/C++, primitive sizes never shift across 32-bit vs. 64-bit operating systems |
| Multithreading | Built-in concurrency primitives (Thread, Runnable, synchronized) | Multiple threads share heap memory and coordinate execution natively |
Compile-Time Safety vs. Runtime Verification
Seeing how these guarantees divide between javac and the JVM helps answer architecture questions accurately:
public class SafetyTrace {
public static void main(String[] args) {
// int count = "ten"; // Compile-time error: strong static typing
int[] scores = {90, 85};
// System.out.println(scores[2]); // Compiles, throws ArrayIndexOutOfBoundsException
String msg = new String("Ready");
msg = null; // Original "Ready" object becomes eligible for GC
System.gc(); // Non-binding hint only; JVM decides when/if GC runs
System.out.println(scores.length);
}
}
Before SafetyTrace.class even starts executing main, the JVM's classloader loads the bytecode and the bytecode verifier checks structural and static constraints such as operand-stack type consistency. Linking also applies access checks when resolving symbolic references. During execution, strong static typing has already prevented incompatible variable assignments, while runtime bounds checks ensure out-of-range array access fails cleanly with an exception instead of corrupting adjacent memory.
Note
A common misconception is that Java guarantees zero memory leaks because of garbage collection. Garbage collection manages unreachable objects. An application can still retain memory unintentionally if it keeps reachable references (for example, in a static List) to objects it no longer needs.
Which statement accurately compares the JDK, JRE, and JVM in Java SE 8?
The JRE includes javac and javadoc so developers can compile .java source files
The JVM is platform-independent, whereas .class bytecode files depend on the host OS
The JRE is a superset of the JDK that adds debugging and packaging tools
The JDK contains the JRE and development tools such as javac, while the JRE contains the JVM and core runtime libraries
A class declares private double balance; and exposes public void deposit(double amount) that rejects negative amounts. Which Java feature does this design primarily demonstrate?
Platform independence
Encapsulation
Automatic garbage collection
Dynamic polymorphism
Which statement about Java's robustness and memory management features is TRUE?
Calling System.gc() forces the JVM to immediately reclaim all unreferenced objects before the next line executes
The size of a Java int depends on whether the host JVM is 32-bit or 64-bit
Java enforces compile-time static type checking, performs runtime array bounds checking, and prohibits raw pointer arithmetic
Because Java uses automatic garbage collection, it is impossible for an application to exhaust heap memory
Sections you finish are checked off in the contents.