1.1 Dev Environment Setup

This guide walks through setting up a modern Java development environment on macOS and Windows using VS Code as the primary editor. By the end, you'll have:

  • JDK 25 installed and configured
  • VS Code with Java extensions
  • Maven or Gradle for build management
  • A working "Hello World" project

Prerequisites

  • macOS: macOS 12+ (Monterey or later)
  • Windows: Windows 10/11 with PowerShell or Windows Terminal
  • VS Code: Download from code.visualstudio.com
  • Internet connection for downloading JDK and dependencies

Step 1: Install JDK 25

macOS

Option A: Using Homebrew (Recommended)

  1. Install Homebrew if you haven't already:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install OpenJDK 25 (or latest available):

    brew install openjdk@25
    
  3. Link the JDK to the system path:

    sudo ln -sfn $(brew --prefix openjdk@25)/libexec/openjdk.jdk \
    /Library/Java/JavaVirtualMachines/openjdk-25.jdk
    
  4. Verify installation:

    java -version
    # Expected output:
    # openjdk version "25" ...
    # OpenJDK Runtime Environment (build 25+...)
    # OpenJDK 64-Bit Server VM (build 25+...)
    

Option B: Manual Installation

  1. Download JDK 25 from Adoptium or Oracle
  2. Open the .pkg installer and follow prompts
  3. Set JAVA_HOME:
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home
    echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home' >> ~/.zshrc
    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.zshrc
    source ~/.zshrc
    

Windows

Option A: Using WinGet (Windows 11)

  1. Open PowerShell or Windows Terminal as Administrator:

    winget install EclipseAdoptium.Temurin.25.JDK
    
  2. Verify installation:

    java -version
    

Option B: Manual Installation

  1. Download JDK 25 from Adoptium or Oracle
  2. Run the .msi installer
  3. During installation, check "Set JAVA_HOME" and "Add to PATH"
  4. After installation, open a new terminal and verify:
    java -version
    

Manually Setting JAVA_HOME (if needed):

  1. Search for "Environment Variables" in Start Menu
  2. Click "Environment Variables" button
  3. Under "System variables", click "New":
    • Variable name: JAVA_HOME
    • Variable value: C:\Program Files\Eclipse Adoptium\jdk-25.0.0-hotspot
  4. Edit Path variable and add: %JAVA_HOME%\bin
  5. Click OK and restart terminal

Step 2: Install VS Code Java Extensions

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  3. Search for "Extension Pack for Java" by Microsoft
  4. Click Install

This pack includes:

  • Language Support for Java (Red Hat)
  • Debugger for Java (Microsoft)
  • Test Runner for Java (Microsoft)
  • Maven for Java (Microsoft)
  • Project Manager for Java (Microsoft)
  • IntelliCode (Microsoft)

Optional but Recommended:

  • Gradle for Java (Microsoft) - if using Gradle
  • Spring Boot Extension Pack - if building Spring apps
  • Lombok Annotations Support - if using Lombok

  • Restart VS Code after installation


Step 3: Verify Java Extension Setup

  1. Open VS Code
  2. Press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows)
  3. Type "Java: Configure Java Runtime" and select it
  4. Verify that JDK 25 is detected and selected

If JDK 25 doesn't appear:

  • Click "+" to manually add the JDK path
  • macOS: /Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home
  • Windows: C:\Program Files\Eclipse Adoptium\jdk-25.0.0-hotspot

Step 4: Install Build Tool (Maven or Gradle)

Maven

macOS:

brew install maven
mvn -version

Windows (using Chocolatey):

choco install maven
mvn -version

Manual Installation:

  1. Download from maven.apache.org
  2. Extract to C:\Program Files\Apache\maven (Windows) or /usr/local/maven (macOS)
  3. Add <maven-dir>/bin to PATH

Gradle

macOS:

brew install gradle
gradle -version

Windows (using Chocolatey):

choco install gradle
gradle -version

Manual Installation:

  1. Download from gradle.org
  2. Extract to C:\Gradle (Windows) or /usr/local/gradle (macOS)
  3. Add <gradle-dir>/bin to PATH

Step 5: Create Your First Java Project

Using VS Code Java Extension

  1. Open VS Code
  2. Press Cmd+Shift+P / Ctrl+Shift+P
  3. Type "Java: Create Java Project"
  4. Select "Maven" or "Gradle"
  5. Choose project location
  6. Enter:
    • Group ID: com.example
    • Artifact ID: hello-java25
    • Version: 1.0.0
  7. Select JDK version: 25

