Module 1: Getting Started with Java & Computing
1.1 How Programming Works & The JVM Architecture
Estimated reading & practice time: ~20 minutes
Learning Objectives
• Explain the difference between source code, bytecode, and native machine code.
• Describe the specific roles of JDK, JRE, and JVM.
• Understand how memory and execution flow in a Java runtime.
Mental Model & Analogy
Think of Java like an international orchestra. The composer writes sheet music in standard notation (Java source code .java). A musical transcriber converts it into a universal performance score (.class bytecode). Then, any conductor (the JVM installed on Windows, Mac, or Linux) translates that universal score into the exact physical hand movements for the local orchestra (native CPU machine code).
Core Concept Breakdown
Computers only understand binary electrical pulses (0s and 1s) known as machine language. Because different CPUs (Intel x86, Apple ARM, AMD) speak different native machine dialects, traditional languages like C required compiling separate binaries for each operating system.
Java revolutionized this by introducing the Java Virtual Machine (JVM). When you compile Java code using the `javac` compiler, it generates architecture-neutral **Bytecode** stored in `.class` files. When you run the application, the JVM interprets and Just-In-Time (JIT) compiles this bytecode directly into CPU instructions on your target operating system.
Key trio to remember:
1. **JDK (Java Development Kit)**: Contains the compiler (`javac`), debugger, and development tools.
2. **JRE (Java Runtime Environment)**: Contains the libraries required to run Java applications.
3. **JVM (Java Virtual Machine)**: The execution engine executing the bytecode.
Architecture Diagram
Code Example
JAVA Example
// Every Java application starts with a class declaration
public class ArchitectureDemo {
public static void main(String[] args) {
// Output system properties provided by the JVM
System.out.println("Java Version: " + System.getProperty("java.version"));
System.out.println("Operating System: " + System.getProperty("os.name"));
System.out.println("JVM Architecture: " + System.getProperty("os.arch"));
}
}Line-by-Line Walkthrough
• Line 2: `public class ArchitectureDemo` creates an accessible class container. The file must match this name (`ArchitectureDemo.java`).
• Line 3: `public static void main(String[] args)` is the JVM entry point.
• Line 5-7: `System.getProperty()` asks the JVM host for runtime information.
Java Version: 21.0.2 Operating System: Windows 11 JVM Architecture: amd64
Common Pitfalls & Debugging
• Forgetting that Java is strictly case-sensitive: `system.out.println` or `String[] Args` will cause compilation errors.
• Naming the file differently from the public class name.
Try It Yourself — Java Sandbox
Live ExecutionTask: Open your terminal or an online Java playground and write a class named `MyFirstCheck` that prints your name and your primary learning goal for this course on two separate lines.
Solution.java
Edit the code and click Run Code to verify output directly inside TBLearn.
1
Terminal Output
Click "Run Code" or press Ctrl+Enter to execute.