|

How to Install Java in VS Code on Windows (3 Methods, 2026)

How to Install Java in VS Code: Step-by-Step Installation Guide

The fastest way to set up Java in VS Code on Windows is the Coding Pack for Java from code.visualstudio.com/docs/languages/java. It installs VS Code, the JDK, and the Java Extension Pack in one step. If you already have VS Code, install the Extension Pack for Java from inside VS Code and a JDK separately. Either way, you write and run Java directly with the green play button next to main.

Applies to: Windows 10 (22H2) and Windows 11 (23H2, 24H2, 25H2) | Last updated: May 4, 2026

How to Install Java in VS Code: Step-by-Step Installation Guide

Key Takeaways

  • VS Code is not a Java IDE on its own — you need a JDK (Java Development Kit) and Microsoft’s Extension Pack for Java to compile and run Java code.
  • The Coding Pack for Java is the fastest setup — one installer downloads and configures VS Code, OpenJDK 21 LTS, and the Java Extension Pack together.
  • Java 21 is the current LTS in 2026 with support through 2031. Java 17 LTS is the previous one and still widely used in enterprise.
  • Extension Pack for Java bundles 6 extensions: Language Support, Debugger, Test Runner, Maven, Project Manager, and Gradle. You don’t need to install them individually.
  • The play button to run Java code only appears after the Java extension finishes indexing. If it does not show, restart VS Code — that fixes it almost every time.

Quick Steps

  1. Go to code.visualstudio.com/docs/languages/java and click Install the Coding Pack for Java – Windows.
  2. Run the installer and accept the license terms.
  3. Confirm the JDK and VS Code components are ticked, then click Install.
  4. Click Finish and let VS Code launch.
  5. Press Ctrl + Shift + P, type Java: Create Java Project, and pick No build tools.
  6. Pick a save location, name the project, and trust the folder when prompted.
  7. Open App.java and click the green play button above the main method.

In This Guide


Which Install Method Should You Use?

VS Code can run Java in three ways, each suited to a different starting point:

  • No VS Code, no JDK installed yet: use the Coding Pack for Java — it installs VS Code, the JDK, and the Extension Pack in a single wizard.
  • VS Code already installed, no Java set up: install the Extension Pack for Java from inside VS Code, then add a JDK.
  • You want a specific JDK vendor (Oracle, Adoptium Temurin, Amazon Corretto, Liberica, Microsoft): install that JDK manually and point VS Code’s java.jdt.ls.java.home setting at it.

Method 1 is the path I recommend for anyone starting Java on a fresh machine — students, people moving over from another language, anyone who wants the shortest distance to a running Java program. Methods 2 and 3 are for developers who already have an opinion about which JDK they want.

Method 1: Coding Pack for Java (Recommended)

Microsoft publishes the Coding Pack for Java, a single installer that sets up VS Code, OpenJDK 21 LTS, and the Java Extension Pack — all in one. Open any browser and visit code.visualstudio.com/docs/languages/java.

Java in VS Code official documentation page on the Visual Studio Code website.

Scroll down until you find the Install the Coding Pack for Java – Windows button. Click it to download JavaCodingPack.exe (about 600 MB).

VS Code Java documentation showing the Install the Coding Pack for Java - Windows download button.

Open the downloaded file. The Coding Pack wizard launches. Tick the box to accept the license terms and click Next.

Coding Pack for Java setup wizard welcome screen on Windows.

The Components screen lists what is about to be installed: the JDK, VS Code, and the Java Extension Pack. If VS Code is already on your machine, only the JDK and the extension are installed — the Coding Pack detects the existing VS Code install automatically. Click Install.

Coding Pack for Java components screen with JDK, VS Code, and Java Extension Pack ticked for install.

The installer takes a few minutes. When it finishes, leave Launch Visual Studio Code ticked and click Finish. VS Code opens with the Java extensions already installed and the OpenJDK on your PATH.

Coding Pack for Java setup completion screen with Launch Visual Studio Code option ticked.

Method 2: Extension Pack for Java in an Existing VS Code Install

If you already have VS Code installed (see my VS Code install guide if you don’t), you can add Java support without re-running the Coding Pack.

  1. Open VS Code.
  2. Click the Extensions icon in the activity bar (or press Ctrl + Shift + X).
  3. Search for Extension Pack for Java by Microsoft.
  4. Click Install.

The Extension Pack bundles six extensions: Language Support for Java, Debugger for Java, Test Runner for Java, Maven for Java, Project Manager for Java, and Gradle for Java. They install together and you do not need to manage them individually.

You still need a JDK on the system for any of this to actually run code — Method 3 covers that.

Method 3: Install the JDK Separately

If you want a specific JDK distribution — Oracle JDK, Adoptium Temurin, Amazon Corretto, Microsoft Build of OpenJDK, BellSoft Liberica — install it manually and point VS Code at it. The most common picks for new projects in 2026 are:

  • Adoptium Temurin 21 LTS — community-built OpenJDK, no licensing concerns. Download from adoptium.net.
  • Microsoft Build of OpenJDK — what the Coding Pack ships, free for any use. Download from learn.microsoft.com/java/openjdk.
  • Oracle JDK 21 — Oracle’s official build. Free for personal and most internal-business use under the NFTC license.

Run the JDK installer and let it set the JAVA_HOME environment variable. To verify the install, open a new PowerShell window and run:

