Kotlin Cheat Sheet
Kotlin syntax, null safety, data classes, coroutines, and extension functions for concise, safe JVM development.
2 PagesIntermediateMar 30, 2026
Basic Syntax
Variables, control flow, and printing.
kotlin
fun main() { val age = 30 // immutable (val) var count = 0 // mutable (var) val name = "Ada" val pi: Double = 3.14159 if (age >= 18) { println("$name is an adult") } for (i in 0 until 5) { println("Count: $i") }}
Null Safety & Data Classes
Compile-time null checks and value objects.
kotlin
data class User(val name: String, val age: Int)fun greet(user: User?) { val name = user?.name ?: "Guest" // safe call + Elvis operator println("Hello, $name")}val user: User? = User("Ada", 30)user?.let { println(it.age) } // scope function, runs if non-nullval u2 = user!! // force-unwrap (throws if null)
Coroutines
Lightweight concurrency with suspend functions.
kotlin
import kotlinx.coroutines.*suspend fun fetchData(): String { delay(1000) // non-blocking suspension return "data"}fun main() = runBlocking { val job = launch { val result = fetchData() println(result) } job.join() val deferred = async { fetchData() } println(deferred.await())}
Core Keywords
Common Kotlin language keywords.
- val/var- read-only and mutable variable declarations
- ?./?:- safe call operator and Elvis (null-coalescing) operator
- data class- auto-generates equals(), hashCode(), toString(), copy()
- sealed class- restricted class hierarchy known at compile time
- when- expressive replacement for switch statements
- extension function- adds a function to an existing type without inheritance
- suspend- marks a function as coroutine-suspendable
- companion object- holds members shared across all instances (like static)
Pro Tip
Use `data class` with `copy()` for immutable state updates instead of mutating fields directly — it keeps state predictable in concurrent code.
Was this cheat sheet helpful?
Explore Topics
#Kotlin#KotlinCheatSheet#Programming#Intermediate#BasicSyntax#Null#Safety#Data#OOP#Functions#Concurrency#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance