Phase 1 15 min windows macos linux

Install VS Code for Java

Your code editor with built-in Java support

What You’re Installing

VS Code (Visual Studio Code) is a free code editor by Microsoft. With the right extensions, it provides syntax highlighting, error detection, debugging, and Git integration for Java. It is not the same thing as Visual Studio (that’s a different product).

Download and Install

Get it from https://code.visualstudio.com/

Windows 1. Download the **User Installer** (64-bit) `.exe`. 2. Run the installer. 3. On the "Select Additional Tasks" screen, check: - **"Add to PATH"** (important) - "Add 'Open with Code' action to file context menu" (convenient, optional) 4. Finish the installer. After installing, you can open VS Code from the Start menu or by typing `code` in a terminal.
macOS 1. Download the `.zip` file. 2. Unzip it (double-click). 3. Drag **Visual Studio Code.app** into your **Applications** folder. 4. Open VS Code, then press `Cmd+Shift+P` and type `Shell Command: Install 'code' command in PATH`. Run it. Now you can open VS Code from the terminal with `code`.
Linux (Ubuntu/Debian) ```bash sudo apt update sudo apt install -y wget gpg wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" | sudo tee /etc/apt/sources.list.d/vscode.list sudo apt update sudo apt install -y code ``` Or download the `.deb` package from the VS Code website and install with `sudo dpkg -i .deb`. </details> ## Install the Java Extension Pack This is required. It gives VS Code the ability to understand Java code. 1. Open VS Code. 2. Click the **Extensions** icon in the left sidebar (or press `Ctrl+Shift+X` / `Cmd+Shift+X`). 3. Search for **"Extension Pack for Java"** by Microsoft. 4. Click **Install**. This single pack installs several extensions at once: - Language Support for Java (syntax, errors, autocomplete) - Debugger for Java - Test Runner for Java - Maven/Gradle for Java - Project Manager for Java Wait for all of them to finish installing. You'll see progress in the bottom-right corner. ## Verify JDK Detection 1. Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (macOS) to open the Command Palette. 2. Type `Java: Configure Java Runtime` and select it. 3. You should see **JDK 25 (Temurin)** listed and detected. If JDK 25 is not listed, VS Code can't find it. See troubleshooting below. ## Test It: Write and Run Hello.java 1. Open VS Code. 2. Go to **File > Open Folder** and open any empty folder (e.g., `~/Documents/java-test/`). 3. Create a new file called `Hello.java`. 4. Paste this code: ```java public class Hello { public static void main(String[] args) { System.out.println("VS Code + Java is working."); } } ``` 5. Click the **Run** button (triangle icon) above the `main` method, or right-click in the editor and choose **Run Java**. 6. You should see `VS Code + Java is working.` in the terminal panel at the bottom. If this works, your setup is correct. You can delete the test folder. ## Recommended Settings Open Settings (`Ctrl+,` / `Cmd+,`) and search for these: - **"Auto Save"** — set to `afterDelay`. Prevents losing unsaved work. - **"Format On Save"** — enable it. Keeps your code consistently formatted. - **"Terminal: Default Profile"** — on Windows, consider setting this to **Git Bash** or **PowerShell**. ## Common Errors **"JDK 25 not detected" in Java: Configure Java Runtime** VS Code looks for `JAVA_HOME` or searches common install paths. Fix: 1. Open Settings (`Ctrl+,`). 2. Search for `java.jdt.ls.java.home`. 3. Set it to the path of your JDK 25 installation. Examples: - Windows: `C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.1+12` - macOS: `/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home` - Linux: `/usr/lib/jvm/temurin-25-jdk-amd64` **"No Java runtime present, requesting install" (macOS)** This means macOS is using the system stub, not your installed JDK. Make sure `JAVA_HOME` is set correctly in your shell profile (`~/.zshrc` or `~/.bashrc`). Then restart VS Code. **Extension Pack not working / red squiggles everywhere** 1. Make sure all extensions in the pack finished installing (check the Extensions panel). 2. Try reloading: `Ctrl+Shift+P` > `Developer: Reload Window`. 3. Check the Java output log: `Ctrl+Shift+P` > `Java: Open Java Language Server Log`. **Run button doesn't appear above main()** The Java extension hasn't finished loading yet. Wait 10-15 seconds after opening a `.java` file for the first time. If it still doesn't appear, reload the window. ## Next Step VS Code is ready. Next, set up your [GitHub account](/setup/setup-github/) so you can receive and submit assignments.