Hello World Program in Kotlin
The "Hello World" program is the most basic program you can write. It simply displays the text "Hello, World!" on the screen. Let’s break it down step by step.
fun main() {
println("Hello, World!")
}
Code Breakdown
fun: This keyword is used to define a function in Kotlin. In this case, we are creating a function namedmain(). This is the starting point of any Kotlin program.main(): The main function is where your Kotlin program begins execution. Every Kotlin program must have amain()function.println(): This is a built-in function in Kotlin that prints whatever is inside the parentheses to the screen. Here, it’s printing the string"Hello, World!"."Hello, World!": This is the string that will be printed. In Kotlin, anything inside double quotes is considered a string.
In simple words
- We start by creating a
main()function (which is necessary for the program to run). - Then we use
println()to print the text"Hello, World!"on the screen.
How to Run the Program
- Open IntelliJ IDEA or any Kotlin compiler.
- Type the code in your Kotlin file.
- Run the program, and you will see the output:
Hello, World!on the screen.
