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)
Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install OpenJDK 25 (or latest available):
brew install openjdk@25Link the JDK to the system path:
sudo ln -sfn $(brew --prefix openjdk@25)/libexec/openjdk.jdk \ /Library/Java/JavaVirtualMachines/openjdk-25.jdkVerify installation:
java -version # Expected output: # openjdk version "25" ... # OpenJDK Runtime Environment (build 25+...) # OpenJDK 64-Bit Server VM (build 25+...)
Option B: Manual Installation
- Download JDK 25 from Adoptium or Oracle
- Open the
.pkginstaller and follow prompts - 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)
Open PowerShell or Windows Terminal as Administrator:
winget install EclipseAdoptium.Temurin.25.JDKVerify installation:
java -version
Option B: Manual Installation
- Download JDK 25 from Adoptium or Oracle
- Run the
.msiinstaller - During installation, check "Set JAVA_HOME" and "Add to PATH"
- After installation, open a new terminal and verify:
java -version
Manually Setting JAVA_HOME (if needed):
- Search for "Environment Variables" in Start Menu
- Click "Environment Variables" button
- Under "System variables", click "New":
- Variable name:
JAVA_HOME - Variable value:
C:\Program Files\Eclipse Adoptium\jdk-25.0.0-hotspot
- Variable name:
- Edit
Pathvariable and add:%JAVA_HOME%\bin - Click OK and restart terminal
Step 2: Install VS Code Java Extensions
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Extension Pack for Java" by Microsoft
- 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
- Open VS Code
- Press
Cmd+Shift+P(macOS) orCtrl+Shift+P(Windows) - Type "Java: Configure Java Runtime" and select it
- 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:
- Download from maven.apache.org
- Extract to
C:\Program Files\Apache\maven(Windows) or/usr/local/maven(macOS) - Add
<maven-dir>/binto PATH
Gradle
macOS:
brew install gradle
gradle -version
Windows (using Chocolatey):
choco install gradle
gradle -version
Manual Installation:
- Download from gradle.org
- Extract to
C:\Gradle(Windows) or/usr/local/gradle(macOS) - Add
<gradle-dir>/binto PATH
Step 5: Create Your First Java Project
Using VS Code Java Extension
- Open VS Code
- Press
Cmd+Shift+P/Ctrl+Shift+P - Type "Java: Create Java Project"
- Select "Maven" or "Gradle"
- Choose project location
- Enter:
- Group ID:
com.example - Artifact ID:
hello-java25 - Version:
1.0.0
- Group ID:
- 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
- Open
App.java - Click the Run button above
main()method, or pressF5 - 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_HOMEpoints to JDK root (notbinfolder) - Restart terminal after changes
VS Code Doesn't Detect JDK
- Open Command Palette (
Cmd/Ctrl+Shift+P) - Run "Java: Clean Java Language Server Workspace"
- Reload VS Code
- 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 -versionorgradle -version
Class Not Found When Running
- Ensure
pom.xmlorbuild.gradlespecifies correct main class - Run
mvn clean installorgradle clean build - Check package declaration matches folder structure
Next Steps
Now that your environment is ready, you can:
- Explore Java 25 Features - Try preview features with
--enable-preview - Add Dependencies - Use Maven Central to find libraries
- Write Tests - Create unit tests in
src/test/java - Debug Code - Set breakpoints and use VS Code debugger
- 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.