Skip to lesson

Set up VS Code for Java

I'm on:

Showing steps for Windows. They are marked “On Windows” below.

Pick one IDE – you only need one. VS Code, IntelliJ IDEA and Eclipse are alternatives for this step: finish any one of them and the step is done. This guide sets up VS Code.

Install VS Code

An IDE (Integrated Development Environment) is an app where you write, run and fix code in one window. It shows mistakes as you type and runs your program with one click.

VS Code (Visual Studio Code) is a free code editor from Microsoft. With Microsoft's Java extensions it works like a full Java IDE. Install the JDK first (Install Java (opens in a new tab)), because VS Code needs it to run Java.

On Windows

Open the Download VS Code page using the button above.

  1. Click the big Windows button. It downloads the installer (.exe).
  2. Open your Downloads folder, double-click the .exe file and accept the agreement.
  3. On Select Additional Tasks, keep Add to PATH ticked. You can also tick the Open with Code options.
  4. Click Install, then Finish. VS Code opens.

Add the Java extension

An extension is a small add-on that gives VS Code new features. Microsoft's Extension Pack for Java adds Java support, error checking and the Run button.

On Windows

Do this once, inside VS Code.

  1. Open the Extensions view: press Ctrl + Shift + X.
  2. Search for Extension Pack for Java.
  3. Choose the one by Microsoft and click Install.
  4. Wait until the install finishes. Restart VS Code if it asks you to.

Create a project and run Hello World

A project is a folder that holds all the files of one program. Make one folder for all your Java projects, for example java inside Documents, and let VS Code make a simple project in it.

On Windows

Your project will be in a folder like C:\Users\<you>\Documents\java\HelloApp.

  1. Open the Command Palette: press Ctrl + Shift + P.
  2. Type Java: Create Java Project and press Enter. Choose No build tools.
  3. Choose your java folder, type the name HelloApp and press Enter.
  4. In the Explorer on the left, open src, then App.java.
  5. Click Run just above the main line, or press F5.
  6. By default, the output appears in the Terminal panel at the bottom. Show or hide it with Ctrl + `.
If you or a setting changed where Java programs run, the output may appear in the Debug Console tab instead. Both are fine.

Common problems and fixes

Most setup problems come from a missing JDK or an extension that is still loading. If there is no Run link above main, wait a minute and watch the status bar at the bottom. If nothing changes, run Developer: Reload Window from the Command Palette.

On Windows

Problems seen on Windows:

  • "JDK not found" or "Java runtime could not be located" – first check that java -version and javac -version work in a new Command Prompt. Then close VS Code fully and open it again. Only if it still fails: open Settings (Ctrl + ,), search java.jdt.ls.java.home and set it to your real JDK folder, for example C:\Program Files\Java\jdk-25.
  • 'code' is not recognized in Command Prompt – run the VS Code installer again with Add to PATH ticked, then open a new Command Prompt.
  • Extension not working – in the Extensions view, check that Extension Pack for Java by Microsoft is installed and enabled.

Example

App.javaJava
public class App {    public static void main(String[] args) throws Exception {        System.out.println("Hello, World!");    }}
Output
Hello, World!

What this code does

  • VS Code writes this code for you in src/App.java when you create the project.
  • The program starts in main and prints one line in the Terminal panel.
  • throws Exception is extra code that the project template adds. Your program does not need it, so ignore it for now; a later module explains it.

Next step

Practice what you learned

2 small exercises