Programming and Java Fundamentals

Setting Up the Java Development Environment

ReadingPreview

You are viewing a free preview lesson.

Lesson Overview

To write, compile, and run Java code, you need a working development environment on your computer.

In this course, we will use:

  • Azul Zulu JDK 21
  • IntelliJ IDEA

In this lesson, you will install Azul Zulu JDK 21, verify the installation, and configure IntelliJ IDEA to use Java 21.

We will cover:

  • Installing Azul Zulu JDK 21
  • Verifying the java and javac commands
  • Understanding PATH and JAVA_HOME
  • Installing IntelliJ IDEA
  • Configuring a JDK in IntelliJ IDEA
  • Running a Java program from the terminal and IDE
  • Troubleshooting common setup problems

Learning Objectives

After completing this lesson, you will be able to:

  • Install Azul Zulu JDK 21
  • Verify a Java installation from the terminal
  • Understand the roles of PATH and JAVA_HOME
  • Configure Java 21 in IntelliJ IDEA
  • Compile and run a Java program from the terminal
  • Run a Java program from IntelliJ IDEA
  • Identify common setup problems

What Do You Need?

To start Java development, you need two main tools:

  1. Azul Zulu JDK 21
  2. IntelliJ IDEA

Conceptually, the setup looks like this:

Computer
├── Azul Zulu JDK 21
│   ├── Java Compiler
│   ├── Java Runtime
│   └── Development Tools
│
└── IntelliJ IDEA
    ├── Code Editor
    ├── Project Management
    ├── Run / Debug Support
    └── Test Support

We will use Java 21 for the code and exercises in this course.

Installing Azul Zulu JDK 21

When downloading the JDK, make sure you select:

  • Distribution: Azul Zulu
  • Java version: 21
  • Package: JDK
  • Correct operating system
  • Correct CPU architecture

CPU Architecture

When downloading a JDK, you will commonly see architectures such as:

  • x64
  • ARM64 / AArch64

In general:

  • Intel or AMD 64-bit processor → x64
  • Apple Silicon Mac → ARM64

On macOS or Linux, you can check your architecture using:

uname -m

The output may be:

x86_64

or:

arm64

or:

aarch64

Download the Azul Zulu JDK 21 package that matches your machine's architecture.

Installing Azul Zulu JDK 21 on Windows

From Azul's official download source, select:

  • Java version: 21
  • Package: JDK
  • Operating system: Windows
  • Architecture: x64 or ARM64

Download the installer and complete the installation.

If the installer provides an option to add Java to PATH, you can leave that option enabled.

After installation, open a new PowerShell or Windows Terminal window.

Run:

java -version

Then:

javac -version

Both commands should show Java version 21.

Installing Azul Zulu JDK 21 on macOS

First, check your architecture:

uname -m

On an Apple Silicon Mac, the output will usually be:

arm64

On an Intel Mac, it will usually be:

x86_64

Then, when downloading Azul Zulu, select:

  • Java version: 21
  • Package: JDK
  • Operating system: macOS
  • The correct architecture for your processor

After installation, you can view installed JDKs using:

/usr/libexec/java_home -V

Then verify the installation:

java -version
javac -version

Installing Azul Zulu JDK 21 on Linux

When selecting the Linux package for Azul Zulu JDK 21, make sure you choose:

  • Java version: 21
  • Package: JDK
  • Operating system: Linux
  • Correct CPU architecture

The package format and installation method may differ depending on your Linux distribution.

After installation, verify it with:

java -version
javac -version

Both commands should report Java 21.

Verify the Installation

After installing the JDK, first run:

java -version

Then:

javac -version

The java command shows whether the Java runtime is available.

The javac command shows whether the Java compiler is available.

The major version of both should be:

21

Conceptually, your setup should look like:

java  → Java 21
javac → Java 21

If the two commands show different Java versions, you may have multiple JDKs installed or your environment configuration may not be correct.

What Is PATH?

PATH is an environment variable.

When you type:

java

in the terminal, the operating system needs to know where the java executable is located.

JDK executable files are usually located inside the bin directory:

