Install a JDK, add the Extension Pack for Java, and open your project folder in VSCode. A small Run link then shows up above the main method. Click it and the program compiles and launches.
Most setup problems come from one thing people don’t expect. VSCode uses two separate JDKs. One is the tooling JDK, which starts the language server. The other is the project JDK, and that’s the one that compiles and runs your code.
Red Hat’s vscode-java documentation (2026) sets Java 25 as the minimum for the tooling JDK on the universal extension build. Platform-specific builds embed their own runtime. Your project JDK can be anything from Java 1.8 upward.
What do you need installed before running Java in VSCode?

Start with the JDK and VSCode itself. The extensions, the Run button and the debugger all depend on those two being in place.
Get the full JDK. A standalone runtime won’t do, because the javac compiler only ships with the JDK.
The VS Code Java docs list 8 JDK sources: Amazon Corretto, Azul Zulu, Eclipse Adoptium Temurin, IBM Semeru, Microsoft Build of OpenJDK, Oracle Java SE, Red Hat OpenJDK and SapMachine. Any of them works. If your course or team already uses one, go with that and skip the research.
On Windows or macOS there’s a faster route. The Coding Pack for Java bundles VSCode, a JDK and the Java extensions in one installer, and it is only available for Windows and macOS. Linux users install the pieces separately.
If VSCode is already on your machine and you just lack a JDK, open the Command Palette and run Java: Install New JDK. It handles the download for you.
Which JDK version does the setup need?
You’ll find two different minimums in the official sources, and they don’t actually contradict each other.
The VS Code docs (page dated 10/28/2026) say the Extension Pack for Java supports Java 1.8 or later. The vscode-java README is stricter about the language server. Its universal build needs Java 25 as the minimum to launch the language server, while the platform-specific builds for Windows, Linux and macOS on x64 and arm64 embed a JRE.
Once you split the tooling JDK from the project JDK, the numbers make sense. The README says projects can target code from Java 1.8 up to Java 27. So a Java 17 assignment still runs fine when the language server sits on a newer JDK.
My advice is to install JDK 25 and be done with it. It reached general availability on September 16, 2025, and Oracle lists it among the LTS releases (8, 11, 17, 21 and 25).
That one install meets the universal build’s minimum and covers most projects. If a project needs an older JDK, you map it separately, which comes up again in the Maven and Gradle section.
To check the install, open a system terminal (not the VSCode one yet) and run these two commands:
java -versionprints the runtime versionjavac -versionprints the compiler version
If javac comes back as not recognized, the JDK bin folder is missing from PATH.
Set JAVA_HOME to the JDK home folder. That’s the folder that contains bin, not bin itself (I’ve seen this mistake more times than I can count). Add the bin subfolder to PATH, then restart VSCode. With no JDK path configured, the universal build checks JDK_HOME first, then JAVA_HOME, then the system path.
For reference, here are the numbers from this section and where they come from:
- 1.8 or later: Java versions the Extension Pack for Java supports (VS Code docs, October 2026)
- 25: minimum Java version for the language server in the universal build (vscode-java README, November 2026)
- 8: JDK sources listed in the VS Code Java docs
- September 16, 2025: JDK 25 general availability (OpenJDK)
How to install the Extension Pack for Java

The Extension Pack for Java installs 6 extensions in one go:
- Language Support for Java by Red Hat, which provides code intelligence through the Eclipse JDT Language Server
- Debugger for Java, for breakpoints and the Run and Debug view
- Test Runner for Java (runs and debugs JUnit and TestNG tests)
- Maven for Java, which adds Maven project support and commands
- Project Manager for Java, behind project creation and the Java Projects view
- Visual Studio IntelliCode, for AI-assisted completions
You don’t strictly need all six. Running and debugging a single file only takes Language Support for Java by Red Hat and Debugger for Java.
I’d still install the whole pack. The first time a Maven project or a test file lands in your workspace, you’ll be glad you don’t have to stop and add more extensions.
Gradle for Java isn’t in the pack. VS Code’s docs list it as an optional extension.
Installing it is the same as any other VS Code extension. Press Ctrl+Shift+X to open the Extensions view, search for Extension Pack for Java, and click Install.
Now open a .java file inside a folder. The Java language server starts by itself, and a language status item appears in the Status Bar.
A few Command Palette commands are worth knowing early on. Java: Create Java Project is the one you’ll use most. Java: Tips for Beginners and Java: Extensions Guide are more of a one-time read.
If none of them show up after installing, run Developer: Reload Window from the same palette.
How to run a Java file with the Run button

