Syllabus / Java / Phase 1: Java Foundations (Days 1–5)
Beginner

Introduction to Java and Setting Up Your Environment

📂 Phase 1: Java Foundations (Days 1–5) · Java

Java is a class-based, object-oriented programming language designed to be platform-independent — code written once can run on any device with a Java Virtual Machine (JVM), following the principle "write once, run anywhere."

JDK, JRE, and JVM — The Three Pillars

ComponentFull FormPurpose
JVMJava Virtual MachineExecutes Java bytecode, converts it to machine code for the OS
JREJava Runtime EnvironmentJVM + libraries needed to run Java apps
JDKJava Development KitJRE + compiler and tools needed to build Java apps

How Java Code Executes

Source Code (.java)
      ↓  javac (compiler)
Bytecode (.class)
      ↓  JVM
Machine Code (runs on any OS)

This compile-once, run-anywhere model is what makes Java platform-independent — the same .class file runs unchanged on Windows, Linux, or macOS, as long as a JVM is installed.

Your First Java Program

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Breaking Down the Syntax

  • public class HelloWorld — declares a class; the filename must match the class name (HelloWorld.java)
  • public static void main(String[] args) — the entry point; every standalone Java program starts execution here
  • System.out.println(...) — prints text to the console followed by a new line

Compiling and Running

javac HelloWorld.java   // compiles to HelloWorld.class
java HelloWorld         // runs it (no .class extension needed)
Interview tip: A common question is "Why is main() static?" — Answer: so the JVM can call it directly without first creating an object of the class.