How to print Hello World in Kotlin in IntelliJ-Idea

Kotlin program to print hello world:

For any programming language, the first program we learn is how to print the hello world string. You can use any IDE to write this program. This is a simple program that will print the “Hello World” string on the console. I will show you how to write it with IntelliJ-Idea in this post.

1. Create a new project:

Download IntelliJ-Idea from jetbrains website and also make sure that Kotlin is installed on your system. I am not going into detail about the installation process as it is different for different operating systems.

Open IntelliJ-Idea and click on File→New→Project. It will show you a list of inputs.

Android studio create new project

  • Enter the Name of the project. You can give any name.
  • Choose the location to create the project. You can also tick the Create Git Repository checkbox to make the project folder also a git repository.
  • Select the Language as Kotlin.
  • Select the build system, I am choosing Gradle for this example.
  • Select the JDK and Gradle DSL.
  • The last two settings are used to add a GroupId for the project and an ArtifactId.

Click on Create to create the project.

2. Create a Kotlin file to write the program:

Once the project is created, it will start the project. The src/main/kotlin folder will be empty when it is started. To create a new Kotlin file to write the program, right click on the folder → Select new → Select Kotlin Class/File.

Android studio create kotlin file

Enter a name for the file and select File from the dropdown options. We can create different types of files like class, interface, data class etc. In this example, we are creating a File and the name of the file is ExampleTest.

Android studio create class file

3. Write the Hello World program:

It will create a new file ExampleTest.kt. Open the file and write the below program in that file:

fun main(args: Array<String>) {
    println("Hello World!!")

We added a main function with a statement to print the Hello World!! string. The main function is the entry point of the program.

4. Run the program:

To run the program, click on the run icon in the gutter and click on Run ‘ExampleTestKt’.

Android studio run program

It will build and run the program and the output will be displayed in a run tool window.

Android studio output

You can also press ⌃ ⇧ R or the run button on the top right corner of the window to run the project.

Android studio run program play button

You might also like: