GK SOLUTIONS
AI • IoT • Arduino • Projects & Tutorials
DEFEAT THE FEAR

🛠️ 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

  1. Download JDK 21 (LTS) from adoptium.net or oracle.com
  2. Install with default settings
  3. Verify: java --version and javac --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 class
  • public static void main(String[] args) — Entry point, always this signature
  • System.out.println() — Print to console with newline
  • System.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();
    }
}

✅ Quick Quiz

❓ What command compiles a Java file?

❓ Must the class name match the filename?

❓ What does System.out.println() do?

← Previous Next: Variables & Data Types →