> ## Content Index
> Fetch the complete content index at: https://www.ggorantala.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# Creating Your First Java Application With IntelliJ IDEA
- URL: https://www.ggorantala.dev/creating-your-first-java-applications/
- Published: 2023-04-22T13:10:00.000Z
- Updated: 2023-04-22T13:44:48.000Z
- Description: Creating a Java application is easy using the IntelliJ IDEA IDE tool.
- Author: Gopi Gorantala
- Tags: IntelliJ IDEA

In this article, we will create, run, and package a simple Java application that prints "Hello, world!" to the system output.

## Getting started with IntelliJ IDEA

We will use IntelliJ IDEA IDE for creating our first Java application. We will also see IntelliJ IDEA features for boosting your productivity, for example, coding assistance and supplementary tools.

Install the [IntelliJ IDEA community/ultimate](https://jb.gg/student-referral-Gopi-Gorantala) version, both support the features we're talking about.

## How to create a new project?

Click on "New Project" on the IntelliJ IDEA as shown below.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/IntelliJ-IDEA-New-Project.png)

Select "Empty Project" from the left sidebar. On the right screen, choose a name for your project, I chose "Hello World" and chose a location. Once finished, click on the "Create" button to create the project.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Java-empty-project.png)

After the project is created, you see an IntelliJ IDEA project window as follows. The left bar is the project window that shows us all the directories and files that make up our project. You can use the mouse or arrow keys to navigate around the project window. 

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/project-window-1.png)

## How to create your first Java class

Let us create our first class for our example application. `Package` (packages) are used to group together classes that belong to the same category or provide similar functionality, and are useful for organizing large applications with hundreds of classes.

To create a new class, press `Cmd + N` on macOS or `Alt+Insert` on Windows or Linux on the src directory, and select "Java class".

But if we want to create a new class in a particular package, we can type the whole `package` path, separated by dots, followed by the class name.

IntelliJ IDEA can create a number of different types of class files, such as `Interface`, `Record`, `Enum`, and `Annotation`.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/java-class.png)

We see that IntelliJ IDEA created the package we wanted under the correct directory structure.

Type `main` inside the class, and IntelliJ IDEA suggests a method, press the key enter to generate the code for us with the correct parameters.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/intellij-main-method.png)

After the code is generated, you will see something like this.

```java
package src.com.example.helloworld;

public class HelloWorld {
    public static void main(String[] args) {

    }
}

```

Inside the `main` method press `Cmd+j` or `Ctrl+j` in Windows to see the list of live templates that are valid for the current context.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Screenshot-2023-04-22-at-17.25.55.png)

Let's call a method to print something on the console.

If we type `Sy`, we see a dropdown of likely classes we might want to call. We want, the first one, and it's already highlighted.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Screenshot-2023-04-22-at-17.28.07.png)

If we press the dot next to `System`, IntelliJ IDEA will bring up the next suggestion. Typing `o` will list accessible fields and methods in the `System` class that begins with `o`, `out` is the one we want to insert another dot again and code completion shows the most likely methods.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Screenshot-2023-04-22-at-17.51.00.png)

choose `println()` and press enter to select it.

There are a number of `println` methods, and they all take different types of parameters. IntelliJ Idea shows the different parameter types available to us, which can be useful.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Screenshot-2023-04-22-at-17.53.39.png)

Type a double quote, we should notice several things; first, the editor automatically inserts a closing quote. Second, it highlights the String parameter for our method, so we can see this is a valid type for the method.

Use escape to hide the pop-up.

Now, let's type `Hello, world!`. 

```java
package src.com.example.helloworld;

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

If this is your first time programming in Java, congratulations! You've just created your first Java application. 

## How to run a Java application on IntelliJ IDEA?

Java files like this one can be compiled into bytecode and run. IntelliJ IDEA can do all of this for you. 

We can run classes with a main method either from the green run icon at the class level or from the run icon in the gutter next to the main method itself.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Screenshot-2023-04-22-at-18.00.40.png)

We can see there's more than one way to run an application, for example, we could debug it. But for this lesson, we're going to run it in the simplest way.

Hit the green icon to run the application. IntelliJ IDEA compiles the file into a class file, then runs it and shows the output in the Run window at the bottom.

![](https://storage.ghost.io/c/e3/0b/e30b8112-16a4-4a70-8441-b0c5d5f2b4d7/content/images/2023/04/Hello-World--output.png)

The second line in this output of our program is "Hello, world!".

IntelliJ IDEA compiled the `HelloWorld.java` file into a class file. 

## Sketch of files and folders

By default, the IDE creates a folder called *out/production* as shown below sketch.

```java
HelloWorld
|
+--- .idea
|
+--- out
|    |
|    +--- production
|          |    
|          +--- HelloWorld
|		   |
|          +--- src.com.example.helloworld
|                |
|                +--- HelloWorld.class
|
+--- src.com.example.helloworld
     |
     +--- HelloWorld.java
```

This sketch completes our first Java program.