Module 1.2

Java Development Environment Setup

Set up your complete Java development environment with JDK installation, IDE configuration, and write your very first Java program. Everything you need to start coding in Java!

35 min read
Beginner
Installation Guide
What You'll Learn
  • Install JDK 17+ (LTS version)
  • Configure JAVA_HOME and PATH
  • Set up IntelliJ IDEA or VS Code
  • Write your first Java program
  • Understand compile and run process
Contents
01

Why Environment Setup Matters

Before writing any Java code, you need a properly configured development environment. Unlike interpreted languages like Python, Java requires compilation. Your source code (.java files) must be compiled into bytecode (.class files) before the Java Virtual Machine (JVM) can execute it.

Good News: Setting up Java is straightforward! We'll install the JDK (Java Development Kit), configure environment variables, and set up an IDE. Takes about 20 minutes.
JDK (Java Development Kit)

Contains compiler (javac), JRE, and development tools

Environment Variables

JAVA_HOME and PATH to access Java from anywhere

IDE (Integrated Development Environment)

IntelliJ IDEA, VS Code, or Eclipse for efficient coding

Command Line Tools

javac (compiler) and java (runtime) commands

02

What We'll Install

Here's everything you need for professional Java development:

JDK 17+ (LTS)

The Java Development Kit includes everything needed to develop and run Java applications. We recommend JDK 17 or 21 (Long Term Support versions).

Includes: javac (compiler), java (runtime), JRE, development tools

IDE (Choose One)

A powerful code editor designed for Java development with features like auto-completion, debugging, and project management.

Options: IntelliJ IDEA (recommended), VS Code, Eclipse

JDK vs JRE: JDK (Java Development Kit) is for developers and includes the compiler. JRE (Java Runtime Environment) is just for running Java programs. As developers, we need the JDK!
03

Installing the JDK

We'll install Oracle JDK or OpenJDK. Both work great - OpenJDK is free and open-source, Oracle JDK requires a license for commercial use. For learning, either is fine!

Windows Installation

1
Download JDK

Visit adoptium.net (Eclipse Temurin - recommended) or oracle.com/java and download JDK 17 or 21 for Windows.

2
Run the Installer

Double-click the downloaded .msi or .exe file and follow the wizard.

Important: Note the installation path (usually C:\Program Files\Java\jdk-17). You'll need it!
3
Set JAVA_HOME Environment Variable

Open System Properties (search "Environment Variables" in Start Menu):

  1. Click "Environment Variables" button
  2. Under "System variables", click "New"
  3. Variable name: JAVA_HOME
  4. Variable value: C:\Program Files\Java\jdk-17 (your JDK path)
  5. Click OK
4
Add to PATH

Still in Environment Variables:

  1. Find "Path" under "System variables" and click "Edit"
  2. Click "New" and add: %JAVA_HOME%\bin
  3. Click OK on all dialogs
5
Verify Installation

Open a new Command Prompt (important - must be new!) and run:

java --version
javac --version

You should see version 17.x.x or 21.x.x

macOS Installation

1
Install via Homebrew (Recommended)

If you have Homebrew installed, this is the easiest way:

brew install openjdk@17

Then create the symlink:

sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
2
Alternative: Download Installer

Download from adoptium.net and run the .pkg installer.

3
Set JAVA_HOME (if needed)

Add to your ~/.zshrc or ~/.bash_profile:

export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export PATH=$JAVA_HOME/bin:$PATH

Then reload:

source ~/.zshrc
4
Verify Installation
java --version
javac --version

Linux Installation

1
Install via Package Manager

Ubuntu/Debian:

sudo apt update
sudo apt install openjdk-17-jdk

Fedora:

sudo dnf install java-17-openjdk-devel

Arch Linux:

sudo pacman -S jdk17-openjdk
2
Set JAVA_HOME

Add to ~/.bashrc or ~/.zshrc:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export PATH=$JAVA_HOME/bin:$PATH
3
Verify Installation
java --version
javac --version
echo $JAVA_HOME
04

Setting Up Your IDE

While you can write Java in any text editor, an IDE (Integrated Development Environment) makes you significantly more productive with features like auto-completion, error highlighting, debugging, and refactoring.

IntelliJ IDEA (Recommended)

IntelliJ IDEA is the most popular Java IDE, known for its intelligent code assistance and ergonomic design.

1
Download IntelliJ IDEA

Visit jetbrains.com/idea and download the Community Edition (free and sufficient for learning).

2
Install and Launch

Run the installer and follow the setup wizard. On first launch, choose your preferred theme (Darcula recommended).

3
Create Your First Project
  1. Click "New Project"
  2. Select "Java" from the left panel
  3. Choose your installed JDK from the dropdown (or click "Download JDK")
  4. Click "Next", then "Next" again (skip templates)
  5. Name your project (e.g., "HelloJava") and click "Create"

VS Code (Lightweight Alternative)

VS Code is a lightweight, fast editor that works great for Java with the right extensions.

