English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Kotlin Setup in IntelliJ IDEA Environment

This tutorial will demonstrate how to install and set up the Kotlin development environment in IntelliJ IDEA, and create a simple Kotlin Hello World application.

    Set up the environment

1In this tutorial, we will use IntelliJ IDEA. For instructions on how to compile and execute Kotlin applications using the command line compiler, please refer toUse the command line compiler.

  Install the latest version of IntelliJ IDEA. Kotlin version from2015has been bundled with IntelliJ IDEA since the beginning of the year. From the JetBrains official website ( http://www.jetbrains.com/idea/download/index.html ) Download the free community version.

2After installing IntelliJ IDEA, open it and create a new project. Select the menu: [File]-> [New Project], Java Module and select SDK, Kotlin should be with JDK 1.6+Use them together. Additionally, select the Kotlin (Java) checkbox.

3Enter the project name: HelloWorld, click Finish (Finish) as shown in the figure below -

4The folder structure of the newly created project is as follows -

5Create a new Kotlin file under the src folder and name it: app.kt.

6After creating the file, you need to write the main program (main), which is the entry point of the Kotlin application. IntelliJ IDEA provides a template to quickly complete this operation. Just type 'main' and press the tab key to automatically complete.

Now add a line of code to print out "Hello, World!".

/**
 * Created by w3codebox on 2019/8/10.
 *
 * @copyright oldtoolbag.com
 */
fun main(args: Array<String>) {
    println("Hello, World!");
{}

7Now we can run the application. The simplest way is to click the Kotlin icon in the Kotlin menu or right-click in the code and select [Run 'AppKt'] from the pop-up menu.

 8If everything goes well, you should see the result in the Run Tool window as follows:

    Congratulations! The first Kotlin application has run successfully.