🛠️ Lesson 2: Setup & Your First Java Program
⏱️ Estimated time: 20 minutes | Difficulty: Beginner
Getting Started
To develop in Java, you need the Java Development Kit (JDK) and an IDE like IntelliJ IDEA or VS Code.
Step 1: Install Java JDK
- Download JDK 21 (LTS) from
adoptium.netororacle.com - Install with default settings
- Verify:
java --versionandjavac --version
Step 2: Choose an IDE
- IntelliJ IDEA (Community) — Best for Java
- VS Code + Java Extension Pack — Lightweight
- Eclipse — Classic Java IDE
Your First Java Program
// File: HelloWorld.java
// Class name MUST match filename!
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Welcome to Java! ☕");
}
}
Compile & Run
$ javac HelloWorld.java # Compile → creates HelloWorld.class
$ java HelloWorld # Run the bytecode
Hello, World!
Welcome to Java! ☕
Breaking Down the Code
public class HelloWorld— Every Java program needs a classpublic static void main(String[] args)— Entry point, always this signatureSystem.out.println()— Print to console with newlineSystem.out.print()— Print without newline- Every statement ends with
;
Getting User Input
import java.util.Scanner;
public class UserInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("What's your name? ");
String name = scanner.nextLine();
System.out.println("Hello, " + name + "!");
scanner.close();
}
}