Hello world in Kotlin

  • Create a new project as specified in the previous post.
  • Right-click on src folder and select New->Kotlin File/Class.

2018-06-24 14_25_23-KotlineDemo [C__Users_Pravin_IdeaProjects_KotlineDemo] - IntelliJ IDEA

  • In the dialog box, specify the name of the file and click on OK.

2018-06-24 14_26_06-KotlineDemo [C__Users_Pravin_IdeaProjects_KotlineDemo] - IntelliJ IDEA

  • Type the following code:

fun main(args: Array<String>)
{
println(“hello, Kotlin!”)
}

  • From the top menu bar, click on the Run->Run… . A list of configurations will appear. Note that the IDE has already created a configuration for us.

2018-06-24 15_09_54-KotlineDemo [C__Users_Pravin_IdeaProjects_KotlineDemo] - ..._src_hello.kt [Kotli

  • Choose the HelloKt (which is the name of the Kotlin file).
  • The output should appear in the bottom pane.

2018-06-24 14_28_22-KotlineDemo [C__Users_Pravin_IdeaProjects_KotlineDemo] - ..._src_hello.kt [Kotli

  • Note that the project structure will show an Out directory containing the generated class file.

2018-06-24 15_18_25-KotlineDemo [C__Users_Pravin_IdeaProjects_KotlineDemo] - ..._src_hello.kt [Kotli

Leave a comment