Install a Code Editor for Java

Introduction

In the previous chapter, you compiled and ran Java from the terminal. That workflow is essential, but plain terminals do not offer syntax highlighting, code completion, or inline error hints. This chapter installs a modern editor and connects it to your JDK 21 so you can write Java with better feedback.

Prerequisites

  • JDK 21 installed and verified (java -version, javac -version)
  • Completed terminal Hello World
  • Internet access to download an editor
  • At least 4 GB RAM (8 GB recommended for IntelliJ IDEA)

Why Use a Code Editor for Java

A good editor speeds up learning and catches mistakes before you compile.

Key benefits:

  • Syntax highlighting separates keywords, types, and strings
  • Code completion suggests methods and imports
  • Inline diagnostics flag errors before javac
  • Integrated terminal keeps compile-run steps in one window
  • Debugger support (later chapters) for stepping through code

Editor Options Used Most in Practice

For Java beginners, these two are the most common:

EditorBest for
IntelliJ IDEA Community (recommended)Java-first workflow, strong defaults, free for learning
VS CodeLightweight editor if you already use it for other languages

Tip

Choosing Quickly

If you want the smoothest Java onboarding, start with IntelliJ IDEA Community Edition.
If you already live in VS Code, install the Java extension pack and continue there—but still read Hello World in IntelliJ if your course follows IDEA.

Step 1: Download IntelliJ IDEA Community Edition

  1. Open https://www.jetbrains.com/idea/download/
  2. Choose Community (free, sufficient for this tutorial)
  3. Download the installer for your OS (Windows .exe, macOS .dmg, Linux Toolbox or tarball)

Step 2: Run Installation

  • Windows: run the installer; keep default options unless you need a custom install path
  • macOS: open .dmg, drag IntelliJ IDEA to Applications
  • Linux: use JetBrains Toolbox or the official tarball; make the launcher script executable if needed

Step 3: First Launch and JDK Detection

  1. Open IntelliJ IDEA
  2. On first run, complete the setup wizard (theme, plugins—defaults are fine)
  3. When creating a project later, IntelliJ should detect JDK 21 if it is on PATH or registered with the OS

If JDK 21 is missing inside the IDE:

  1. File → Project Structure → SDKs (Windows/Linux) or IntelliJ IDEA → Settings → Project Structure → SDKs (macOS)
  2. Click +Add JDK
  3. Point to your JDK folder (e.g. Temurin under Program Files, Homebrew openjdk@21, or /usr/lib/jvm/java-21-openjdk-amd64)

Step 4: Create a Quick Test Project (Optional Smoke Test)

  1. New Project
  2. Select Java on the left
  3. Build system: choose IntelliJ (no Maven/Gradle yet—keep it simple)
  4. JDK: select 21
  5. Name the project java-editor-setup and click Create
  6. If src is empty, right-click srcNew → Java Class → name it HelloFromEditor
  7. Add:
java
public class HelloFromEditor {
    public static void main(String[] args) {
        System.out.println("Hello from IntelliJ!");
    }
}
  1. Run with the green ▶ gutter icon or Run → Run 'HelloFromEditor'

Expected output in the Run tool window:

text
Hello from IntelliJ!

Option B: Install VS Code

Step 1: Download VS Code

  1. Open https://code.visualstudio.com/
  2. Download and install for your operating system

Step 2: Install Java Extensions

Open VS Code and install:

  • Extension Pack for Java (Microsoft)—bundles Language Support, debugger, test runner, Maven support, and more

Reload the window if prompted.

Step 3: Point VS Code to JDK 21

VS Code uses the JDK for compilation and language features.

  1. Open Settings (Ctrl+, / Cmd+,)
  2. Search for java.jdt.ls.java.home (or Java: Home in the UI)
  3. Set it to your JDK 21 root directory (the folder that contains bin, not bin itself)

Alternatively, ensure JAVA_HOME is set in the environment before launching VS Code.

Step 4: Open a Folder and Verify

  1. Create a folder, e.g. java-vscode-hello
  2. File → Open Folder and select it
  3. Create HelloFromEditor.java:
java
public class HelloFromEditor {
    public static void main(String[] args) {
        System.out.println("Hello from VS Code!");
    }
}
  1. When prompted, Trust the folder so the Java language server can run
  2. Click Run above main, or open the terminal:
bash
javac HelloFromEditor.java
java HelloFromEditor

Expected output:

text
Hello from VS Code!

Warning

Do not install many unrelated extensions before basic Java setup works. Noisy linters confuse beginners.

Common Setup Problems and Fixes

JDK Not Detected in IntelliJ

  • Problem: New Project shows no JDK or wrong version
  • Fix:
    1. Confirm java -version works in a system terminal
    2. Project Structure → SDKs → Add JDK and select JDK 21 manually
    3. Restart IntelliJ

VS Code Shows “JDK not found” or No Run Button

  • Problem: Language server cannot find a JDK
  • Fix:
    1. Set java.jdt.ls.java.home to JDK 21
    2. Reload VS Code (Developer: Reload Window)
    3. Ensure the file is saved as .java and defines public static void main

Editor Runs Code but Terminal javac Uses a Different Version

  • Problem: java -version in terminal ≠ IDE SDK
  • Fix: Align JAVA_HOME, IDE project SDK, and VS Code Java: Home to the same JDK 21 path

Class Name Does Not Match Filename

  • Problem: Red errors in editor; compile fails
  • Fix: Rename the file or class so public class Name matches Name.java exactly (case-sensitive)

What’s Next

Your editor is ready. The next chapter walks through a full Hello World project in IntelliJ IDEA—project layout, run configuration, and useful shortcuts: Write Hello World in IntelliJ IDEA.

FAQ

Should beginners choose IntelliJ IDEA or VS Code first?

IntelliJ IDEA Community is usually easier for pure Java learning because project and JDK setup are built in. VS Code is excellent if you already use it daily or want a lighter editor.

Do I need IntelliJ IDEA Ultimate (paid)?

No. Community Edition covers Java fundamentals, console programs, and learning through this tutorial series.

Why is syntax highlighting important for Java?

Java has more ceremony than Python—braces, types, and keywords. Highlighting helps you spot missing semicolons, strings, and mismatched blocks faster.

Can I switch editors later?

Yes. .java files are standard. You can open the same sources in IntelliJ, VS Code, or compile from the terminal.

Does the editor replace javac and java?

No. The IDE invokes the JDK tools (or equivalent build logic) for you. Understanding the terminal workflow from the previous chapter still matters.