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! Answer from Equivalent_Cod_9705 on reddit.com
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › java
Java in Visual Studio Code
November 3, 2021 - Open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and type "java tips" to select the command. You can use VS Code to read, write, run, and debug Java source file(s) without creating a project.
🌐
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.
Discussions

compilation - How to compile and run Java code in Visual Studio Code - Stack Overflow
Read the documentation for VSCode and the Java pack? BTW,t he link you gave for the Java pack is invalid. ... 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. More on stackoverflow.com
🌐 stackoverflow.com
Debug/run standard java in Visual Studio Code IDE and OS X? - Stack Overflow
Right click anywhere on the java file and select run code. Check the output in the console. Done, hope this helps. ... Sign up to request clarification or add additional context in comments. ... As indicated by @Ashwin, it is possible to debug standalone files nowadays. Even better, VS Code automatically generates the .vscode... More on stackoverflow.com
🌐 stackoverflow.com
visual studio code - Running a java program in VScode - Stack Overflow
I start coding java with VScode recently. I have a simple problem. The problem is that I do not want the output to be like that. In other words, I do not want the program to run in the terminal as ... More on stackoverflow.com
🌐 stackoverflow.com
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
June 2, 2019
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-tutorial
Getting Started with Java in VS Code
November 3, 2021 - To learn more about editing Java, see 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. You can also use the Run|Debug CodeLens option in the editor.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-debugging
Running and debugging Java
November 3, 2021 - For details on how to get started with the extension pack, you can review the Getting Started with Java tutorial. By default, the debugger will run out-of-box by automatically finding the main class and generating a default launch configuration in memory to launch your application. If you would like to customize and persist your launch configuration, you can select the create a launch.json file link in the Run and Debug view. The launch.json file is located in a .vscode folder in your workspace (project root folder).
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-project
Managing Java Projects in VS Code
November 3, 2021 - As Java evolves, it's common that developers work with multiple versions of JDK. You can map them to your local installation paths via the setting: java.configuration.runtimes.
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-build
Java build tools in VS Code
November 3, 2021 - This document is an overview of how to work with your Java build tools in Visual Studio Code. It covers the Maven for Java and Gradle for Java extensions as well as other tools. If you run into any issues when using the features below, you can contact us by entering an issue.
🌐
Dev.java
dev.java › learn › vscode-java
Building a Java application in Visual Studio Code - Dev.java
April 22, 2024 - In the Run and Debug view you can customize your launch configurations by choosing Java+ from the dropdown list and then click the run icon. Default launch configurations are available in launch.json file. You can attach debugger actions by selecting either from available processes or enter the port to connect to the JVM running with JDWP.
🌐
Vaadin
vaadin.com › blog › vs-code-for-java-and-maven-projects
How to use Visual Studio Code with Java and Maven projects | Vaadin
March 28, 2025 - Download a starter project from start.vaadin.com (or use an existing project), extract it into a folder, and then use Open Folder in VS Code to open the project. VS Code automatically recognizes that it is a Maven-based Java project.
🌐
Loiane Groner
loiane.com › 2024 › 03 › visual-studio-code-for-java-the-complete-guide
Visual Studio Code for Java: The Complete Guide (Tips, Setup, and Extensions)
Then, provide the project name: ... open the App.java file. ... 1: When you open a class with a public static void main method, you will get a Run and Debug option so you can run your file....
🌐
Visual Studio Code
code.visualstudio.com › docs › getstarted › getting-started
Tutorial: Get started with Visual Studio Code
November 3, 2021 - This tutorial gives you an overview of the key features of Visual Studio Code to help you get started quickly.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-testing
Testing Java with Visual Studio Code
November 3, 2021 - You can also find the command in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) by searching for Java: Go to Test. There are other testing commands (for example, Run Tests in Current File) that can be found by searching for 'Test:' in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
🌐
Microsoft
devblogs.microsoft.com › dev blogs › microsoft for java developers › java on visual studio code update – january 2022
Java on Visual Studio Code Update – January 2022 - Microsoft for Java Developers
January 21, 2022 - We have also updated our getting started experience and Configure Java Runtime page (Ctrl+Shift+P: “Configure Java Runtime”) to reflect this change. For new users, just simply install the Extension Pack for Java, download the Java Development Kit for your project (Java 1.5 or above is supported), create a Java file, and happy coding!
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-webapp
Java Web Apps with Visual Studio Code
November 3, 2021 - Maven creates the project files in a new folder with a name of artifactId, which in this example is webapp-project. ... We just built a Java web application and ran it locally. Now you will learn how to deploy from Visual Studio Code and run it on Azure in the cloud.
🌐
Baeldung
baeldung.com › home › ide › how to use visual studio code with java?
How to Use Visual Studio Code With Java? | Baeldung
July 28, 2024 - Spring Boot, Quarkus, and MicroProfile ... any Java source file to show it again. To run the project, we just have to press F5 (debug) or Ctrl-F5 (run)....
🌐
Medium
medium.com › @amutheswaran › java-setup-on-vs-code-windows-4747964402b7
Java Setup on VS Code (Windows)
September 23, 2023 - This includes 6 different extensions and click here to know more on that. ... Click on Extension icon on the Activity bar. ... Click on first match which is from Microsoft. And click on install.
🌐
W3Schools
w3schools.com › java › java_getstarted.asp
Java Getting Started
To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe): ... java version "22.0.0" 2024-08-21 LTS Java(TM) SE Runtime Environment 22.9 (build 22.0.0+13-LTS) Java HotSpot(TM) 64-Bit Server VM 22.9 (build 22.0.0+13-LTS, mixed mode)
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-gui
Working with GUI applications in VS Code
November 3, 2021 - To run the JavaFX application, you can open the Maven Explorer, expand hellofx > Plugins > javafx and run the Maven goal: javafx:run.