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:
| Editor | Best for |
|---|---|
| IntelliJ IDEA Community (recommended) | Java-first workflow, strong defaults, free for learning |
| VS Code | Lightweight 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.
Option A: Install IntelliJ IDEA (Recommended)
Step 1: Download IntelliJ IDEA Community Edition
- Open https://www.jetbrains.com/idea/download/
- Choose Community (free, sufficient for this tutorial)
- 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
- Open IntelliJ IDEA
- On first run, complete the setup wizard (theme, plugins—defaults are fine)
- When creating a project later, IntelliJ should detect JDK 21 if it is on
PATHor registered with the OS
If JDK 21 is missing inside the IDE:
- File → Project Structure → SDKs (Windows/Linux) or IntelliJ IDEA → Settings → Project Structure → SDKs (macOS)
- Click + → Add JDK
- Point to your JDK folder (e.g. Temurin under
Program Files, Homebrewopenjdk@21, or/usr/lib/jvm/java-21-openjdk-amd64)
Step 4: Create a Quick Test Project (Optional Smoke Test)
- New Project
- Select Java on the left
- Build system: choose IntelliJ (no Maven/Gradle yet—keep it simple)
- JDK: select 21
- Name the project
java-editor-setupand click Create - If
srcis empty, right-click src → New → Java Class → name itHelloFromEditor - Add:
public class HelloFromEditor {
public static void main(String[] args) {
System.out.println("Hello from IntelliJ!");
}
}- Run with the green ▶ gutter icon or Run → Run 'HelloFromEditor'
Expected output in the Run tool window:
Hello from IntelliJ!Option B: Install VS Code
Step 1: Download VS Code
- Open https://code.visualstudio.com/
- 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.
- Open Settings (
Ctrl+,/Cmd+,) - Search for
java.jdt.ls.java.home(or Java: Home in the UI) - Set it to your JDK 21 root directory (the folder that contains
bin, notbinitself)
Alternatively, ensure JAVA_HOME is set in the environment before launching VS Code.
Step 4: Open a Folder and Verify
- Create a folder, e.g.
java-vscode-hello - File → Open Folder and select it
- Create
HelloFromEditor.java:
public class HelloFromEditor {
public static void main(String[] args) {
System.out.println("Hello from VS Code!");
}
}- When prompted, Trust the folder so the Java language server can run
- Click Run above
main, or open the terminal:
javac HelloFromEditor.java
java HelloFromEditorExpected output:
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:
- Confirm
java -versionworks in a system terminal - Project Structure → SDKs → Add JDK and select JDK 21 manually
- Restart IntelliJ
- Confirm
VS Code Shows “JDK not found” or No Run Button
- Problem: Language server cannot find a JDK
- Fix:
- Set
java.jdt.ls.java.hometo JDK 21 - Reload VS Code (
Developer: Reload Window) - Ensure the file is saved as
.javaand definespublic static void main
- Set
Editor Runs Code but Terminal javac Uses a Different Version
- Problem:
java -versionin 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 NamematchesName.javaexactly (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.