Hello World Program in Kotlin

In the last tutorial, we learned about how to set up the environment for Kotlin and how to start new Kotlin project in Eclipse. In this tutorial, we will learn how to write Hello World program in Kotlin. Before going further it is important to mention that we save Kotlin program files with extension .kt. If you want to save you program file with HelloWorld name you have to save it as HelloWorld.kt. Let’s check out code of our first Kotlin program.

      fun main (args: Array<String>){
           println(“Hello World”)

To run this code you can use play button which is available in the toolbar or click on Run in the menu bar then Run As option. You will get the output of this program in the console.

Hello World code Explanation:

  • fun: In our code, you can see we started from fun. fun is a keyword in kotlin to define the function after writing fun we write function name.
  • main(): The main function is Kotlin is same as main() in java and c. From where the execution of the program starts. In Kotlin main function take an array of string as a parameter.
  • println(): The println() is a function which is used to print a string on the screen. We write a string in println() function in double-quotes.
Spread the love
Scroll to Top