IntelliJ IDEA 2025.3 Help

Create your first Java application

In this tutorial, you will learn how to create, run, and package a simple Java application that prints Hello World to the system output.

You will get acquainted with compact source files from Java 25 and learn how to convert them to regular classes. Along the way, you will become familiar with IntelliJ IDEA features for boosting your productivity as a developer: coding assistance and supplementary tools.

For this tutorial, you only need basic knowledge of Java and familiarity with IntelliJ IDEA.

Create a new Java project

In IntelliJ IDEA, a project helps you organize your source code, tests, libraries that you use, build instructions, and your personal settings in a single unit.

  1. Launch IntelliJ IDEA.

    If the Welcome screen opens, click New Project.

    Otherwise, go to File | New Project in the main menu.

  2. In the New Project wizard, select Java from the list on the left.

  3. Name the project (for example HelloWorld) and change the default location if necessary.

  4. Leave the Create Git repository option disabled as we are not going to work with version control systems in this tutorial.

  5. Make sure that IntelliJ is selected in Build system.

    Creating a new Java project
  6. To develop Java applications in IntelliJ IDEA, you need a Java SDK (JDK).

    In this tutorial, we need Java 25 or higher. If it is already defined in IntelliJ IDEA, select it from the JDK list.

    If the JDK is installed on your computer, but not defined in the IDE, select Add JDK from Disk and specify the path to the JDK home directory (for example, /Library/Java/JavaVirtualMachines/openjdk-25.0.1).

    Creating the new project and adding the JDK

    If you do not have the necessary JDK on your computer, select Download JDK. In the next dialog, select version 25 (for example, Oracle OpenJDK 25), change the installation path if required, and click Select.

    Downloading a JDK when creating a project
  7. Leave the Add sample code option disabled as we are going to do everything from scratch in this tutorial. Click Create.

After that, the IDE will create and load the new project for you.

Once the project is loaded, the project window opens. On the left, you will see the Project tool window. It displays the structure of your application and helps you browse the project files. To open the tool window, press Alt+1 or go to View | Tool Windows | Project in the main menu.

Project window

Write the code

Let's start by creating a compact source file. Java compact source files look different from usual Java classes. They do not have a class declaration, and the public class boilerplate is also not required. They are useful for smaller code samples and tutorials.

Create a compact source file

  1. In the Project tool window, make sure the src folder is selected.

  2. Click on the tool window toolbar (or press Alt+Insert) and select Java Compact File.

    Creating Java compact source file
  3. Name the file HelloWorld and press Enter.

Together with the file, IntelliJ IDEA has automatically generated a method declaration. This is done by means of file templates. Depending on the type of the file that you create, the IDE inserts initial code and formatting that is expected to be in all files of that type. For more information about how to use and configure templates, refer to File templates.

Java compact source file

Call the println() method using code completion

IntelliJ IDEA automatically places the caret at the next line after the main() method declaration. Let's call a method that prints some text to the standard system output.

  1. Type IO and press Ctrl+. to insert the selection with a trailing period.

  2. From the completion list that opens, select the println method and press Enter.

  3. Type ". The second quotation mark is inserted automatically, and the caret is placed between the quotation marks. Type Hello World.

Code completion analyzes the context around the current caret position and provides suggestions as you type. You can open the completion list manually by pressing Ctrl+Space.

For more information about different completion modes, refer to Code completion.

Call the println() method using a live template

You can call the println() method much quicker using the iop live template.

  1. Type iop and press Enter.

  2. Type ". The second quotation mark is inserted automatically, and the caret is placed between the quotation marks. Type Hello World.

    Alternatively, if completion suggests finishing the line for you, press Tab to accept the suggestion.

Build and run the application

Valid Java classes and compact source files can be compiled into bytecode. You can compile and run files with the main() method right from the editor using the green arrow icon the Run button in the gutter.

  1. Click the Run button in the gutter and select Run 'HelloWorld.main()' in the popup. The IDE starts compiling your code.

  2. When the compilation is complete, the Run tool window opens at the bottom of the screen.

    The first line shows the command that IntelliJ IDEA used to run the compiled class. The second line shows the program output: Hello World. And the last line shows the exit code 0, which indicates that the program exited successfully.

    If your code is not correct and the IDE cannot compile it, the Run tool window will display the corresponding error.

