Category: JVM Languages

To write Kotlin program you will need an IDE (Integrated Development Environment). One of the IDE that you can use is the IntelliJ IDEA CE (Community Edition). It comes with Kotlin Java Runtime Library so you don’t need to install it separately.

To run it, right click on the editor and choose the Run HelloKotlinKt from the menu.

If you want to run it with an argument you can set it in the Run/Debug Configurations dialog.

To open the Run/Debug Configurations click the down-arrow button next to HelloKotlinKt in the navigation bar on the top-right and choose Edit Configurations…

Type in the arguments in the Program arguments textbox.

Run/Debug Configurations

That’s all. Now you have your JDK, IntelliJ IDEA CE installed and created your first Kotlin program. If you have any questions please post it in the comments section below. Thank you and have fun with Kotlin.

In Kotlin, the HelloWorld.kt program can be written as a simple function like the following snippet.

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

From this little code snippet we can learn the following features of the Kotlin programming language:

Kotlin program saved in a file with .kt extension.

The fun keyword to declare a function to show you that programming can be fun again 😉

To declare variables we start with the variable name followed by its type separated by a colon.

We don’t have to end a statement with a semicolons.

To print we can use the println function, which is a wrapper to Java System.out.println.

The main function is the execution entry point of our HelloWorld program.

We can create functions at the top level file without creating a class.

To compile the HelloWorld.kt program we run the following command:

kotlinc HelloWorld.kt

The compiler creates a class file called HelloWorldKt.class. To run it type the following command, assumed that you’ve setup the $KOTLIN_LIB environment variable. In my case the variable is set to /usr/local/Cellar/kotlin/1.2.40/libexec/lib.

java -cp $KOTLIN_LIB/kotlin-stdlib.jar:. HelloWorldKt

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy