Java

Installing JDK, Setting Up IntelliJ IDEA, and Your First Java Program

Executive Summary

Installing JDK 21 takes three steps: install a distribution such as Eclipse Temurin, verify it with java –version and javac –version, then install IntelliJ IDEA Community Edition and point it at that JDK. Your first program is one class with a main method; you compile it to bytecode with javac and run it on the JVM with java, although IntelliJ hides the cycle behind a green run button. Choose an LTS release (21 today) and one vendor build, and resist installing multiple JDKs without a version manager. Set JAVA_HOME once, keep PATH clean, and your tools will stop surprising you. The payoff is a working Java environment for the remaining 73 articles of this course.

What You’re Actually Installing

Three acronyms hide inside every Java install, and mixing them up causes real confusion later. Learn the split now; it pays off again in the JVM architecture article in Part 6.

Piece What it is Key commands
JDK The development kit: compiler, launcher, debugger, JShell, plus everything below javac, java, jshell, jdb
JRE The runtime: JVM plus core libraries. Runs programs, cannot compile them java
JVM The virtual machine: loads bytecode, JIT-compiles hot paths, manages memory and GC launched by java

The JDK contains the JRE, which contains the JVM. Since Java 11 there is no separate JRE download: the JDK is the single install, and smaller runtimes are cut later with the jlink tool when needed. Therefore, one download gives you the whole toolchain.

Installing the JDK, Step by Step

Use JDK 21, the LTS release this course targets. Download it from a reputable distributor. Eclipse Temurin is free and production-proven; Oracle JDK 21 is free for development and production under its no-fee license terms, but many teams pick Temurin to keep licensing conversations simple. Both pass the same OpenJDK compatibility tests, so the choice is about support and habit, not features.

Windows

  1. Download the Windows .msi from Adoptium.
  2. Run the installer, and enable “Set JAVA_HOME” and “Add to PATH” when offered.
  3. Open a new PowerShell window, because PATH changes do not reach terminals that are already open.
java --version
openjdk version "21.0.x" ...

javac --version
javac 21.0.x

macOS

Install Homebrew from brew.sh if you have not, then run:

brew install --cask temurin@21

Linux (Debian and Ubuntu)

sudo apt install openjdk-21-jdk

Verify on all three platforms with the same two commands shown above. If java works but javac is missing, you installed a runtime, not a JDK. Consequently, go back and grab the full JDK 21 build.

The complete tool inventory, from javap to jcmd, is documented in the official JDK 21 guides. You will meet most of these tools later in the course.

Set JAVA_HOME Once

Running simple programs needs only the java command on PATH. Build tools such as Maven and Gradle read JAVA_HOME instead, so set it now and skip a class of confusing errors later. On Windows, the MSI checkbox does it; confirm it with $env:JAVA_HOME in PowerShell. On macOS, add this to your shell profile:

export JAVA_HOME=$(/usr/libexec/java_home -v 21)

Setting Up IntelliJ IDEA

You can write Java in any editor, and later in this article you will compile from the command line to understand the cycle. However, for daily work use IntelliJ IDEA: its inspections, refactoring, and debugger are why experienced Java engineers move fast.

Edition Cost Covers this course?
Community Free, open source Yes, fully
Ultimate Paid, free for students Only needed for the Spring Boot course later

Download the Community Edition from JetBrains. On first launch, open a project and check the SDK list in Project Structure: IntelliJ usually detects your JDK 21 automatically. If not, add an SDK entry pointing at the install directory.

Your First Java Program

Create a new project: File, New Project, language Java, SDK 21, no build system yet (Maven arrives in Part 7). Name it first-steps. Then create a file named HelloWorld.java under src and type this:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, production.");
        System.out.println("Java version: " + System.getProperty("java.version"));
    }
}

Run it with the green arrow next to main. Then run it the way the IDE does, from the terminal in the project directory:

javac HelloWorld.java     # compiles to HelloWorld.class (bytecode)
java HelloWorld           # the JVM loads the class and runs main()

# Java 11+ also runs single source files directly:
java HelloWorld.java

Three rules in that file matter. The public class name and the file name must match exactly, including case: HelloWorld lives in HelloWorld.java. The entry point signature must be exactly public static void main(String[] args). And the args array receives command-line arguments, which the CLI calculator build will use.

The Compile and Run Cycle

  you write              javac compiles          the JVM runs
  ------------           ---------------         ----------------
  HelloWorld.java   ->   HelloWorld.class   ->    loads the class
  (source you can         (bytecode:             JIT-compiles hot paths
   read and edit)          platform-neutral)      executes main()

The IDE hides this cycle, but it still happens on every run. In practice, knowing it saves you the day a build works in IntelliJ but fails on a server: you compare the .class files you shipped against the .java files you wrote, and the lie surfaces.

How Real Systems Do This

Production teams pin one JDK version and one distribution in a single place, then repeat that choice everywhere: laptops, CI pipelines, and containers. CI downloads the same Temurin build in a setup step, a pattern covered later in CI basics for Java with GitHub Actions. Dockerfiles install the same package. Consequently, “works on my machine” shrinks to almost nothing.

In my experience, the worst environment bugs come from silent version drift. We once lost two days to a build that failed only in CI because the runner defaulted to Java 17 while every laptop had 21; the fix was one line that pinned the version. A mistake I have seen more than once: JAVA_HOME still pointing at a JDK that was uninstalled during an upgrade, which produces errors that blame Maven or Gradle.

Decision Framework

Choose your environment with these questions, in order.

  1. Which release? An LTS one. Java 21 for this course; 25 only if you have a specific reason and matching tooling.
  2. Which vendor build? Temurin as the default. AWS Corretto if you live on AWS, Azul Zulu if your company standardized there, Oracle if policy says so.
  3. Which IDE? IntelliJ IDEA Community for this course. Eclipse and VS Code work, however the course instructions assume IntelliJ.
  4. Do you need several JDKs side by side? If yes, install SDKMAN on macOS and Linux or a similar version manager on Windows, instead of hand-editing PATH.
  5. Do you need a scratchpad? Yes: JShell, which ships with the JDK. Type jshell and experiment without classes or files.

When NOT to Use This

  • Do not install Java 8 in 2026 because an old tutorial said so. Its free public updates ended years ago, and course idioms such as var, records, and virtual threads do not compile on it.
  • Do not download the JDK from random “free Java” sites. Use Adoptium, Oracle, or your OS package manager. A tampered toolchain is a supply-chain incident waiting to happen.
  • Do not juggle multiple JDKs by editing PATH per project. That approach works until two projects need different versions; then use a version manager.

Common Mistakes

  • ‘javac’ is not recognized. The JDK bin directory is missing from PATH, or you did not open a new terminal after installing.
  • java works but javac does not. You installed a runtime, not a JDK; repeat the install with the full JDK 21 package.
  • Class and file name mismatch. public class HelloWorld inside helloWorld.java fails with a confusing compile error; case matters.
  • Editing code but running a stale build. The IDE executed an old .class because save-on-run or auto-build was off.
  • Setting JAVA_HOME in the wrong shell profile, so some tools see it and others do not, with “wrong version” errors as the symptom.
  • Never compiling from the terminal. If the green button is your only model, a broken build outside the IDE leaves you without a mental picture to debug.

Key Takeaways

  • The JDK compiles and runs Java, the JRE only runs it, and the JVM executes the bytecode. One JDK 21 download includes all of it.
  • After installing JDK 21, verify every install with both java –version and javac –version, in a new terminal.
  • Set JAVA_HOME once; Maven and Gradle read it, and stale values cause misleading build errors.
  • IntelliJ IDEA Community is free and covers the entire course; Ultimate matters only for the Spring Boot course.
  • Know the cycle: javac turns .java into .class, and the JVM loads and runs the bytecode. The IDE just presses the same buttons.
  • Pin one JDK version and one vendor across laptop, CI, and containers to kill version drift.
  • JShell, included in the JDK, is your scratchpad for experiments between articles.

FAQ

Do I need to set JAVA_HOME to run Java?

For simple runs, no: the java command on PATH is enough. Build tools such as Maven and Gradle read JAVA_HOME, however, so set it once now and avoid “wrong version” errors later.

What is the difference between JDK and JRE?

The JRE runs Java programs; the JDK compiles them. The JDK contains the JRE plus javac, jshell, jdb, and friends. Since Java 11 there is no separate JRE download; the JDK is the single install.

Which JDK distribution should I install?

Eclipse Temurin is the safe default and this course’s assumption. AWS Corretto fits AWS shops, Azul Zulu appears in many enterprises, and Oracle JDK 21 is free for dev and production under its no-fee terms. All pass the same compatibility tests, so pick one and stay consistent.

Is IntelliJ IDEA free?

The Community Edition is free and open source, and it covers everything in this course. Ultimate Edition is paid and adds framework tooling you will not need until the Spring Boot course.

Can I use VS Code instead of IntelliJ?

Yes. Install the Extension Pack for Java and point it at JDK 21. The course assumes IntelliJ, though, because full-IDE refactoring and debugging will save you hours from Part 2 onward.

Conclusion

You now have a working JDK 21, IntelliJ IDEA, and the one mental model that matters: source compiles to bytecode, and the JVM runs it. Everything ahead, from the next article on variables to the capstone build, stands on that cycle.

Pin your JDK, keep one distribution, and move on. The environment is done; now write code worth running.

Last updated on 25 September 2026.

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *