What VS Code provides
Visual Studio Code is an editor. Java support comes from a JDK and extensions; VS Code alone is not a Java compiler or runtime. Microsoft’s Extension Pack for Java bundles language, debugging, testing and project-management support. Start with that pack rather than stacking several overlapping Java extensions.
The Coding Pack for Java combines VS Code, a JDK and essential extensions on Windows and macOS. On Linux, install those parts separately. If you already have a suitable JDK and VS Code, adding the Extension Pack may be enough.
Install and check the JDK
Download VS Code from its official site and use the Extensions view to install Extension Pack for Java. Install a maintained JDK separately unless you chose Microsoft’s Coding Pack. In a terminal, run java -version and javac -version to verify the tools.
Open the folder containing your .java files through File > Open Folder. Trust only projects you understand. If VS Code reports an unavailable JDK, check the Java configuration or select the installed JDK using the Java: Configure Java Runtime command.
Integrated terminal — verify tools
java -version
javac -versionCreate and run Main.java
Create Main.java in the open folder and enter the class-based example. Wait for Java language support to finish loading. Use the Run action above main or the integrated terminal commands below. Output from the editor’s run action appears in the terminal or run view; terminal commands print in that terminal.
If an editor offers a newer compact source-file template, you can still create a regular Java class for this walkthrough. The public class must be called Main because the file is Main.java.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codectionary!");
}
}Terminal — explicit workflow
javac Main.java
java MainPause with a breakpoint
Click the gutter beside System.out.println to set a breakpoint, then choose Debug above main or use the Run and Debug view. Execution pauses before the line. Inspect variables and the call stack, then step or continue. A breakpoint is useful when a program produces an unexpected value; it lets you inspect the state at the point of interest rather than guessing.
This tiny example has no changing local value to inspect. Add a local variable such as String message = "Hello, Codectionary!"; and print message to see the variable in the debugger.
Common setup problems and next steps
If Run is missing, confirm you opened the folder, saved a .java file, installed the Extension Pack and selected a JDK. If the terminal and Java extension use different releases, configure the project runtime deliberately. Read Problems and terminal errors for the first failed line. VS Code can also open Maven or Gradle projects, but neither build tool is needed for this single-file tutorial.
After the greeting works, change the message, add a variable and then move on to Java classes and collections. Keep the local JDK available even if you sometimes use the Codectionary Playground.
Syntax
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codectionary!");
}
}Examples
A file VS Code can run and debug
Set a breakpoint on println and compare the editor action with terminal commands.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codectionary!");
}
}- The class and Main.java filename correspond.
- The main method is where this program begins.
- println writes the greeting. A breakpoint pauses before that statement executes.
Best practices
- Install the Extension Pack for Java and a supported JDK.
- Open the project folder so Java tooling can discover the file.
- Use the debugger and first diagnostic message before changing configuration blindly.
Runtime & versions
Java Virtual Machine. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Java Language Specification