Running your first Kotlin program

Now that we have our command-line compiler set up, let's try it out with a simple Kotlin program. Navigate to your home directory and create a new file named Hello.kt. All Kotlin files have a .kt extension appended to the end of the filename.

Open the file you just created in a text editor of your choosing and input the following:

// The following program prints Hello world to the standard system output.fun main (args: Array<String>) {  println("Hello world!")}

Save the changes made to the program file. After the changes have been saved, open your terminal window and input the following command:

kotlinc hello.kt -include-runtime -d hello.jar

The preceding command compiles your program into an executable, ...

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.