Week 1

Environment setup

How Java works

Types and Variables

Arrays

Basic IO

Control Flow

Packages

OOP in Java

Static Members

Practice

Assignment

Back end Track

🎯 Learning Objectives

By the end of this module, you will be able to:


1. What is the JDK?

The Java Development Kit (JDK) is the software package you install on your machine to write, compile, and run Java programs. It contains three main components:

Component Full Name What it does
JVM Java Virtual Machine Executes your compiled Java program
JRE Java Runtime Environment The libraries and files the JVM needs to run
Dev Tools Development Tools Command-line tools for compiling, packaging, and documenting code

Think of it this way: the JRE is the engine, the JVM is what runs your code inside that engine, and the dev tools are the toolkit you use to build things.


2. Command-Line Tools You Get with the JDK

When you install the JDK, you get these tools available in your terminal:

Tool Command What it does JS/Node Equivalent
Compiler javac Converts .java source code into .class bytecode tsc (TypeScript Compiler)
Launcher java Starts the JVM and runs your compiled program node index.js
Archiver jar Packages your code into a single .jar file npm pack / Webpack
Documentation javadoc Generates HTML docs from your code comments JSDoc

You won't use all of these immediately, but it's good to know they exist. For now, javac and java are the two you'll use the most — and your IDE will often run them for you behind the scenes.


3. JDK Distributions

Java is an open standard, which means different organisations can build and distribute their own version of the JDK as long as they comply with the official specification. They all run the same Java code — the difference is who builds and maintains them.

Distribution Provider Cost Recommended for
OpenJDK Oracle / Community Free General use, the reference implementation
Temurin Adoptium (Eclipse) Free Most popular choice for production
Corretto Amazon Free AWS-hosted applications
Oracle JDK Oracle Paid (commercial) Enterprise with Oracle support contracts
Zulu Azul Free / Paid Broad platform support
GraalVM Oracle / Community Free / Paid Performance-critical or polyglot apps

💡 For this course we use OpenJDK 21 — it's free, widely used, and the version most tools and frameworks support well. Any other free distribution would also work fine.


4. Installing OpenJDK 21

Follow the instructions for your operating system. If you're not sure which one you have, ask your coach before starting.


🪟 Windows

Open PowerShell as Administrator and run:

# Step 1 — Install Chocolatey (Windows package manager)
powershell -c "irm <https://community.chocolatey.org/install.ps1> | iex"

# Step 2 — Install OpenJDK 21
choco install openjdk21

💡 Chocolatey is a package manager for Windows — similar to apt on Ubuntu or brew on macOS. It handles downloading and installing software from the command line.


🐧 Linux (Ubuntu / Debian)

Open your terminal and run:

# Step 1 — Update the package registry
sudo apt update

# Step 2 — Install OpenJDK 21
sudo apt install openjdk-21-jdk

🍎 macOS

Open your terminal and run:

# Step 1 — Install Homebrew (macOS package manager), skip if already installed
/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

# Step 2 — Install OpenJDK 21
brew install openjdk@21

# Step 3 — Link it so your terminal can find it
sudo ln -sfn $(brew --prefix)/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk

💡 Homebrew is the standard package manager for macOS development tools — similar to apt on Ubuntu.


5. Verify Your Installation

Once the installation is complete, close and reopen your terminal, then run:

javac -version

You should see output like:

javac 21.0.x

Also verify the runtime:

java -version

Expected output:

openjdk version "21.0.x" ...

⚠️ If you see an error like javac: command not found, try closing and reopening your terminal first. If the error persists, your PATH may not include the JDK's bin folder — see the JAVA_HOME section below or ask your coach.

For more help, visit the official installation guide: https://openjdk.org/install/


6. Understanding JAVA_HOME

Many Java tools — including IntelliJ IDEA, Maven, and Gradle — look for an environment variable called JAVA_HOME. This variable holds the path to the root folder of your JDK installation, so these tools can find the JDK without you having to configure each one manually.

Check if it's already set

# macOS / Linux
echo $JAVA_HOME

# Windows (PowerShell)
echo $env:JAVA_HOME

If it prints a path (e.g. /usr/lib/jvm/java-21-openjdk-amd64), you're good. If it prints nothing, you may need to set it — IntelliJ can usually handle this automatically, but some build tools need it explicitly.

💡 In practice, IntelliJ IDEA detects your JDK automatically when you create a project. You only need to set JAVA_HOME manually if a command-line build tool like Maven or Gradle can't find your JDK. Ask your coach if you run into this.


7. Managing Multiple Java Versions with SDKMAN!

As you work on different projects, you may encounter ones that require different Java versions. SDKMAN! is the standard tool for installing and switching between multiple JDK versions from the terminal — similar to nvm for Node.js.

It works on macOS, Linux, and Windows (via WSL):

# Install SDKMAN!
curl -s "<https://get.sdkman.io>" | bash

# Install a specific JDK
sdk install java 21-open

# Switch between versions
sdk use java 21-open

# List available versions
sdk list java

💡 You don't need SDKMAN! right now, but it's worth knowing it exists. It becomes very useful once you start working on multiple Java projects professionally.

More information: https://sdkman.io/


8. Setting Up IntelliJ IDEA

IntelliJ IDEA is the industry-standard IDE for Java development. It handles compiling, running, debugging, and much more — so you can focus on writing code rather than managing tools.

Installation

  1. Go to https://www.jetbrains.com/idea/download/
  2. Download the Community Edition (free) for your operating system
  3. Run the installer and follow the setup wizard

Create Your First Project

  1. Open IntelliJ IDEA