Hello World program in Kotlin (original) (raw)
Last Updated : 04 May, 2025
**Hello, World! It is the first basic program in any programming language. Let's write the first program in the Kotlin programming language.
**The "Hello, World!" program in Kotlin:
Open your favorite editor, **Notepad or Notepad++, and create a file named **firstapp.kt with the following code.
// Kotlin Hello World Program
fun main(args: Array) {
println("Hello, World!")
}
You can compile the program with the command-line compiler.
$ kotlinc firstapp.kt
Now, run the program to see the output in a command-line compiler.
$kotlin firstapp.kt
Hello, World!
**Note: You can run the program in _Intellij IDEA as shown in the Setting up the environment article.
Details about the "Hello, World!" program:
**Line #1:
The first line is a comment that is ignored by the compiler. Comments are added to the program to make the source code easy to read and understand by the readers.
Kotlin supports two types of comments as follows:
1. **Single line comment
// single line comment
2. **Multiple line comment
/* This is
multi line
comment
*/
**Line #2:
The second line defines the main function.
fun main(args: Array) {
// ...
}
The main() function is the entry point of every program. All functions in Kotlin start fun keyword followed by the name of the function(here main is the name), a list of parameters, an optional return type, and the body of the function ( { ……. } ).
In this case, main function contains the argument – an array of strings and return units. Unit type corresponds to void in java means the function does not return any value.
**Line #3:
The third line is a statement and it prints "**Hello, World!" to print the output of the program.
println("Hello, World!")
Semicolons are optional in Kotlin, just like other modern programming languages.