As a first step, try to compile your programm from te command line. E.g. How do I run a Java program from the command line on Windows? is a good start. You can run the commands directly in VSCode's integrated terminal. Optionally, create a VS Code build task from that command to run builds with the build command.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Foo",
            "type": "shell",
            "command": "javac foo.java",
            "problemMatcher": []
        }
    ]
}

To run/debug, create a launch config in the debug viewlet, for example:

   // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)-Foo",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopOnEntry": false,
            "mainClass": "Foo",
            "args": ""
        },
        {
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 0
        }
    ]
}
Answer from Martin Aeschlimann on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-tutorial
Getting Started with Java in VS Code
November 3, 2021 - VS Code also provides IntelliSense ... Java Editing. To run and debug Java code, set a breakpoint, then either press F5 on your keyboard or use the Run > Start Debugging menu item....
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › java
Java in Visual Studio Code
November 3, 2021 - A Java Development Kit (JDK) is a software development environment used for developing Java applications. In order to run Java within Visual Studio Code, you need to install a JDK.
Discussions

How to run java in VSCODE
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
6
5
October 24, 2024
How can I get JAVA to run in VS code??
Did you follow the instructions step by step ?you need to download and install the Java SE Development Kit (JDK), configure your environment for Java development. and install J ava Extension Pack,you could refer to Java with VS Code More on reddit.com
🌐 r/vscode
6
0
July 17, 2019
Unable to run java project on vscode
If you have installed java SDK make sure that you have setup the proper PATH to it other wise it cna be problem. It PATH is set up than try installing a extension call code runner which is compatible for multiple code running More on reddit.com
🌐 r/vscode
5
1
December 22, 2021
How to run Java in VScode
One easy way to get started with any language is through VSCode Remote Containers, which will allow you to create in an isolated environment without needing to download Java yourself. See here for docs: https://code.visualstudio.com/docs/remote/containers As an example, I was able to go from no Java support at all on my machine to a running sample project with debugger and test support in just a minute, through the "Java Sample" container. I could theoretically go on to deploy the app to any cloud provider's Container service. The one caveat is that you need Docker on your computer. Let me know if this sounds like what you want and I can provide more info. More on reddit.com
🌐 r/vscode
6
1
January 2, 2020
People also ask

Do I need to install a JDK to run Java in VS Code?
Yes. VS Code has no built-in Java runtime. You need a JDK (not just a JRE) installed on your machine. The Extension Pack for Java supports JDK 1.8 and above. JDK 17 or JDK 21 are the recommended choices for new projects.
🌐
tms-outsource.com
tms-outsource.com › home › how to run java in vscode: a step-by-step guide
How to Run Java in VSCode: A Step-by-Step Guide
What extension do I need to run Java in VS Code?
Install the Extension Pack for Java, published by Microsoft. It bundles Language Support for Java (Red Hat), the Debugger for Java, Java Test Runner, Maven for Java, Gradle for Java, and Project Manager for Java.
🌐
tms-outsource.com
tms-outsource.com › home › how to run java in vscode: a step-by-step guide
How to Run Java in VSCode: A Step-by-Step Guide
How do I debug Java in VS Code?
Set a breakpoint by clicking the gutter next to a line number. Press F5 to start a debug session. VS Code auto-generates a launch.json configuration for most projects. Use the Variables panel and Debug Console to inspect runtime state.
🌐
tms-outsource.com
tms-outsource.com › home › how to run java in vscode: a step-by-step guide
How to Run Java in VSCode: A Step-by-Step Guide
🌐
Reddit
reddit.com › r/learnjava › how to run java in vscode
r/learnjava on Reddit: How to run java in VSCODE
October 24, 2024 -

Hi everyone,

I am a complete newbie to java and I'm getting overwhelmed with the barrier of entry to even start writing code. I have VSCode and have my java file, but I can't figure out how to run the code so I can see Hello World!

Here is the code:

public class HelloWorld {
    public static void main(String[] args) {
       // Prints "Hello, World" in the terminal window.
       System.out.println("Hello, World");
    }
 }

And here is the error message when I do java HelloWorld :

Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld

What do I do? I thought I downloaded all the right extensions and everything. Why can't I just write the code and click a button to run it?

