Hello World in Kotlin

Kotlin programming language is becoming the most famous language because Google has announced it as the official android language. Now you can write Android applications in the kotlin too in easy way. So before writing android app in kotlin you have to learn it. Here is just a simple Hello world example in the kotlin which will give a little start. If you are already Java programmer then you can learn it easily because it is the alternative of Java.

You have to setup the kotlin first in your computer as you setup the java. If you didn’t setup the kotlin environment you can go here to setup the kotlin to get started with kotlin.

As in the java you have to write a main class to create a simple hello world program but in kotlin you can write it without any class. You can write or start hello world program in kotlin without any class. Copy the below code and run it using any method using the command line or by using the intellij idea.

Now let me explain the above code.

fun  is the keyword to declare the function and kotlin also start it’s execution from the main function as the Java

In the kotlin you also need the String array parameters as in the Java. Are you confused how the parameters are the declared? Let me give you a little quick start about the parameters declaration in kotlin. In kotlin you can declare the parameters by the following syntax.

nameOfTheVariable : DataType

So as in the main method you have declared args named parameter of String Array type. Now where is the return type? main method return nothing so it is optional to give return type. If you want to write the return type of the method you can write as the follow.

Unit mean void but it is not totally like the void(Don’t be confused you can consider it as void). If you are returning nothing you can give return type Unit which is like void return type in Java. You can also skip it because it is optional.

Now the next line println("Hello World in Kotlin from Ktutorials.com")is the method/function to print the line.

Now paste the code in your favorite environment as I have discussed getting started kotlin with Intellij Idea and compile and run kotlin in command line to test it.