🧰 Prerequisites
Before writing and running your first Java program, make sure the following are set up:
1️⃣ Install Java Development Kit (JDK)
Download from: https://www.oracle.com/java/technologies/javase-downloads.html
(Or use OpenJDK: https://jdk.java.net/)
After installation, verify using:
You should see the version numbers. If not, the JDK isn't properly installed or configured in your system path.
2️⃣ Install VS Code
Download and install from: https://code.visualstudio.com/
3️⃣ Install Java Extension Pack in VS Code
Open VS Code → Extensions tab (
Ctrl + Shift + X) → Search for Java Extension Pack → Click InstallThis installs:
Language Support for Java™
Debugger for Java
Maven support
Java Test Runner
IntelliSense & more
🛠️ Steps to Write Your First Java Program
Open VS Code (or any code editor you prefer)
Create a new folder and open it in the editor
Create a new file named:
Hello.javaWrite 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 + F5On Mac: Press
Cmd + Fn + F5
📌 Option 3: Using Terminal
Open the terminal in VS Code (
Ctrl + ~)Compile the Java file:
javac Hello.javaRun the compiled program:
java Hello
Hello, Java World!