java -version

You should see a line like openjdk version "21.0.5". If you get “command not found”, reboot once and try again — Windows sometimes needs a restart for new PATH entries to apply.

If you have multiple JDKs installed (common when you maintain projects on different LTS versions), tell VS Code which one to use by adding this to your settings.json:

"java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-21.0.5.11-hotspot"

Create and Run Your First Java Project

Once VS Code, the Extension Pack, and a JDK are all in place, write and run your first Java program from the command palette.

Press Ctrl + Shift + P to open the command palette, then type Java: Create Java Project and pick that command.

VS Code command palette showing Java commands after pressing Ctrl Shift P.

VS Code asks which build system to use. For a first project, pick No build tools — Maven and Gradle are great for real projects but add a learning curve. You can switch later by creating a new Maven or Gradle project alongside this one.

VS Code Java Create Project dialog with No build tools selected.

Pick a save folder (Desktop is fine for a quick test), enter a project name like test, and press Enter. VS Code generates a project scaffold with a src/App.java file containing a Hello World template.

VS Code prompts to trust the folder — tick Trust the authors of all files in the parent folder and click Yes. Workspace Trust is VS Code’s protection against running malicious code from cloned repositories — it is fine to trust your own folders.

VS Code Workspace Trust dialog asking whether to trust the authors of files in the project folder.

Open App.java in the file explorer. You should see a Run link above the main method, plus a green play button in the top-right of the editor. Click either one. The Java code compiles and the output appears in the Terminal panel.

VS Code editor with App.java open and the green Run button visible above the main method.

Note: The first time I ran this on a fresh install, the Run link did not appear immediately — the Java extension was still indexing in the background. A quick VS Code restart (close and reopen) fixed it. If you hit the same thing, restart before assuming anything is broken.

Troubleshooting Common Java + VS Code Issues

“Run” link or play button does not appear: The Java extension is still indexing. Wait 30 seconds, then close and reopen VS Code. This fixes the problem in nearly every case.

“Could not find or load main class App”: The class name in the file does not match the filename, or the file is not in a folder VS Code recognizes as a Java project. Make sure the public class declaration matches: a file named App.java must contain public class App.

“The JAVA_HOME environment variable is not defined correctly”: Open System Properties > Environment Variables, add a new system variable JAVA_HOME pointing to your JDK install (for example C:\Program Files\Microsoft\jdk-21.0.5.11-hotspot), and append %JAVA_HOME%\bin to PATH. Reboot, then run java -version in PowerShell to verify.

VS Code wants to install IntelliCode/Test Runner extras: These are optional and add code completion intelligence. Approve them — they all come from Microsoft and are widely trusted in the Java VS Code community.

Internet timeouts during install: The Coding Pack downloads about 600 MB of payload. On a slow or unreliable connection, the installer can fail partway through. Use a wired Ethernet connection if possible, and pause OneDrive sync, Windows Update, and any other big downloads while the Coding Pack runs.

JDK version mismatch in a workspace: If a project requires a specific JDK (for example, an older Java 8 project), open the command palette and run Java: Configure Java Runtime to map a specific JDK to the workspace.

Frequently Asked Questions

What is the Coding Pack for Java?

The Coding Pack for Java is a free Microsoft-maintained installer that bundles three things: VS Code, OpenJDK 21 LTS (Microsoft Build of OpenJDK), and the Java Extension Pack. It is designed for users new to Java who want a working environment in one click. After install, you can update the JDK or extensions independently — the Coding Pack is just a shortcut, not a long-term dependency.

Do I need to install the JDK separately if I use the Coding Pack?

No. The Coding Pack installs Microsoft’s Build of OpenJDK 21 LTS automatically and adds it to your PATH. You only need a separate JDK install if you want a specific vendor build (Oracle, Temurin, Corretto, Liberica) or an older LTS version like Java 17 or Java 11.

Can I use this guide for macOS or Linux?

The Coding Pack is Windows-only, but the Extension Pack for Java works identically on macOS and Linux. Install VS Code from code.visualstudio.com, install a JDK from your package manager (Homebrew on macOS, apt or dnf on Linux), then install the Extension Pack for Java from the Extensions tab in VS Code. The “Java: Create Java Project” command works the same way on every platform.

Why doesn’t VS Code recognize my Java code?

The most common cause is a missing Extension Pack for Java. Open the Extensions tab in VS Code (Ctrl + Shift + X) and search for Extension Pack for Java by Microsoft. If the pack is installed and code still is not recognized, restart VS Code, then check that java -version works in a new PowerShell window — if it doesn’t, your JDK is not on the system PATH.

How do I update the JDK in VS Code?

If you used the Coding Pack, re-run it any time — Microsoft updates it with the latest JDK builds regularly. If you installed a JDK separately, go to that vendor’s website (Adoptium, Microsoft, Oracle) and download the new installer. After installing, restart VS Code so it picks up the new PATH.

Should I use Java 21, Java 17, or Java 8?

For new projects in 2026, use Java 21 LTS — it is supported through 2031 and has all the modern language features (records, sealed classes, pattern matching, virtual threads). Java 17 LTS is still widely supported through 2029 and is what most enterprise projects target. Java 8 is end-of-life for free Oracle support and should only be used to maintain very old codebases. The Coding Pack ships Java 21.

Similar Posts