Hello World with IntelliJ IDEA

The first thing that appears when you start IntelliJ IDEA is the welcome screen. There you have the possibility to open an existing project. This can be done via importing an existing project from your filesystem or from a remote repository. In our case we are starting a new project.

IntelliJ IDEA New Project

After you have selected to create a new project, you can choose between different types of projects. Select a Kotlin project for JVM (Java Virtual Machine) and click Next.

IntelliJ IDEA Kotlin Project

Now you can define some properties for your project. This includes the project name (“HelloWorld“) and the project location. Aswell you can select the Java SDK (Software Development Kit) on which your Kotlin project will be based.

IntelliJ IDEA Hello World Project

What happens if you don’t have yet installed a Java Runtime Environment (JDK)? In this case IntelliJ IDEA is showing you that you don’t have a SDK and you need to install a JDK. This is the case because you have selected a Kotlin Project for JVM. Checkout the following link to install your JDK.

IntelliJ IDEA no jdk

Once you have installed a JDK, IntelliJ IDEA is usually able to recognize it in your file system. Just select the folder with the JDK version you like to use.

IntelliJ IDEA select JDK

Add a new file

The empty project is now created and you need to add now a new Kotlin file to your source folder. For that right-click on src and select New – Kotlin File/Class. Give it a name and create the file (in this case the name is HelloWorld). Alternatively you can select the src Folder. Make sure that the folder is selected by checking the path:

IntelliJ IDEA selected path

Now click on the File tab and select New – Kotlin File / Class. The new file should be placed in the src folder.

IntelliJ IDEA HelloWorld file

Add main function

Now you have your first Kotlin file and you have to add a main function to make the program executable. For that add the following code to the HelloWorld.kt file.

fun main(args: Array<String>) {
    println("Hello from Kotlin-Code")

Run your HelloWorld programm

IntelliJ IDEA automatically recognizes the new main function. Just click on the green arrow next to your main function to run your programm. An alternative way to run the main function is to select it from the configuration manager on top right. After you have run a programm for the first time you can trigger it again with the green arrow on the bottom left. You will see the output of your programm in the terminal at the bottom.

IntelliJ IDEA Kotlin Main function
Run your program with the green arrow
IntelliJ IDEA run configuration
Select a configuration and run it with the green arrow
IntelliJ IDEA Execute Hello World
Rerun the last configuration

Congratulations, you have just run your first Kotlin program in IntelliJ IDEA.