Project Structure (Maven)

hello-java25/
├── pom.xml
└── src/
    ├── main/
    │   └── java/
    │       └── com/example/
    │           └── App.java
    └── test/
        └── java/
            └── com/example/
                └── AppTest.java

Edit pom.xml

Ensure Java 25 is configured:

<properties>
    <maven.compiler.source>25</maven.compiler.source>
    <maven.compiler.target>25</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Write App.java

package com.example;

import java.util.List;

public class App {

    // Record for type-safe data (Java 16+)
    record Developer(String name, int experience) {}

    public static void main(String[] args) {
        System.out.println("Hello, Java 25!");

        // Text blocks for multi-line strings (Java 15+)
        String json = """
            {
                "language": "Java",
                "version": 25,
                "released": true
            }
            """;
        System.out.println(json);

        // Pattern matching with records (Java 21+)
        var developer = new Developer("Alice", 8);
        if (developer instanceof Developer(String name, int exp) && exp > 5) {
            System.out.println("Senior developer: " + name);
        }

        // Modern collections (Java 9+)
        List<String> features = List.of(
            "Virtual Threads",
            "Pattern Matching",
            "Records",
            "Text Blocks"
        );

        features.forEach(feature -> 
            System.out.println("✓ " + feature)
        );
    }
}

This example demonstrates several Java 25-finalized features:

  • Records for immutable data classes
  • Text blocks for readable multi-line strings
  • Pattern matching with record destructuring
  • Lambdas and method references for functional programming
  • Modern collections with List.of()

Run it to see Java 25 in action!


Step 6: Build and Run

Using VS Code

  1. Open App.java
  2. Click the Run button above main() method, or press F5
  3. Output appears in Terminal:
    Hello, Java 25!
    {
     "name": "Java Developer",
     "version": 25,
     "modern": true
    }
    

Using Terminal (Maven)

cd hello-java25
mvn clean compile
mvn exec:java -Dexec.mainClass="com.example.App"

Using Terminal (Gradle)

cd hello-java25
gradle build
gradle run

Step 7: Configure VS Code Settings

Create .vscode/settings.json in your project:

{
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-25",
      "path": "/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home",
      "default": true
    }
  ],
  "java.compile.nullAnalysis.mode": "automatic",
  "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": true
  }
}

Windows path example:

"path": "C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.0-hotspot"

Step 8: Essential VS Code Shortcuts

Action macOS Windows
Run/Debug F5 F5
Run without debugging Ctrl+F5 Ctrl+F5
Command Palette Cmd+Shift+P Ctrl+Shift+P
Go to Definition F12 F12
Find References Shift+F12 Shift+F12
Rename Symbol F2 F2
Format Document Shift+Option+F Shift+Alt+F
Quick Fix Cmd+. Ctrl+.
Toggle Terminal Ctrl+ ` Ctrl+ `

Troubleshooting

"JAVA_HOME not set" Error

macOS:

echo $JAVA_HOME
# If empty:
export JAVA_HOME=$(/usr/libexec/java_home -v 25)
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 25)' >> ~/.zshrc

Windows:

  • Check Environment Variables (System Properties)
  • Ensure JAVA_HOME points to JDK root (not bin folder)
  • Restart terminal after changes

VS Code Doesn't Detect JDK

  1. Open Command Palette (Cmd/Ctrl+Shift+P)
  2. Run "Java: Clean Java Language Server Workspace"
  3. Reload VS Code
  4. Manually add JDK path in "Java: Configure Java Runtime"

Maven/Gradle Command Not Found

  • Ensure build tool is in PATH
  • Restart terminal after installation
  • Verify with mvn -version or gradle -version

Class Not Found When Running

  • Ensure pom.xml or build.gradle specifies correct main class
  • Run mvn clean install or gradle clean build
  • Check package declaration matches folder structure

Next Steps

Now that your environment is ready, you can:

  1. Explore Java 25 Features - Try preview features with --enable-preview
  2. Add Dependencies - Use Maven Central to find libraries
  3. Write Tests - Create unit tests in src/test/java
  4. Debug Code - Set breakpoints and use VS Code debugger
  5. Profile Performance - Use JFR (Java Flight Recorder) for production-like analysis

The next chapter covers JDK 25's new features and how to leverage them in real projects.