Setting Up IntelliJ IDEA for Java Development

java dev.to

If you asked a hundred Java developers what editor they use, most of them would say IntelliJ IDEA. There is a reason for that. It has been the dominant Java IDE for years, and once you get used to how much it does for you, going back to a plain text editor feels like writing with your non-dominant hand.

This walkthrough covers the setup from scratch. Download, install, create a project, write some code, run it, and debug it. By the end you will have a working Java environment and a feel for the shortcuts that make IntelliJ worth learning.

Community vs Ultimate

IntelliJ comes in two editions. Community is free and has everything you need for standard Java development. Ultimate is the paid version with extra support for web frameworks, databases, and enterprise tools.

When you first install IntelliJ, you get a 30-day trial of Ultimate. After that, it drops down to Community automatically. For learning Java and most personal projects, Community is more than enough. Do not pay for Ultimate unless you know you need it.

Download IntelliJ from the JetBrains website and follow the installer for your operating system.

Create your first project

Launch IntelliJ and you will see a welcome screen. Click New Project.

In the New Project window:

  1. Select Java on the left.
  2. Give the project a name, something like java-demo.
  3. Pick a build system. You have three choices here, and it matters less than you might think:
    • IntelliJ is the simplest. No extra config files. Fine for small experiments.
    • Maven is the industry standard. It uses a pom.xml file to manage dependencies and builds. If you plan to share your code or add libraries later, pick this.
    • Gradle is the other big build tool. Common in Android and large projects. Slightly steeper learning curve.

For this guide, choose Maven. It is the most common in tutorials and job listings, so getting comfortable with it early pays off.

  1. Leave Add sample code unchecked. You will write the code yourself.

Click Create.

Set up your JDK

A JDK (Java Development Kit) is what actually compiles and runs your code. IntelliJ cannot do Java without one.

If you already have a JDK installed, IntelliJ usually finds it. Just pick it from the JDK dropdown in the New Project window.

No JDK yet? No problem. Click the dropdown, select Download JDK, and IntelliJ downloads one for you. Pick a vendor (Oracle OpenJDK is a safe default) and a version. Java 17 and Java 21 are both long-term support releases and good choices for new projects. Java 25 is the newest if you want the latest features.

This is one of the things IntelliJ does better than most editors. You never have to mess with environment variables or PATH settings. It handles the JDK configuration internally.

The project structure

After you click Create, IntelliJ opens your project. On the left side you will see the Project tool window with a folder structure that looks something like this:

java-demo/
├── src/
│   ├── main/
│   │   └── java/       ← your code goes here
│   └── test/
│       └── java/       ← your tests go here
├── pom.xml             ← Maven configuration
└── .idea/              ← IntelliJ settings (don't touch)
Enter fullscreen mode Exit fullscreen mode

The src/main/java folder is where your Java source files live. The test folder is for automated tests. The pom.xml is where Maven stores project info and dependency declarations.

Write and run your first class

Right-click the src/main/java folder and select New > Java Class. Name it Main. IntelliJ creates a basic class skeleton for you.

Replace the contents with this:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello from IntelliJ!");
    }
}
Enter fullscreen mode Exit fullscreen mode

Now look at the left margin, next to the main method declaration. You will see a green play button. Click it and select Run 'Main.main()'.

Your output shows up in the Run panel at the bottom. No javac command, no manual compile step. IntelliJ compiles and runs in one click.

If you are on a Mac, Ctrl+Shift+R runs the current file. On Windows or Linux, use Ctrl+Shift+F10.

Code completion and quick fixes

This is where IntelliJ starts earning its reputation. As you type, it suggests class names, method names, and variable names. Press Tab or Enter to accept a suggestion. It saves you from typos and from memorizing the entire standard library.

The bigger feature is Alt+Enter (or Option+Enter on Mac). Any time IntelliJ spots a problem, a red underline appears. Press Alt+Enter and IntelliJ offers to fix it. Missing import? It adds the import. Wrong variable type? It suggests a cast. Undefined variable? It offers to create one.

Think of Alt+Enter as the "do something smart" key. You will press it constantly.

You can also generate boilerplate code. Press Alt+Insert (or Cmd+N on Mac) inside a class, and IntelliJ offers to generate constructors, getters, setters, toString(), equals(), and hashCode(). For a class with five fields, that is five minutes of typing saved.

Debugging

Run your code with the debugger instead of the regular Run button, and you can pause execution at any line. Click in the gutter next to a line number to set a breakpoint (a red dot appears). When execution hits that line, it stops.

From there:

  • F8 steps over to the next line without diving into method calls
  • F7 steps into a method to see what happens inside it
  • F9 resumes execution until the next breakpoint

While paused, you can see the current value of every variable in the Variables panel. You can also right-click any expression and select Evaluate Expression to see its value on the spot. This is invaluable when a calculation returns something unexpected and you need to figure out which step went wrong.

Testing

Press Ctrl+Shift+T (or Cmd+Shift+T on Mac) with your cursor inside a class, and IntelliJ jumps to the test for that class. If no test exists yet, it creates one for you.

IntelliJ defaults to JUnit 5, the most widely used testing framework for Java. If JUnit is not in your project yet, IntelliJ detects this and offers to add the dependency automatically. Click Fix and it updates your pom.xml for you.

Write a test method, annotate it with @Test, and run it with the same green play button. Green bar means pass, red means fail.

Refactoring

Renaming a variable in five files by hand is tedious and error-prone. IntelliJ does it safely. Put your cursor on a variable, method, or class name and press Shift+F6. Type the new name, hit Enter, and IntelliJ updates every reference across your entire project.

Other useful refactorings:

  • Ctrl+Alt+M (or Cmd+Alt+M on Mac) extracts selected code into a new method. Great for breaking up long methods.
  • Ctrl+Alt+V extracts an expression into a variable. Useful when a complex expression is hard to read.
  • Ctrl+Alt+L reformats your code to match the project's style settings.

Search Everything

Press Shift twice and a search box pops up. Type anything: a class name, a file name, a setting, an action. IntelliJ searches your entire project and its own settings. It is the fastest way to find anything without clicking through menus.

For searching inside file contents across the whole project, press Ctrl+Shift+F (or Cmd+Shift+F on Mac). This opens Find in Files, which is handy for tracking down where a method is used or finding a specific string.

Quick summary

  • IntelliJ Community is free and sufficient for learning Java. Ultimate adds enterprise features.
  • Create a Maven project from the welcome screen. Maven is the most common build tool in the Java ecosystem.
  • No JDK? IntelliJ downloads one for you. No PATH or environment variable setup needed.
  • Code lives in src/main/java, tests in src/test/java, Maven config in pom.xml.
  • Click the green play button in the gutter to run code. Alt+Enter fixes problems. Alt+Insert generates boilerplate.
  • Debug with breakpoints (F8 to step over, F7 to step in, F9 to resume).
  • Shift+Shift opens Search Everywhere. Ctrl+Shift+F searches file contents project-wide.
  • Shift+F6 renames safely across the whole codebase.

Based on dev.java/learn: Building a Java application in IntelliJ IDEA

Source: dev.to

arrow_back Back to Tutorials