1.2 Anatomy of Hello World & Java Syntax
Module 1: Getting Started with Java & Computing

1.2 Anatomy of Hello World & Java Syntax

Estimated reading & practice time: ~25 minutes

Learning Objectives

• Explain every keyword in 'public static void main(String[] args)'. • Use comments and clean indentation properly. • Understand compiler errors vs runtime errors.

Mental Model & Analogy

Consider a locked bank vault with security clearance. 'public' means anyone with the address can knock on the outer door; 'static' means the door exists immediately without having to build a new building first; 'void' means the door doesn't hand you an item back when opening; and 'main' is the specific master key slot the guard checks.

Core Concept Breakdown

Java enforces explicit, strongly-typed structure. Unlike scripting languages that allow top-level statements, Java requires every instruction to reside inside a method, which in turn must reside inside a class. Let's break down the entry point signature: 1. `public`: Access modifier signaling this method is callable from anywhere, including outside the package by the JVM launcher. 2. `static`: Indicates the method belongs to the class itself, not to a specific instantiated instance. The JVM can call it before creating objects. 3. `void`: Return type indicating this function produces no output value. 4. `main`: The exact identifier mandated by the Java specification. 5. `String[] args`: An array of text arguments passed from the command line.

Architecture Diagram

public static void main (String[] args) Accessible to JVM No object needed No return value Entry point CLI inputs

Code Example

JAVA Example
public class Main {
    public static void main(String[] args) {
        /* Print line outputs text and appends a line break.
           Print outputs text without a line break. */
        System.out.println("Hello, TBLearn Learner!");
        System.out.print("Welcome to Java 21");
        System.out.println(" - Let's build real projects.");
    }
}

Line-by-Line Walkthrough

• `System.out.println()` outputs text and automatically inserts a newline character at the end. • `System.out.print()` outputs text without moving the cursor to the next line.
Expected Console Output
Hello, TBLearn Learner!
Welcome to Java 21 - Let's build real projects.

Common Pitfalls & Debugging

• Omitting the semicolon `;` at the end of a statement. • Writing `Main` with a capital 'M' instead of `main`. • Placing statements outside of any method body.

Try It Yourself — Java Sandbox

Live Execution

Task: Modify the code to print a receipt layout: Header with '=== TBLEARN CAFE ===', Item 'Filter Coffee - ₹30', and Footer 'Thank you for visiting!'.

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.
Knowledge Checkpoint • Earn +40 Credits

Test Yourself Before Moving Forward

Short, practical questions tied directly to this section. Passing awards Credits toward course discounts and interview packs.

Checkpoint: Hello World & Java Compilation

Verify you understand javac compilation, JVM bytecode execution, and public class naming rules.