SLIDE 1 / 5

1. The Motto: Write Once, Run Anywhere

In traditional compiled languages like C, the compiler produces machine code tied to a specific processor. In Java, source code compiles to Bytecode (.class): a universal instruction set that any Java Virtual Machine (JVM) can execute on any operating system.

Hola.java Source Code javac Hola.class 0xCAFEBABE aload_0 invokespecial Universal Bytecode JVM Windows (x86) Intel / AMD instructions JVM macOS (ARM64) Apple Silicon M-Series JVM Linux Server ELF binaries & cloud kernel A single .class file runs unmodified across every OS through its local JVM.
Bytecode Inspector Select target platform
JVM Windows (x86_64)
// Bytecode (.class) es IDÉNTICO:
0: getstatic #2 // System.out
3: ldc #3       // "Hola Mundo"
5: invokevirtual #4 // println

// Instrucciones emitidas por la JVM nativa:
mov eax, [rcx+0x10]
lea rdx, [rel str_hola]
call qword ptr [rax+0x28]

The javac compiler never talks to the target chip: the local native JVM translates bytecode at runtime.

2. JVM Internal Architecture

The Java Virtual Machine is split into three foundational subsystems: ClassLoader, Runtime Data Areas, and Execution Engine.

ClassLoader 1. Loading (.class) 2. Linking / Verifier 3. Initialization Verifies bytecode security Runtime Memory Method Area (Clases) HEAP Live objects JVM Stacks Threads & frames PC Registers Execution Engine Interpreter Line by line JIT Compiler HotSpot native compiler to C++ speed Garbage Collector Reclaims dead memory
Subsystem Deep Dive Click a module

ClassLoader Subsystem

Locates and loads .class files into memory. The Bytecode Verifier inspects the binary structure to ensure no illegal pointers, forbidden memory access, or stack overflows occur before running.

✓ Java Security Sandbox Guarantee

3. Anatomy of public static void main(String[] args)

Every single keyword in the entry method signature has a precise technical purpose in the Java architecture.

public Visible to the JVM launcher from outside any package.
static Executable directly by the JVM without allocating an instance first.
void Returns nothing to the caller. Errors exit via exceptions or system exit codes.
main Canonical entry point identifier sought by the JVM launcher.
String[] args String array containing command-line arguments supplied at startup.
CLI Arguments Simulator Test passing parameters
$ java MiApp
args array memory layout:
args[0] = "servidor.cfg"
args[1] = "8080"
args[2] = "--debug"
args.length = 3

4. Standard I/O Streams and Scanner

The System class wires Java to standard OS file descriptors: standard in, out, and err. Scanner wraps raw byte streams into typed tokens.

Terminal "42 Juan\n" Teclado / Consola System.in Scanner nextInt() → 42 next() → "Juan" System.out Display println() Screen Output
Scanner Tokenizer Demo Token consumption
Buffer: 19 3.1415 true
Invoked method: scanner.nextDouble()
Assigned Java variable: double pi = 3.1415;

5. Stack vs Heap: First Look at Memory

Every variable in Java lives on either the Stack or the Heap. At this entry level, local primitive variables inside main reside directly inside the Stack Frame: instant access and automatic cleanup upon exit.

Call Stack (Hilos) Frame: main() int edad = 25 double saldo = 1500.0 boolean activo = true HEAP (Montón Global) No objects instantiated yet (Reserved for "new" and Objects in lessons 07+)

Key Takeaways

  • Write Once, Run Anywhere: javac generates .class bytecode; each OS native JVM executes it.
  • Arquitectura JVM: ClassLoader verifies security; JIT compiles hotspots to native CPU speed.
  • Firma de main(): public for JVM visibility, static to run without instantiation, void because it returns nothing.
  • Memoria Stack: Local primitive variables live directly within the stack frame.