Setting Up Your Java Development Environment¶
Before writing Java code, you need to install Java and set up your development tools. This guide will get you up and running quickly.
What You'll Install¶
- Java Development Kit (JDK) - The core Java tools
- Text Editor or IDE - Where you'll write your code
- Command Line Tools - To compile and run your programs
Step 1: Install Java Development Kit (JDK)¶
Check if Java is Already Installed¶
Open your terminal/command prompt and run:
If both commands show version 17 or higher, you can skip to Step 2.
Install JDK¶
Option 1: Using Homebrew (Recommended)¶
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Java
brew install openjdk@21
# Add to PATH
echo 'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Option 2: Download from Oracle¶
- Visit Oracle JDK Downloads
- Download JDK 21 for macOS
- Run the installer and follow the prompts
Option 1: Download from Oracle¶
- Visit Oracle JDK Downloads
- Download JDK 21 for Windows
- Run the installer
- Add Java to PATH:
- Open System Properties → Environment Variables
- Add Java installation path to PATH variable
Option 2: Using Package Manager¶
# Update package list
sudo apt update
# Install OpenJDK 21
sudo apt install openjdk-21-jdk
# Verify installation
java --version
javac --version
Verify Installation¶
After installation, verify everything works:
You should see version information for both commands.
Step 2: Choose a Text Editor or IDE¶
Option 1: VS Code (Recommended for Beginners)¶
- Download: code.visualstudio.com
- Install Java Extension Pack:
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "Extension Pack for Java"
- Install it
Option 2: IntelliJ IDEA Community Edition¶
- Download: jetbrains.com/idea/download
- Choose the free Community Edition
- Install with default settings
Option 3: Simple Text Editor¶
Any text editor works for learning:
- Notepad++ (Windows)
- TextEdit (macOS) - Make sure to use plain text mode
- Gedit (Linux)
- Sublime Text (All platforms)
Step 3: Create Your First Java Program¶
Let's verify everything is working by creating a simple program.
Create Project Directory¶
Create Your First Program¶
Create a file named HelloWorld.java
:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Java is working!");
}
}
Compile and Run¶
You should see:
Understanding the Development Workflow¶
The basic Java development cycle:
- Write - Create
.java
source files - Compile - Use
javac
to create.class
bytecode files - Run - Use
java
to execute the bytecode
Essential Command Line Commands¶
# Compile a single file
javac HelloWorld.java
# Compile multiple files
javac *.java
# Run a program
java HelloWorld
# Check Java version
java --version
# Check compiler version
javac --version
# See detailed compilation errors
javac -verbose HelloWorld.java
Project Organization¶
Organize your learning projects like this:
java-learning/
├── lesson1/
│ ├── HelloWorld.java
│ └── HelloWorld.class
├── lesson2/
│ ├── Variables.java
│ └── Variables.class
└── lesson3/
├── Calculator.java
└── Calculator.class
Common Setup Issues and Solutions¶
Issue: "javac is not recognized as a command"¶
Solution: Java isn't in your PATH. Add the JDK bin directory to your system PATH.
Issue: "Error: Could not find or load main class"¶
Solutions:
- Make sure the class name matches the filename exactly
- Make sure you're in the correct directory
- Check that the
.class
file was created during compilation
Issue: VS Code doesn't recognize Java¶
Solution:
- Install the Java Extension Pack
- Open a folder containing Java files
- VS Code should automatically detect Java projects
Editor Configuration Tips¶
VS Code Settings¶
Add to your VS Code settings.json:
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.saveActions.organizeImports": true,
"java.format.enabled": true
}
Basic VS Code Shortcuts¶
- Ctrl+Shift+P - Command palette
- F5 - Run program
- Ctrl+` - Open terminal
- Ctrl+Shift+` - New terminal
What's Next?¶
Great! You now have a working Java development environment. Time to learn the language itself.
Troubleshooting Resources¶
If you encounter issues:
- Oracle Installation Guide
- VS Code Java Documentation
- Stack Overflow Java Tag - For specific error messages