Codectionary / Developer documentation / Java

Create a Java project in IntelliJ IDEA, select a JDK, run Main and debug a simple program.

What IntelliJ IDEA is

IntelliJ IDEA is a Java-focused integrated development environment (IDE). It combines an editor, project tools, code analysis, run configurations and a debugger. It still needs a suitable JDK to compile and run your Java project. IntelliJ IDEA is distinct from VS Code, which is an editor extended with Java tooling.

JetBrains now provides a unified IntelliJ IDEA distribution with free core functionality and paid advanced features. Check the current licence for the features and use case you need; do not assume every feature is free.

Install IntelliJ IDEA and select a JDK

Get IntelliJ IDEA from JetBrains and follow its installer for your operating system. On the Welcome screen choose New Project, select Java, name the project and choose a location. For a beginner project, the IntelliJ build system is sufficient; Maven or Gradle is useful later when a project needs dependency and build management.

In the New Project window, select an installed JDK, use Add JDK from Disk, or use Download JDK. Pick a maintained release compatible with your course or project. JetBrains’ current first-app tutorial may offer a compact source file; this guide uses a conventional class so you can see the standard main method and also run the file outside the IDE.

Create and run a Java class

In the Project tool window, create a Java class named Main under the source folder. Replace any generated content with the example below. Use the green Run control beside main, or right-click the class and choose Run. The Run tool window should show Hello, Codectionary! followed by a successful process exit.

If you use the terminal outside IntelliJ instead, save Main.java and run javac Main.java followed by java Main. An IDE can build files for you, but understanding these two commands helps explain compiler and runtime errors.

Main.java

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}

Terminal alternative

javac Main.java
java Main

Inspect a program with the debugger

Click the gutter beside the print line to add a breakpoint, then choose Debug instead of Run. Execution pauses before the statement. The Debug tool window shows the current line, frames and variables; step to the next line or continue. Add a local message variable and watch its value so the exercise teaches more than a single paused line.

An editor highlight or a successful build does not prove your program behaves correctly. Run it, inspect output and test changed inputs.

Project JDK and build problems

If IntelliJ cannot run the class, check Project SDK/JDK, confirm Main.java is in a source folder and read the first compiler error. If terminal commands use a different JDK from the IDE, compare java -version and javac -version with the project’s selected JDK. If a file uses newer syntax than the configured language level, align the project setting with the installed supported JDK or use syntax supported by that project.

For a first project, stay with the small class-based program. Add build tools and external libraries only when a project actually needs them.

Syntax

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}

Examples

Run a conventional Java class in IntelliJ IDEA

Use the Run gutter action, then try a breakpoint on the print line.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}
  1. The project contains Main.java with a public Main class.
  2. The IDE uses its selected JDK to compile and start the main method.
  3. System.out.println sends the greeting to the Run window. A breakpoint pauses before it executes.

Best practices

  • Set the project JDK deliberately, especially if several JDKs are installed.
  • Use the free core features before deciding whether paid IDE features are necessary.
  • Read the first compiler diagnostic and test the running program after edits.

Runtime & versions

Java Virtual Machine. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Java Language Specification

Specifications & further reading