Install VS Code for Java to enjoy a fast, lightweight, and customizable coding environment without the heavy load of traditional IDEs. With the right extensions, Visual Studio Code becomes a powerful Java development setup that’s perfect for beginners and professionals alike.

In this guide, we’ll cover:

  1. Installing VS Code
  2. Setting up Java and necessary extensions
  3. Creating and running your first Java program
  4. Tips for Java development in VS Code

1. Why Use VS Code for Java?

Visual Studio Code (VS Code) is a free, open-source code editor developed by Microsoft. While it’s not a full IDE like Eclipse or IntelliJ IDEA, it can be customized to act like one using extensions.

Advantages of VS Code for Java:

  • Lightweight & Fast – Loads quicker than full IDEs.
  • Customizable – Supports thousands of extensions.
  • Beginner-Friendly – Easy setup for learning Java.
  • Cross-Platform – Works on Windows, macOS, and Linux.

2. Installing VS Code

Step 1 – Download VS Code

  1. Visit the official site: https://code.visualstudio.com/
  2. Click Download for your operating system.
  3. Wait for the file to download.
Install VS Code

Step 2 – Install VS Code

  • Run the installer.
  • Accept the license agreement.
  • Keep the default location or choose your own.
  • Check Add to PATH and Create Desktop Icon options.
  • Click Install and finish the setup.

3. Install Java JDK

Before running Java programs in VS Code, you need to install the Java Development Kit (JDK).

  1. Go to Adoptium Temurin JDK or Oracle JDK Download.
  2. Download the latest LTS version ( Java 21).
Install VS Code
  1. Install it using the wizard.
  2. Verify Installation:
java -version

You should see something like:

java version "21.0.1"

4. Install VS Code Extensions for Java

  1. Open VS Code.
  2. Click the Extensions icon on the left sidebar (Ctrl+Shift+X).
  3. Search for Extension Pack for Java.
  4. Click Install.
Install VS Code

This will install:

  • Language Support for Java™ by Red Hat
  • Debugger for Java
  • Java Test Runner
  • Maven for Java
  • Java Dependency Viewer

5. Creating Your First Java Program in VS Code

Option 1 – Quick Java File

If you just want to try Java quickly:

  1. Create a folder named JavaPrograms.
  2. Open it in VS Code (File → Open Folder).
  3. Create a new file HelloWorld.java.
  4. Add:
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, VS Code!");
    }
}
  1. Save (Ctrl+S).
  2. Open the terminal (`Ctrl+“) and run:
javac HelloWorld.java
java HelloWorld

Option 2 – Java Project Using VS Code’s Built-in Tools

For a proper structure:

  1. Press Ctrl+Shift+P → type:
Java: Create Java Project
  1. Select No Build Tools (for beginners) or Maven/Gradle (for advanced users).
  2. Choose your project folder and name it (e.g., MyJavaProject).
  3. VS Code creates:
MyJavaProject
├── src
│   └── App.java
└── .vscode
  1. Open App.java and write:
public class App {
    public static void main(String[] args) {
        System.out.println("My first Java program in VS Code!");
    }
}
  1. Click Run ▶ at the top right or press Ctrl+F5.

6. Running Java in VS Code

You can run programs by:

  • Clicking Run ▶ above the main method.
  • Using the terminal:
javac FileName.java
java FileName
  • Using Run and Debug (left sidebar).

7. Tips for Java Development in VS Code

  • Enable IntelliSense: Auto-complete for faster coding.
  • Organize Classes: Use the Java Dependency Viewer.
  • Auto Save: Turn on in File → Auto Save.
  • Install Maven: For managing dependencies in big projects.

8. Troubleshooting

Issue: "java" not recognized
Fix: Ensure JDK is installed and PATH is set.

Issue: Run button missing
Fix: Install Extension Pack for Java and reload VS Code.


Conclusion

Now you know how to install VS Code for Java, set up extensions, and run your first program. This lightweight setup is great for both students and developers who want a flexible coding environment.

With just JDK + VS Code + Java Extension Pack, you can start coding Java in minutes. Give it a try and enjoy a faster, simpler development experience.


Resources


You May Also Like