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