Thank you
Top answer
1 of 4
4
That error message means you're either not running from the correct directory or the code isn't compiled. If you want a single button to handle this automatically, and you don't want to stress over installing everything needed to run Java in VS Code, just install the "Extension Pack for Java" from the extensions tab in VS Code. After it finishes installing, it will prompt you to install a version of the JDK (Java Development Kit). Simply choose the latest one (JDK 21). After that, the next task it will ask you to do is create a Java project using the command palette. You can access this by clicking at the top or pressing CTRL+Shift+P and typing: Java: Create Java Project. Then, choose "No build tools" and select the location where you want the code to be saved when prompted. It will set everything up for you and open the project. Once the project is open, go into the "src" folder and open App.java. This file should already contain the "Hello, World!" code. You can then press the "Run Java" button at the top right (it looks like a play button) to run the code. This button should both compile and run the code for you. If you're confused about why the project is structured this way or what "compiling code" means, I recommend taking some time to research Java and how it works before diving into the coding aspect. I hope this helps!
2 of 4
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-debugging
Running and debugging Java
November 3, 2021 - In addition to support for debugging Java projects managed by build tools, VS Code also supports for debugging single Java files without any project. The default Debug Console in VS Code doesn't support inputs. If your program needs inputs from a terminal, you can use the Integrated Terminal (⌃` (Windows, Linux Ctrl+`)) within VS Code or an external terminal to launch it.
🌐
Baeldung
baeldung.com › home › ide › how to use visual studio code with java?
How to Use Visual Studio Code With Java? | Baeldung
January 4, 2026 - If we need to open an existing ... any Java source file to show it again. To run the project, we just have to press F5 (debug) or Ctrl-F5 (run)....
Find elsewhere
🌐
GUVI
guvi.in › blog › java › how to run java in visual studio code?
How to Run Java in Visual Studio Code: Step-by-Step Guide
March 25, 2026 - Quick Answer: Running Java in Visual Studio Code requires installing a supported JDK, configuring VS Code with Java extensions, and selecting the correct Java runtime. After creating a project or folder and writing a program with a main method, ...
🌐
YouTube
youtube.com › watch
Java in VS Code Full Setup Tutorial (2026) | Install, Create & Run Java - YouTube
Learn how to install and run Java in Visual Studio Code step by step in this complete 2026 guide. This tutorial covers Java installation, VS Code setup, requ...
Published: April 15, 2026
🌐
TMS Outsource
tms-outsource.com › home › how to run java in vscode: a step-by-step guide
How to Run Java in VSCode: A Step-by-Step Guide
June 20, 2026 - This is the step most people skip and then spend 20 minutes wondering why the Java Language Server won’t start. Open the Command Palette (Ctrl+Shift+P) and run “Java: Configure Java Runtime”. A settings panel opens showing detected JDKs.
🌐
Dev.java
dev.java › learn › vscode-java
Building a Java application in Visual Studio Code - Dev.java
In addition to Visual Studio Code's explorer, the Oracle Java Platform extension offers Project Explorer that contains an overview of the project structure. This feature aims to simplify Java package structure navigation. You can use it to clean, compile, test, debug, and execute your Maven/Gradle Java projects. The Oracle Java Platform Extension launch configuration supports debugging and running Java applications using JDK11 or newer.
🌐
YouTube
youtube.com › watch
How to Setup Java in VS Code [Updated 2025] | Run Java in VS Code | Amit Thinks - YouTube
Learn how to setup and run Java on VS Code. We will also run an example Java file after the setup.Java Free Tutorial: https://studyopedia.com/tutorials/javaV
Published: January 7, 2025
🌐
YouTube
youtube.com › watch
How to Run Java Program in VS Code | Java Setup & Hello World Tutorial for Beginners - YouTube
Learn how to run Java programs in VS Code step by step. This Java in Visual Studio Code tutorial shows you how to write, compile, and execute your first Java...
Published: 1 week ago
🌐
C# Corner
c-sharpcorner.com › home › technologies › java › run java code in visual studio code
Run Java Code In Visual Studio Code
September 26, 2019 - Introduction of case L -> syntax that removes the need for break statements, because only the statements next to -> are executed. Switch can be an expression, so it can have a value or it can return a value. ... Firstly, we need JDK 12 installed in our system with the path variable or JAVA_HOME set. If you have successfully installed JDK 12, execute the following command ... The following result will you get in the command prompt. ... Download the Visual Studio Code as shown below.
🌐
Medium
amiryunas.medium.com › java-in-vscode-91b11c1b1c00
Java in VSCode. It’s important to understand how a… | by Amir Yunas | Medium
August 18, 2020 - If we now try to run Main.java in the terminal, we still get the same errors as before. What is missing? Long story short, because Java is a compiled language, we must compile our java source code into java byte code which is interpreted by the Java Virtual Machine (JVM).
🌐
Reddit
reddit.com › r/vscode › how can i get java to run in vs code??
r/vscode on Reddit: How can I get JAVA to run in VS code??
July 17, 2019 -

I have downloaded the MS java package.

I have created a new java file (java extension)

I am creating a simple hello world print

public class testing 3
{
        public static void main(String[] args)
        {
            System.out.println("hello world");
        }
}

I have tried Alt C, Alt R and F5 but I cannot see anything in the OUTPUT section of the terminal. I am probably missing something simple. There is a little JAVA symbol beside my file name so I know it is working in java. If there was an error in the code, I would have thought I could see that, but nothing.

🌐
javaspring
javaspring.net › blog › how-to-run-java-in-vscode
Running Java in Visual Studio Code: A Comprehensive Guide — javaspring.net
Set a breakpoint in your Java code by clicking in the gutter next to the line number where you want the program to pause. Start debugging by pressing F5, or click the "Debug" CodeLens link above your main method, or use the Run and Debug view in the Activity Bar.
🌐
YouTube
youtube.com › watch
How to Install & Run Java in Visual Studio Code [2025] Complete Guide | Java Extensions in VS Code - YouTube
This video is about - how to set up and run a Java program in visual studio code on Windows. In this video, I have shown a step-by-step complete guide for s...
Published: April 18, 2025
🌐
Medium
jodesignsat.medium.com › run-java-programs-in-visual-studio-code-bf886d22387e
Run Java programs in Visual Studio Code | by Jyothi Krishna | Medium
June 14, 2024 - Open VSCode app (restart the app if already open), search for “Extension Pack for Java” in extensions and click on install.
🌐
YouTube
youtube.com › watch
How to Run Java in VS Code - YouTube
This video explains how to run Java in VS Code (Visual Studio Code). In this tutorial we will install Java, and run a Java program. During the installation p...
Published: August 11, 2022
🌐
Medium
medium.com › @amutheswaran › java-setup-on-vs-code-windows-4747964402b7
Java Setup on VS Code (Windows)
September 23, 2023 - javac HelloWorld.java #to compile the program java HelloWorld #to execute the program ... If you prefer compile and running java program IDE style, click on Play button on right top or click on run option available above main method.