Kotlin Basics
Use values and string templates.
On this page
The concept
val creates a read-only reference. main is the program entry point. A string template inserts the current value into text.
Code example
Kotlin
fun main() {
val name = "Ada"
println("Hello, $name")
}Output
Hello, Ada
Follow the code
Open the walkthrough to inspect the example one step at a time.
Show guided walkthrough
Guided walkthroughReady
1
fun main() {2
val name = "Ada"3
println("Hello, $name")4
}Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| Bind Ada to a read-only name. | name = "Ada" | — | |
| Insert name into the string template and print. | name = "Ada" | Hello, Ada |
Behind the scenes
How Kotlin processes this code
Kotlin commonly compiles to JVM bytecode, which the JVM executes.