0Pricing
Kotlin Academy · Lesson

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 reassigned

All lessons in this course

  1. Setting Up Kotlin: REPL, IntelliJ & Online Playground
  2. val vs var: Immutability From Day One
  3. Kotlin Basic Types: Int, Double, Boolean, Char
  4. Your First Kotlin Program: main, println & Input
← Back to Kotlin Academy