Summary - Kotlin basics
- Kotlin course
- Beginner
- Lesson 6/116
- 5 min
Combine main, println and comments to write your first Kotlin program.
Summary - Kotlin basics
So far you've learned the structure of a Kotlin program, writing to the screen, comments and string templates. A Kotlin program starts with fun main(), writes with println(...), adds comments with // and /* */, and embeds variables in strings with $.
These concepts will be the foundation for all following lessons. Let's combine them in a short exercise.
Practice Put it together
Write a fun main(). Inside it, in order: a single-line comment, val name = "Alex", and println("Hello $name").
Sample solution
fun main() {
// start
val name = "Alex"
println("Hello $name")
}Expected output
Hello Alex
Next step
Congratulations! You've completed the Kotlin basics. In the next group you'll dig into variables: the difference between val and var, type inference, const, lateinit and by lazy.
Each lesson adds a new concept with a short exercise. You'll practice declaring variables, annotating types and assigning values. Ready? Let's go.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is Kotlin's program entry point?
- fun start
- fun main Correct answer
- fun run
- fun begin
Explanation: fun main is the entry point of a Kotlin program.
2 Match the concepts
| Term | Meaning |
|---|---|
fun |
Function |
println |
|
// |
Comment |
$ |
Template |
3 Summary - Kotlin basics: fill in the missing part
val name = "Alex"
println("Hello $____")
val name = "Alex"
println("Hello $name")
Explanation: You embedded the variable with $name.