Java > Visual Studio Code (VS Code) Installation
Introduction
VS Code is a popular code editor with extensive extensions and debugging tools.
Installation Steps
- Download from VS Code.
- Run the installer and follow the setup instructions.
- Open VS Code and install necessary extensions.
Setting Up Java in Visual Studio Code
1. Install Java Extension Pack
- Open VS Code.
- Click on the Extensions icon in the left sidebar or press
Ctrl+Shift+X. - Search for Java Extension Pack.
- Click Install to add the extension pack.
- Restart VS Code if needed.
2. Prerequisite Java Development Kit (JDK)
4. Create a Java Program
- Open VS Code.
- Click on File > Open Folder and select or create a new folder for your Java project.
- Click New File and name it
HelloWorld.java. - Add the following Java code:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } - Save the file (
Ctrl+S).
5. Run the Java Program
Using the VS Code Run Button:
- Click on the Run button (
▶symbol) at the top right corner. - Select Run Java File.
- The output should appear in the terminal:
Hello, World!
Using the Terminal:
- Open the terminal in VS Code (
Ctrl+). - Navigate to the folder containing
HelloWorld.java. - Compile the program:
javac HelloWorld.java - Run the compiled program:
java HelloWorld - You should see:
Hello, World!