Setting up an IDE for Java

Pointing it at the JDK you chose, and the three settings worth changing on day one.

8 min read🔧 Setting Up Java

You have compiled and run by hand, so you know what the IDE is going to do for you. Now set it up, and change the three settings that are worth changing before you start.

Which one

IntelliJ IDEA Community Edition is the default for Java. Free, no account, and what most Java teams use. The paid Ultimate edition adds framework support (Spring, JPA tooling) that is genuinely useful later and unnecessary now.

VS Code with the Extension Pack for Java works well and is lighter, and is the obvious choice if you already live there for other languages.

Eclipse is free and capable and has fewer users each year.

Pick one. Learn it properly — its shortcuts, its debugger, its refactorings — rather than using three at ten per cent.

Point it at the JDK you chose

This is the one setup step that actually matters, because the IDE has its own idea of which JDK to use and it is often not yours.

IntelliJ — File → Project Structure → Project SDK. Set it to the JDK you installed, and set the Language level to match. If the list is empty, add it by pointing at your JAVA_HOME directory.

VS Code — java.jdt.ls.java.home in settings, and java.configuration.runtimes if you keep several.

Then check it agrees with your terminal. Print the version from inside a program:

java
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.home"));

Run that in the IDE and compare it with java -version in your terminal. If they differ, you have two JDKs and two answers, and the day they disagree about something subtle you will remember this.

Three settings worth changing on day one

1. Turn on automatic imports. IntelliJ: Editor → General → Auto Import → add unambiguous imports on the fly, and optimise imports on the fly. It removes a constant small friction.

The caveat is worth stating because it bites: when two classes share a name — and List, Date and Logger all have several — the IDE picks one. Glance at the import when you type a class name you have not used in this file before.

2. Make the formatter automatic. Format on save, or a keyboard shortcut you actually press. Consistent formatting is not about beauty; it is about diffs. A commit that changes one line should show one line, not forty because your editor re-indented.

Better still, if the project has a .editorconfig or a formatter configuration, the IDE should be reading it. Then everybody's output matches without anybody negotiating.

3. Learn four shortcuts before anything else. Not thirty. Four:

DoIntelliJ (macOS / Windows)
Go to definition⌘B / Ctrl+B
Find usages⌥F7 / Alt+F7
Search everywhereShift Shift
Rename (as a refactor)⇧F6 / Shift+F6

The first two are the ones you will use hundreds of times a day. Reaching for the mouse each time is a real tax on how far you can follow a thought.

Turn on what will save you

Compiler warnings as something you read. The IDE flags unused variables, unreachable code, a null check that cannot fail, resources never closed. Most are worth acting on. The ones that are not can be suppressed deliberately, which is better than an editor full of yellow you have learned to ignore.

The debugger, and knowing where the button is. You will need it in your first week. The foundations course covers the method; find the breakpoint gutter and the step buttons now, while nothing is broken.

What not to do yet

Do not install a pile of plugins. The defaults are good. Add one when you have felt the specific absence.

Do not adopt somebody's keymap. Learn the four above in your IDE's own bindings; remapping before you know what you are remapping makes every tutorial harder to follow.

Do not let the IDE be the only way you build. Run mvn test or ./gradlew build from the terminal at least once on any project you work on. That is what CI runs, and the first time the two disagree you want to already know how to ask the build directly.

Under the hood: what an IDE's "index" actually is

Go-to-definition and find-usages do not work by re-running javac over your whole project every time you ask a question — that would be far too slow to feel instant. Instead, the IDE builds and maintains its own index: a symbol table it constructs by parsing your source (and the classes and, where available, sources on your classpath) with its own incremental parser, recording where every class, method and field is declared and every place it is referenced. Asking "where is this used" is then a table lookup against that index, not a fresh search through every file.

That parser is deliberately more forgiving than the compiler. It has to tolerate code that does not currently compile — a file you are mid-edit, a method you have not finished typing — because refusing to index anything until the whole project builds would make the editor useless while you are actually writing code. That tolerance is also exactly why the index can be wrong in a way the compiler never is: it is a separate, cached understanding of your code, built by a separate tool, and it only reflects what it last parsed against what it last believed your classpath to be.

That is the real mechanism behind the [!MISTAKE] callout above. The index is built once against the classpath the IDE knew about when it imported the project, and it is updated incrementally after that — but if the actual build's classpath changes (a dependency added to pom.xml or build.gradle, a module moved) and the IDE has not re-synced against the build tool, the index still reflects the old classpath. The editor shows a class as missing that the build compiles without complaint, because the editor and the build are, at that moment, consulting two different pictures of your dependencies.

Try it yourself

Diagnose a red squiggly that shouldn't be there

Your IDE underlines an import in red. You are confident the class exists, and mvn test from the terminal builds clean. Using only what this lesson said about the index, what is actually going on, and what is the right fix — and the wrong one?

What is actually out of sync

The build succeeding proves the class genuinely exists on the real classpath — so the red squiggly is not a real compile error, it is the IDE's own index reporting what its parser currently believes, and that belief has fallen behind the actual build configuration (most often because a dependency changed and the IDE was never told to re-sync). The right fix is to make the IDE re-derive its index from the build file: reimport the project, or the IDE's equivalent "reload changes" action. The wrong fix is editing the import, deleting and retyping it, or otherwise changing working code to please an index that is simply stale — that treats the IDE's cached opinion as more authoritative than the build that actually produces the artifact.

Misconceptions

  • "The red squiggly is always a real compile error." It is the IDE's own index reporting what its parser currently believes, which can lag behind the actual build — see the callout above.
  • "Autocomplete proves a method exists with that exact overload." It proves the index found a symbol matching what you typed against what it last parsed. It has not run the compiler's actual overload resolution, which is a stricter question only the build answers for certain.

Sources

  • IntelliJ Platform documentation, "Indexing" — how the IDE builds and maintains its symbol index.
  • Eclipse JDT (Java Development Tools) documentation — the incremental Java builder used for editor feedback, separate from a project's real build.
  • Language Server Protocol specification — the general parse-and-index-then-serve-navigation model behind editor tooling such as VS Code's Java support.
Progress is saved on this device and to your account when signed in.