Line At A Time
Lesson 3: Strings
Strings Store text in a String and print it.
1fun main() {
2 val hello = "Hello World!"
3 println(hello)
4}
Terminal
$ kotlinc Main.kt -include-runtime -d Main.jar
$ java -jar Main.jar
Hello World!
Every line, explained
fun main() {
Every Kotlin program starts at the main function. When you run the program, Kotlin looks for fun main() and runs everything between its { and } from top to bottom.
val hello = "Hello World!"
A String is a piece of text. In Kotlin text always goes inside double quotes: "like this". Single quotes are only for one single character (like 'A'), so writing 'Hello' would be an error.
println(hello)
println(...) prints whatever is inside the round brackets to the terminal, then moves to a new line. All lowercase, and no semicolon at the end; Kotlin does not need them.
}
This closing curly brace } ends the main function. In Kotlin every opening brace { must have a matching closing brace }.