JAVA - Zero to Hero / Getting Started with JAVA

Write Your First Java Program

🧰 Prerequisites

Before writing and running your first Java program, make sure the following are set up:

1️⃣ Install Java Development Kit (JDK)


2️⃣ Install VS Code


3️⃣ Install Java Extension Pack in VS Code

  • Open VS Code → Extensions tab (Ctrl + Shift + X) → Search for Java Extension Pack → Click Install

  • This installs:

    • Language Support for Java™

    • Debugger for Java

    • Maven support

    • Java Test Runner

    • IntelliSense & more


🛠️ Steps to Write Your First Java Program

  1. Open VS Code (or any code editor you prefer)

  2. Create a new folder and open it in the editor

  3. Create a new file named:

    Hello.java
  4. Write the following code:

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

▶️ How to Run the Program (in VS Code)

📌 Option 1: Using the Run Button

  • Click the Run button at the top-right of VS Code (usually appears after installing the Java extensions)

  • OR right-click anywhere inside the file → Click "Run Java"

📌 Option 2: Using Shortcut Keys

  • On Windows: Press Ctrl + F5

  • On Mac: Press Cmd + Fn + F5

📌 Option 3: Using Terminal

  1. Open the terminal in VS Code (Ctrl + ~)

  2. Compile the Java file:

    javac Hello.java
  3. Run the compiled program:

    java Hello

Hello, Java World!