Zulu JDK 21
└── bin
    ├── java
    ├── javac
    └── ...

If the JDK is installed but you still see:

java: command not found

or on Windows:

'java' is not recognized

you should check whether your PATH configuration is correct.

What Is JAVA_HOME?

JAVA_HOME is an environment variable that usually points to the JDK installation directory.

Conceptually:

JAVA_HOME=/path/to/zulu-jdk-21

JAVA_HOME should point to the root directory of the JDK, not its bin directory.

That means:

JAVA_HOME
└── bin
    ├── java
    └── javac

Maven, Gradle, and other development tools may use JAVA_HOME to locate the JDK.

Checking JAVA_HOME

Windows PowerShell:

echo $env:JAVA_HOME

Windows Command Prompt:

echo %JAVA_HOME%

macOS or Linux:

echo $JAVA_HOME

If JAVA_HOME is configured, make sure it points to the Azul Zulu JDK 21 installation.

Which Java Executable Is Being Used?

If multiple Java installations exist on your computer, you can check which executable the terminal is using.

Windows:

where.exe java
where.exe javac

macOS or Linux:

which java
which javac

Then verify again:

java -version
javac -version

For this course, we need Java 21.

Test a Java Program from the Terminal

Before configuring IntelliJ IDEA, let's compile and run a small Java program from the terminal.

Create a file named Main.java:

public class Main {

    public static void main(String[] args) {
        System.out.println("Java setup is working");
    }
}

Compile it:

javac Main.java

If compilation succeeds, the following file will be created in the same directory:

Main.class

Now run it:

java Main

Output:

Java setup is working

If you see this output, both your Java compiler and runtime are working.

What Is an IDE?

IDE — Integrated Development Environment is an application that provides several software development tools in one place.

An IDE commonly provides:

  • Code editor
  • Project explorer
  • Code completion
  • Error highlighting
  • Run and debug support
  • Refactoring
  • Test runner
  • Terminal
  • Version control integration

In this course, we will use IntelliJ IDEA.

Installing IntelliJ IDEA

Download and install IntelliJ IDEA for your operating system and CPU architecture.

For learning core Java and OOP, the free edition is sufficient.

After installation is complete, start IntelliJ IDEA.

Configure Azul Zulu JDK 21 in IntelliJ IDEA

IntelliJ IDEA needs to know which JDK it should use to compile and run your project.

When creating a new Java project, select:

Azul Zulu 21

as the JDK.

Conceptually:

New Project
→ Java
→ JDK
→ Azul Zulu 21

IntelliJ IDEA may detect the installed JDK automatically.

If it does not, select:

Add JDK

and point IntelliJ IDEA to the Azul Zulu JDK 21 installation directory.

What Is Project SDK?

Project SDK is the JDK that IntelliJ IDEA uses to compile and run a specific project.

For projects in this course, use:

Project SDK: Azul Zulu 21

If there is an option to select the Java language level, keep it compatible with Java 21 as well.

Test the Setup from IntelliJ IDEA

Create a Java project and select Azul Zulu 21 as the JDK.

Create a Main class:

public class Main {

    public static void main(String[] args) {
        System.out.println("IntelliJ IDEA is ready");
    }
}

Run the program.

Output:

IntelliJ IDEA is ready

If you see this output:

  • The JDK is configured
  • The project is compiling
  • The Java program is running

Your development environment is ready.

Why Did We Test Both the Terminal and IDE?

Running a program from the terminal confirms that the operating system-level Java setup is working.

Running a program from IntelliJ IDEA confirms that the IDE is using the correct Project SDK.

If both tests are successful, your environment is ready for the upcoming coding lessons.

Common Setup Problems

java Command Is Not Found

If you see:

java: command not found

or:

'java' is not recognized

check whether:

  • Azul Zulu JDK 21 is installed
  • The JDK is available in PATH
  • You opened a new terminal after installation

Then run again:

java -version

java Works, but javac Does Not

Run:

java -version
javac -version

This may happen if:

  • A full JDK is not installed
  • PATH points to another Java installation

Make sure Azul Zulu JDK 21 is installed.

Wrong Java Version

If you see:

