val vs var: Immutability From Day One
Understand the difference between val and var and why immutability matters.
Two Ways to Declare a Variable
Kotlin has two keywords for declaring variables: val for read-only (immutable) references, and var for mutable ones. Choosing correctly matters.
val: Read-Only Reference
val declares a reference that cannot be reassigned after initialization. Think of it like final in Java.
val name = "Kotlin"
println(name)
// name = "Java" // Error: Val cannot be reassignedAll lessons in this course
- Setting Up Kotlin: REPL, IntelliJ & Online Playground
- val vs var: Immutability From Day One
- Kotlin Basic Types: Int, Double, Boolean, Char
- Your First Kotlin Program: main, println & Input