You need a folder, a class with a main method, and the Run link above it. Output prints in the integrated terminal by default.
- Create a folder for the program and open it with File, then Open Folder.
- Create a file named
Hello.java. - Paste the class shown below.
- Wait for the language status item to show in the Status Bar.
- Click Run above
main, or press F5. - Read the output in the Terminal panel.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from VSCode");
}
}A public class has to match its file name, so Hello lives in Hello.java.
The CodeLens links (Run | Debug above main()) are what most people click. The editor title bar also has Run Java and Debug Java menu items if you prefer those. From the keyboard, F5 finds the project’s entry point automatically, and Ctrl+F5 runs it without the debugger attached.
You don’t have to compile anything by hand first. The setting java.debug.settings.forceBuildBeforeLaunch defaults to true, so the workspace is built before every launch.
One thing that trips up beginners: open the folder, not just the file. Without the folder, the Java Language Server might not work properly.
James Madison University’s CS159 setup page says the same thing. Students there open the course folder itself rather than an enclosing one, so the .vscode settings folder sits first in the tree.
You also don’t need a formal project for small stuff. Lightweight mode suits single files, and standard mode is for full projects. VSCode lets you switch when the code outgrows one file.
How to run Java from the terminal with javac and java
From the folder that holds the source file, compile with javac and launch with java.
Compile and run in two steps
Ctrl+` (backtick) opens the integrated terminal. There are several other ways to open the terminal in VSCode as well.
javac Hello.java
java Hellojavac writes Hello.class next to the source file. Note that java takes the class name, not the file name, so you leave the extension off.
Classes in packages work a little differently. They compile into an output folder and run by their fully qualified name.
javac -d out src/com/example/Hello.java
java -cp out com.example.HelloThe -d flag sets the output folder, and -cp puts that folder on the classpath. Running java Hello from the wrong directory is a common cause of “Could not find or load main class”.
Run a source file in one step
JEP 330, delivered in JDK 11, lets the java launcher compile a single source file in memory and run its first top-level class.
java Hello.javaAnything after the file name passes straight to main as arguments.
On JDK 11 through 21, no other source files are found or compiled, so a program split across two files needs javac or a project. JEP 458, delivered in JDK 22, removed that limit. The launcher now also compiles, in memory, the other source files whose classes the program references. On JDK 25 a small multi-file program runs the same way.
So which one should you use? The two-step javac then java route writes real .class files, compiles several files together and handles packages. java Hello.java compiles in memory and leaves no .class files behind. It’s the quickest option for a throwaway test, with the caveat that it only handled one file before JDK 22.
If the terminal run works and the Run button fails, the editor is probably using a different JDK than your shell. The troubleshooting section covers how to compare the two.
Which way of running Java in VSCode fits your project?
Stick with the Run button until something pushes you off it. The other methods are each useful in one particular situation.
| Method | Needs | Output goes to | Best for |
|---|---|---|---|
| Run button | Extension Pack for Java | Integrated terminal | Daily runs, learning |
| F5 debug | Extension Pack for Java | Integrated terminal | Breakpoints, stepping |
| javac, then java | JDK only | Terminal | Checking a clean build |
| java Hello.java | JDK only | Terminal | Quick experiments |
| Code Runner | Extra extension, executor map | Output Window by default | One-click scratch runs |
When you’re writing or learning a single class, the Run button is plenty. If a value prints wrong, press F5 and step through it. And when the editor says everything is fine but you don’t quite believe it, go to the terminal. That takes the editor’s project model out of the picture completely.
What about Code Runner?
Code Runner is the extension most tutorials reach for, and its Marketplace page shows 42,493,277 installs. For Java, its documented setup is a shell command that changes into the file’s directory, runs javac on the file, then runs java on the class. The page presents that as an example rather than a built-in default.
That command knows nothing about Maven, Gradle or mapped runtimes. Results land in the Output Window unless code-runner.runInTerminal is turned on, and that option is off by default.
The appeal is real, though. One shortcut (Ctrl+Alt+N) runs a file in any language it supports, and you don’t need any Java project setup.
The downsides add up for Java specifically. Output goes to a read-only window unless you change a setting, which means a Scanner prompt can’t receive input. The executor must be on PATH or set in code-runner.executorMap. And Java support depends on a configuration you write yourself.
If you already have the Extension Pack, Code Runner just gives you a second way to do what the Run button already does. I’d skip it unless you jump between several languages in one folder.
How to run a Maven or Gradle project in VSCode
Open the folder that holds pom.xml or build.gradle and let the extension import the project. From there, the main class runs just like a single file.
Both are build automation tools that resolve dependencies and compile the project, and VSCode drives them through extensions.
For Maven, Maven for Java scans the workspace for pom.xml files and lists projects and modules in the Maven Explorer. Right-click a project to run a goal, or right-click a goal to debug it. Maven: History in the Command Palette reruns earlier goals, which is handy when you keep running the same clean install.
Gradle needs Gradle for Java added first. Its Gradle Build Server imports projects and passes build tasks to the Gradle daemon, so output should match running Gradle from the command line. Tasks show up in the Gradle Projects view, where you can run or debug them. Android projects aren’t supported, so those still need Android Studio.
A note on sources. VS Code’s build-tool page carries a 12/10/2021 date and names no extension, Maven or Gradle versions. Treat its menu labels as a guide, not a script.
After you edit dependencies, a ClassNotFoundException usually means the library is missing from pom.xml or build.gradle. Declare it, run Update project configuration, then run Java: Force Java compilation.
Choosing which JDK runs the project
In a Maven or Gradle project, change the JDK in pom.xml or build.gradle. In a plain folder, VSCode uses the runtime marked as default in java.configuration.runtimes.
"java.configuration.runtimes": [
{ "name": "JavaSE-17", "path": "/path/to/jdk-17" },
{ "name": "JavaSE-25", "path": "/path/to/jdk-25", "default": true }
]Each entry takes a name and a path, plus optional default, sources and javadoc keys. Java: Configure Java Runtime shows which JDK each project is using.
How to pass arguments and read console input with launch.json
A Java launch.json only strictly requires mainClass. Arguments, working directory and console choice are all optional.
The file lives in the .vscode folder at the workspace root, and the Run and Debug view links to a template. If you don’t create one, the debugger generates a default configuration in memory.
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Hello with arguments",
"request": "launch",
"mainClass": "Hello",
"args": "alpha beta"
}
]
}The keys you’ll reach for most:
argsholds program arguments, passed tomainvmArgsis for JVM options such as heap sizecwdsets the working directory (the workspace folder by default)envandenvFilesupply environment variables for the runclassPathsadds extra classpath entries
Getting keyboard input to reach your program
This is controlled by the console key. The default-ish option, internalConsole, sends output to the Debug Console, and the Debug Console does not accept input. Use integratedTerminal if you want typing to reach your program in the terminal panel, or externalTerminal for a separate window configured in user settings.
Leave the key out and the global java.debug.settings.console setting decides. The quickest route is to open settings.json in VSCode and set it there for every project.
You’ll know you picked wrong when a Scanner program just sits there waiting. Typing into the Debug Console produces “Failed to evaluate. Reason: Cannot evaluate because the thread is resumed”, because that console only accepts evaluation expressions. Switching console to externalTerminal or integratedTerminal fixes it.
How to debug with breakpoints
Click the gutter next to a line number, then press F5.
Execution stops on that line, and the Run and Debug view shows your variables and threads. The debugger also supports Hot Code Replace and conditional breakpoints.
Launch and debug sessions share the same toolbar controls:
- Pause
- Step over
- Step into
- Step out
- Restart
- Stop
Hot Code Replace has limits. When the JVM can’t apply a change at runtime, you get “Failed to complete hot code replace”. Restart the application, or set java.debug.settings.hotCodeReplace to never if you’d rather switch the feature off.
Why does Java not run in VSCode?
Usually it’s the JDK. Sometimes the language server never started, or the build can’t find your main class. The table covers the errors you’re most likely to see.
| Error | Cause | Fix |
|---|---|---|
| javac is not recognized | JDK bin folder missing from PATH | Add it to PATH, restart VSCode |
| Java runtime could not be located | JAVA_HOME points to a missing folder | Point JAVA_HOME at a valid JDK, then update the project configuration and clean the language server workspace |
| Could not find or load main class | Wrong mainClass value, or the file is not on the classpath | Check mainClass, add the folder to the Java source path, run Java: Force Java compilation |
| Build failed, do you want to continue? | Compilation errors in the workspace | Fix the PROBLEMS view, then search the language server log for build/building workspace |
| UnsupportedClassVersionError | Classes compiled for a newer Java version than the runtime JDK supports | Rebuild after updating Language Support for Java, or install an older JDK and force a full compilation |
The Run button is missing
That means the language server isn’t running. Open the folder instead of a lone file, then watch the Status Bar for the language status item.
In the same situation the debugger reports “Cannot find a class with the main method”, when mainClass is unset and no class with a main method turns up. Create the class, or fix the server first.
The language server won’t start on an older JDK
Set java.jdt.ls.java.home to a newer JDK for the server. Keep the older JDK mapped under java.configuration.runtimes for the project itself.
You’re behind a proxy
When the language server can’t download runtimes or dependencies, set java.jdt.ls.vmargs with your proxy host, port and credentials through the -Dhttp.proxyHost and -Dhttps.proxyHost flags.
Things worked yesterday and don’t today
After you modify a project that is already open, run Java: Clean Java Language Server Workspace and reload. VS Code’s FAQ says you may need to force a clean.
Try the clean before reinstalling anything. It costs you a reload, not a download.
FAQ About Running Java in VSCode
Is VSCode enough for Java, or do I need IntelliJ IDEA or Eclipse?
For running, debugging, Maven, Gradle and JUnit tests, it’s enough. The Extension Pack for Java covers all of that, with Gradle for Java added for Gradle projects. Maven for Java scans the workspace for pom.xml files, so a project built in IntelliJ IDEA opens without conversion. This comparison of VSCode against IntelliJ shows where the two differ.
Where does VSCode put compiled class files?
For a project with no build tool, they go into a folder inside the workspace. You can change that location with the java.project.outputPath setting. It applies only in workspace scope and does not affect Maven or Gradle projects, which write to their own build folders.
How do I stop a running Java program in VSCode?
Click Stop in the debug toolbar, or press Shift+F5. When the program runs in the integrated terminal, Ctrl+C also ends it.
Restart sits next to Stop if you only want a fresh run.
Can VSCode run JUnit tests with the same Java setup?
It can. Test Runner for Java ships in the pack and supports JUnit 4 (4.8.0 or later), JUnit 5 (5.1.0 or later) and TestNG (6.9.13.3 or later), on a JDK 1.8 or later. Beyond declaring the test library, there’s no extra project configuration.
Does the setup differ on Windows, macOS and Linux?
Barely. The extensions, settings and Run button behave the same everywhere.
The differences are outside the editor. On Windows, JAVA_HOME and PATH live in system environment variables, while macOS and Linux keep them in a shell profile. Classpath entries use a semicolon on Windows and a colon elsewhere.
Can VSCode run a Java 25 file with no class declaration?
With a JDK 25 or newer, yes. JEP 512 (compact source files and instance main methods) was delivered in Java 25, and the –enable-preview flag is no longer required at compile or run time.
For a file that holds only a void main method, running java Hello.java from the terminal is the dependable route.
What to Add Once Java Runs in VSCode
A single file and the Run button will carry you until a second source file or an outside library shows up. After that, a Maven or Gradle project is the better base.
Keep single files on the Run button while they stay single. Move to a build-tool project as soon as you add an extra file or a dependency, and leave JUnit tests for after that.
The order matters because a test library has to be declared as a dependency, and pom.xml or build.gradle is where it lives. You do pay for it with a build file to maintain and an import step before the first run. Worth it, in my opinion, once the project is more than a toy.
This advice reflects the tooling as verified on November 20, 2026. Oracle plans Java 29 as the next LTS release for September 2027, and the tooling JDK minimum in the vscode-java README deserves a fresh look at that point.
Once you have tests, unit testing is the natural next topic to study.
- How to Choose a Digital Transformation Consulting Partner - November 30, 2026
- Is Notepad++ Safe? Official Download, Updates, CVEs - November 29, 2026
- How to Evaluate an AI Code Reviewer on Your Own Pull Requests - November 29, 2026