java 17
javac 21

or another version is being used instead of Java 21, check the executable locations.

Windows:

where.exe java
where.exe javac

macOS / Linux:

which java
which javac

Then check:

  • PATH
  • JAVA_HOME
  • IntelliJ IDEA Project SDK

Use Java 21 in all relevant places.

IntelliJ IDEA Does Not Detect the JDK

First, verify from the terminal:

java -version
javac -version

If both commands work correctly, select:

Add JDK

in IntelliJ IDEA and manually choose the Azul Zulu JDK 21 installation directory.

Project SDK is not defined

A JDK has not been selected for the project.

From the project settings, select:

Azul Zulu 21

IntelliJ IDEA Uses Another Java Version

Even if Java 21 is available in the terminal, IntelliJ IDEA may use a different JDK.

Check the Project SDK:

Project SDK: Azul Zulu 21

Wrong CPU Architecture

If the installer or JVM does not start, check whether the downloaded JDK matches your CPU architecture.

Common mapping:

Intel / AMD 64-bit → x64
Apple Silicon      → ARM64

Development Environment Checklist

Before moving to the next lesson, make sure:

  • Azul Zulu JDK 21 is installed
  • The correct operating system and CPU architecture were selected
  • java -version shows Java 21
  • javac -version shows Java 21
  • If JAVA_HOME is configured, it points to Zulu JDK 21
  • A Java program was successfully compiled from the terminal
  • A Java program was successfully run from the terminal
  • IntelliJ IDEA is installed
  • Azul Zulu 21 is configured as the Project SDK
  • A Java program was successfully run from IntelliJ IDEA

Practice Exercise 1: Verify the Environment

Run the following commands from the terminal:

java -version
javac -version

Check whether both commands report Java 21.

Then check the executable locations.

Windows:

where.exe java
where.exe javac

macOS / Linux:

which java
which javac

Practice Exercise 2: Run a Program from the Terminal

Create SetupTest.java:

public class SetupTest {

    public static void main(String[] args) {
        System.out.println("My Java setup works");
    }
}

Compile:

javac SetupTest.java

Run:

java SetupTest

Expected output:

My Java setup works

Practice Exercise 3: Run a Program from IntelliJ IDEA

Create a Java project in IntelliJ IDEA.

Select Azul Zulu 21 as the Project SDK.

Then create:

public class EnvironmentCheck {

    public static void main(String[] args) {
        System.out.println("IDE and JDK are configured");
    }
}

Run the program.

Expected output:

IDE and JDK are configured

Knowledge Check

Question 1

Which JDK and Java version are we using in this course?

Question 2

Why do we check both java -version and javac -version?

Question 3

What is PATH used for?

Question 4

What does JAVA_HOME point to?

Question 5

What is a Project SDK?

Question 6

What commands are used to compile and run a Java program from the terminal?

Question 7

If Java 21 is available in the terminal but IntelliJ IDEA is using another Java version, where should you check?

Knowledge Check Answers

Answer 1

In this course, we use Azul Zulu JDK 21.

Answer 2

java -version shows the Java runtime version, while javac -version shows the compiler version. We need to verify that both are using Java 21.

Answer 3

PATH tells the operating system where to find executable commands.

Answer 4

JAVA_HOME points to the root directory of the JDK installation.

Answer 5

Project SDK is the JDK that IntelliJ IDEA uses to compile and run a project.

Answer 6

Compile:

javac Main.java

Run:

java Main

Answer 7

Check IntelliJ IDEA's Project SDK and configure it to use Azul Zulu 21.

Lesson Summary

In this lesson, we learned:

  • We are using Azul Zulu JDK 21 and IntelliJ IDEA for Java development
  • The correct JDK must be selected for the operating system and CPU architecture
  • java -version and javac -version can be used to verify the Java 21 installation
  • PATH helps the operating system locate Java commands
  • JAVA_HOME points to the JDK installation directory
  • The setup can be verified by compiling and running a Java program from the terminal
  • Azul Zulu 21 should be configured as the Project SDK in IntelliJ IDEA
  • It is important to verify that both the terminal and IDE are using Java 21