The most common first program that programmers write to test a programming language is the Hello, World! program. It is a full program that just displays Hello, World! as text on the console. We are also going to start with this program, because in Kotlin it is based on a function and only on a function (no class is needed). So the Kotlin Hello, World! program looks as follows:
// SomeFile.kt fun main(args: Array<String>) { // 1 println("Hello, World!") // 2, Prints: Hello, World! }
- A function defines a single parameter, args, which contains an array of all arguments used to run the program (from the command line). It is defined as non-nullable, because an empty array is passed to a method when the program is started without any arguments.
- The println function is a Kotlin function...