Set up VS Code for Java
20 min · Beginner
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 (previous lesson), because VS Code needs it to run Java.
Official downloads
On Windows
Open the Download VS Code page using the button above.
- Click the big Windows button. It downloads the installer (
.exe). - Open your Downloads folder, double-click the
.exefile and accept the agreement. - On Select Additional Tasks, keep Add to PATH ticked. You can also tick the Open with Code options.
- 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.
Official downloads
On Windows
Do this once, inside VS Code.
- Open the Extensions view: press Ctrl + Shift + X.
- Search for Extension Pack for Java.
- Choose the one by Microsoft and click Install.
- 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. First make one folder for all your Java projects, for example a java folder inside Documents. Then let VS Code make a simple Java project in it.
On Windows
Your project will be in a folder like C:\Users\<you>\Documents\java\HelloApp.
- Open the Command Palette: press Ctrl + Shift + P.
- Type Java: Create Java Project and press Enter. Choose No build tools.
- Choose your
javafolder, type the nameHelloAppand press Enter. - In the Explorer on the left, open
src, thenApp.java. - Click Run just above the
mainline, or press F5. - By default, the output appears in the Terminal panel at the bottom. Show or hide it with Ctrl + `.
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 -versionandjavac -versionwork in a new Command Prompt. Then close VS Code fully and open it again. Only if it still fails: open Settings (Ctrl + ,), searchjava.jdt.ls.java.homeand set it to your real JDK folder, for exampleC:\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
public class App { public static void main(String[] args) throws Exception { System.out.println("Hello, World!"); }}Hello, World!
What this code does
- VS Code writes this code for you in
src/App.javawhen you create the project. - The program starts in
mainand prints one line in the Terminal panel. throws Exceptionis 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
Check your understanding
6 quick questions