Setting Up a Java Development Environment
Configure your machine for Java development: choosing an IDE (IntelliJ IDEA, Eclipse, VS Code), setting PATH and JAVA_HOME, and structuring a project.
A JDK alone is enough to compile and run Java from a terminal, but for any project larger than a handful of files you'll want an integrated development environment (IDE). An IDE gives you autocomplete, refactoring, an integrated debugger, and a project model that understands Java's package structure.
This chapter compares the major IDEs, walks through a recommended setup, and shows how a typical Java project is organized on disk.
Choosing an IDE
The three most popular Java IDEs are all free for individual use:
- IntelliJ IDEA Community Edition — JetBrains' Java IDE. The free Community Edition is more than enough for most learning and many production projects; the paid Ultimate Edition adds frameworks like Spring and Jakarta EE support. Recommended for this book.
- Eclipse IDE — the long-standing open-source IDE, popular in large enterprises.
- VS Code with the Extension Pack for Java — lighter than IntelliJ or Eclipse, a good fit if you already use VS Code for other languages.
You can also follow along in a plain text editor (Vim, Sublime, Notepad) and use the javac and java commands directly — the early chapters of this book show both styles.
IntelliJ IDEA: a recommended setup
If you have no strong preference, install IntelliJ IDEA Community Edition.
- Download from jetbrains.com/idea and run the installer.
- Launch IntelliJ and open the New Project dialog.
- Pick Java, then select the JDK you installed in the previous chapter from the JDK dropdown (IntelliJ usually detects it automatically; if not, click Download JDK or Add JDK).
- Choose Maven or Gradle as the build system if you want one, or IntelliJ for a plain learning project.
- Click Create.
IntelliJ will open the new project, index it, and place the cursor inside an empty Main.java. Press Shift+F10 (Windows/Linux) or Control+R (macOS) to run it.
VS Code
- Install VS Code.
- Open the Extensions sidebar and search for Extension Pack for Java (published by Microsoft).
- Install it. The pack bundles the Java language server, debugger, Maven support, and a few related extensions.
- Open a folder containing a
.javafile. VS Code will detect the JDK and offer to run or debug the program from the gutter icons.
If VS Code can't find your JDK, set the java.jdt.ls.java.home setting to the JDK's install root (the directory that contains bin/javac).
Eclipse
- Download the Eclipse IDE for Java Developers package from eclipse.org.
- Unpack and launch.
- Use File → New → Java Project, give it a name, and accept the default JDK. Eclipse creates a
src/folder where your.javafiles live.
Project layout
Most Java projects follow a convention popularised by Maven and adopted by Gradle:
my-project/
├── pom.xml # Maven build file (or build.gradle for Gradle)
├── src/
│ ├── main/
│ │ ├── java/ # production source files
│ │ │ └── com/example/MyApp.java
│ │ └── resources/ # config files, templates, properties
│ └── test/
│ ├── java/ # test source files
│ │ └── com/example/MyAppTest.java
│ └── resources/ # test fixtures
└── target/ # compiled output (gitignored)The src/main/java directory mirrors the package hierarchy: a class declared as package com.example; lives in src/main/java/com/example/. Stick to this layout and every Java tool will know where to find your code.
For the early chapters of this book you don't need any of this — a single .java file in any folder is enough to get started.
Configure JAVA_HOME and the PATH
If your IDE can find java and javac from the menus, you don't need to touch environment variables. But the moment you switch to the terminal — or use Maven, Gradle, Spring Boot, or any command-line tool — they need JAVA_HOME set.
See How to Install Java (JDK) for the platform-specific snippets, or use a version manager like SDKMAN! which sets JAVA_HOME per shell automatically.
Useful keyboard shortcuts
The few shortcuts you'll use constantly in IntelliJ:
- Run — Shift+F10 (Win/Linux) / Control+R (macOS)
- Debug — Shift+F9 / Control+D
- Format file — Ctrl+Alt+L / Cmd+Option+L
- Quick fix — Alt+Enter / Option+Return
- Find anywhere — Shift Shift (double tap)
- Rename symbol — Shift+F6
VS Code and Eclipse have equivalents under their respective Keymap menus.
What's next
You're ready to write code. The Java Hello World Program walks through a complete first program line by line, and How to Compile and Run a Java Program shows what happens under the hood when your IDE clicks Run.
Practice
Which directory does the conventional Java project layout use for production source files?