When you click Run, IntelliJ IDEA creates a special run configuration that performs a series of actions. First, it builds your application. At this stage, javac compiles your source code into JVM bytecode.

Once javac finishes compilation, it places the compiled bytecode to the out directory, which is highlighted with yellow in the Project tool window.

After that, the JVM runs the bytecode.

IntelliJ IDEA automatically analyzes the file that is currently opened in the editor and searches for different types of problems: from syntax errors to typos. The Inspections widget in the top-right corner of the editor allows you to quickly see all the detected problems and look at each problem in detail. For more information, refer to Current file.

Convert the compact source file into a regular class

A compact file is a minimal, single-file Java program. It is typically used for demos, tutorials, or small scripts. Compact files are defined outside of packages. However, in production projects, it is recommended that you place Java classes inside packages. To follow this practice, you can convert the compact file into a regular Java class and move it into a package.

Convert the file using a context action

  1. In the editor, place the caret at void main() and press Alt+Enter.

  2. Select Convert into a regular class.

    Converting compact file using a context action

Move the class into a package

  1. In the Project tool window, right-click the scr folder and select New | Package.

  2. Name the new package com.example.helloworld.

  3. In the Project tool window, drag the HelloWorld class into the newly created package.

    IntelliJ IDEA invokes the Move refactoring and shows you a confirmation dialog.

  4. Click Refactor. The class is now located within the package. The package declaration appears at the top of your class as a result of the refactoring.

Refactoring is a process of improving your source code without creating a new functionality. Learn more from Code refactoring.

Package the application in a JAR

When the code is ready, you can package your application in a Java archive (JAR) so that you can share it with other developers. A built Java archive is called an artifact.

Create an artifact configuration for the JAR

  1. In the main menu, go to File | Project Structure (Ctrl+Alt+Shift+S) and click Artifacts.

  2. Click the Add button, point to JAR and select From modules with dependencies.

  3. To the right of the Main Class field, click the Browse button and select HelloWorld (com.example.helloworld) in the dialog that opens.

    IntelliJ IDEA creates the artifact configuration and shows its settings in the right part of the Project Structure dialog.

  4. Apply the changes and close the dialog.

In the Project tool window, you can now see the MANIFEST.MF file. This file has metadata about your JAR, such as the main class to run.

Manifest file

Build the JAR artifact

  1. In the main menu, go to Build | Build Artifacts.

  2. Point to HelloWorld:jar and select Build.

    Building an artifact

    If you now look at the out/artifacts folder, you'll find your JAR there.

    The JAR artifact is built

Run the packaged application

To make sure that the JAR artifact is created correctly, you can run it.

Create a run configuration for the packaged application

To run a Java application packaged in a JAR, IntelliJ IDEA allows you to create a dedicated run configuration.

  1. Press Ctrl+Shift+A, find and run the Edit Configurations action.

  2. In the Run/Debug Configurations dialog, click the Add button and select JAR Application.

  3. Name the new configuration: HelloWorldJar.

  4. In the Path to JAR field, click the Browse button and specify the path to the JAR file on your computer.

  5. Scroll down the dialog and under Before launch, click the Add button, select Build Artifacts | HelloWorld:jar.

    Doing this means that the HelloWorld.jar is built automatically every time you execute this run configuration.

Run configurations allow you to define how you want to run your application, with which arguments and options. You can have multiple run configurations for the same application, each with its own settings.

Execute the run configuration

  • On the toolbar, select the HelloWorldJar configuration and click the Run button to the right of the run configuration widget. Alternatively, press Shift+F10 if you prefer shortcuts.

    As before, the Run tool window opens and shows you the application output.

The process has exited successfully, which means that the application is packaged correctly.

Summary

In this tutorial, you have learned how to:

  • Create a Java project from scratch

  • Create files and packages

  • Run applications in IntelliJ IDEA

  • Create run configurations

  • Package applications in JAR

  • Run packaged applications

Next steps

Learn how to complete other tasks in IntelliJ IDEA from these tutorials:

For a full list of available tutorials, refer to IntelliJ IDEA tutorials.

06 January 2026