Welcome & Hello World

☕ Java Lesson 1 Beginner

Welcome to Java! Java is a robust, class-based, object-oriented programming language used by millions of developers globally. In this first lesson, we will understand how Java works, look at its compilation model, and write our first program.

1 Compiling vs. Interpreting (JVM, JRE, JDK)

Unlike languages that compile directly to raw machine code (like C++) or are directly interpreted line-by-line (like Python), Java utilizes a unique two-stage compilation and execution system:

  • JDK (Java Development Kit): The toolkit used by developers to write and compile programs. It contains the compiler (`javac`).
  • JRE (Java Runtime Environment): The environment required to run Java applications. It contains the JVM and core library classes.
  • JVM (Java Virtual Machine): The engine that executes compiled Java bytecode. The JVM translates bytecode into local computer instruction sets.

The Workflow: You write Java source code (`.java`), compile it using `javac` into Bytecode (`.class`), and run it inside the JVM on any system. This is what enables "Write Once, Run Anywhere" (WORA).

2 Your First Program: Main Method Signature

Let's analyze the classic "Hello, World!" program in Java. In Java, every line of executable code must exist inside a class definition:

Java — Hello World ▶ Run Code
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        System.out.print("Welcome to Our Compiler!");
    }
}

Let's break down the method signature word-by-word:

  • public: Visible to everyone. The JVM must access this method to run your application.
  • static: The JVM can call this method without instantiating an object of the class.
  • void: The method returns no value.
  • main: The keyword name that acts as the entry point of every Java program.
  • String[] args: An array of text strings passed as arguments to the program via command line execution.

Note: System.out.println() writes the text and moves the cursor to a new line, whereas System.out.print() keeps the cursor on the same line.

3 Code Challenge
Challenge: Modify the code in the editor above to output three lines. The first line should output your name, the second your favorite programming language, and the third a welcome greeting. Ensure you use a mix of `println()` and `print()` to understand formatting.