Kotlin Getting started with Kotlin Hello World

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

All Kotlin programs start at the main function. Here is an example of a simple Kotlin "Hello World" program:

package my.program

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

Place the above code into a file named Main.kt (this filename is entirely arbitrary)

When targeting the JVM, the function will be compiled as a static method in a class with a name derived from the filename. In the above example, the main class to run would be my.program.MainKt.

To change the name of the class that contains top-level functions for a particular file, place the following annotation at the top of the file above the package statement:

@file:JvmName("MyApp")

In this example, the main class to run would now be my.program.MyApp.

See also:



Got any Kotlin Question?