val vs var?
val is a read-only (immutable) reference; var is mutable. Prefer val by default; reassign only when needed.
val x = 5 // immutable
var y = 5 // mutable
y = 10
// x = 10 // compile error
Languages · 10 sections
Null-safety, coroutines, and concise syntax — the modern JVM language behind Android and server-side Kotlin.
val is a read-only (immutable) reference; var is mutable. Prefer val by default; reassign only when needed.
val x = 5 // immutable
var y = 5 // mutable
y = 10
// x = 10 // compile error
Kotlin infers types from initializers; you can omit types when unambiguous. Public APIs often declare types explicitly for clarity.
val name = "Kotlin" // String
val count = 42 // Int
fun add(a: Int, b: Int) = a + b // returns Int
T is non-null by default; T? is nullable. The compiler enforces null checks, preventing NPEs from declared non-null values.
var s: String = "hi" // non-null
var n: String? = null // nullable
// s = null // compile error
111 more cards in this sheet
Unlock the Languages bundle — ₹399
One-time payment. Unlocks this sheet and 7 other sheets in the bundle, plus a typeset PDF of each.
Unlock the bundle See all bundles
Or get all 76 sheets for ₹999 — one payment, every future sheet included.
What's new and the interview questions people are actually getting asked. No spam.