1
Download VS Code

Visit code.visualstudio.com and download for your OS.

2
Install Java Extension Pack

Open VS Code, go to Extensions (Ctrl+Shift+X), and search for "Extension Pack for Java" by Microsoft. Install it.

This pack includes: Language Support for Java, Debugger for Java, Maven for Java, and more.

3
Configure Java Runtime

Press Ctrl+Shift+P, type "Java: Configure Java Runtime" and verify your JDK is detected.

Eclipse (Classic Option)

Eclipse is a veteran IDE with a massive plugin ecosystem, popular in enterprise environments.

1
Download Eclipse

Visit eclipse.org/downloads and download "Eclipse IDE for Java Developers".

2
Install and Configure

Extract and run. On first launch, choose a workspace folder for your projects.

Our Recommendation: Start with IntelliJ IDEA Community Edition. It has the best Java support and will make learning easier with its intelligent suggestions.
05

Your First Java Program

Let's write the classic "Hello, World!" program to verify everything works. We'll do it both ways - using the command line and using an IDE.

Method 1: Command Line

1
Create the Source File

Create a file named HelloWorld.java (the filename MUST match the class name):

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        System.out.println("Welcome to Java programming!");
    }
}
2
Compile the Program

Open terminal/command prompt in the same folder and run:

javac HelloWorld.java

This creates HelloWorld.class (bytecode)

3
Run the Program
java HelloWorld

Note: Don't include .class extension when running!

4
Expected Output
Hello, World!
Welcome to Java programming!

Method 2: Using IntelliJ IDEA

1
Create a New Class

Right-click on src folder → New → Java Class → Name it "HelloWorld"

2
Write the Code

IntelliJ creates the class skeleton. Add the main method:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        
        // Let's try some variables too
        String name = "Java Developer";
        int year = 2026;
        
        System.out.println("Welcome, " + name + "!");
        System.out.println("Current year: " + year);
    }
}

Tip: Type psvm and press Tab for the main method shortcut!

3
Run the Program

Click the green play button next to the main method, or press Shift+F10

Understanding the Code

public class HelloWorld - Declares a public class named HelloWorld (must match filename)

public static void main(String[] args) - The entry point of every Java application

System.out.println() - Prints text to the console with a newline

06

Common Issues & Solutions

Running into problems? Here are the most common issues and how to fix them:

"java" or "javac" is not recognized

Solution: The JDK is not in your PATH. Double-check:

  • JAVA_HOME points to your JDK folder (not JRE, not bin folder)
  • PATH includes %JAVA_HOME%\bin (Windows) or $JAVA_HOME/bin (Mac/Linux)
  • Open a new terminal after changing environment variables
# Verify JAVA_HOME is set correctly
echo %JAVA_HOME%   # Windows
echo $JAVA_HOME    # Mac/Linux
"Error: Could not find or load main class"

Solution: This usually means:

  • You're not in the correct directory (must be where the .class file is)
  • The class name doesn't match the filename exactly (case-sensitive!)
  • You included .class extension when running (don't do that)
# Correct way to run
java HelloWorld     # Good
java HelloWorld.class  # Wrong - don't include .class
"class, interface, or enum expected" compiler error

Solution: Check your code structure:

  • Make sure all code is inside a class
  • Check for missing or extra braces { }
  • Verify all statements end with semicolons ;
IntelliJ says "Project SDK is not defined"

Solution:

  1. Go to File → Project Structure → Project
  2. Click the "SDK" dropdown and select your JDK
  3. If not listed, click "Add SDK" → "JDK" and browse to your JDK installation
VS Code doesn't recognize Java

Solution:

  1. Make sure "Extension Pack for Java" is installed
  2. Press Ctrl+Shift+P → "Java: Configure Java Runtime"
  3. Verify JDK is detected, or manually add the path
  4. Restart VS Code

Key Takeaways

JDK is Essential

Install JDK 17 or 21 (LTS versions). JDK includes the compiler (javac), runtime (java), and development tools

Configure JAVA_HOME

Set JAVA_HOME environment variable and add the bin folder to PATH for command-line access

Use a Good IDE

IntelliJ IDEA Community Edition is free and provides the best Java development experience

Filename Must Match Class

The Java filename must exactly match the public class name (case-sensitive): HelloWorld.java for class HelloWorld

Compile Then Run

Java is compiled: first use javac to create .class bytecode, then use java to execute it

main() is the Entry Point

Every Java application needs a main method: public static void main(String[] args) - execution starts here

Knowledge Check

Test your understanding of Java environment setup:

Question 1 of 6

What does JDK stand for, and what does it include?

Question 2 of 6

Why do we set the JAVA_HOME environment variable?

Question 3 of 6

Which command compiles a Java source file?

Question 4 of 6

What is the correct signature for the main method in Java?

Question 5 of 6

If your class is named "Calculator", what must the source file be named?

Question 6 of 6

After compiling HelloWorld.java, how do you run the program?

Answer all questions to check your score