Kotlin is a modern, statically-typed programming language developed by JetBrains that runs on the Java Virtual Machine (JVM), compiles to native binaries, and WebAssembly, and is officially supported for Android development. Since Google announced Kotlin as a first-class language for Android in 2017, it has become the preferred choice for millions of developers due to its concise syntax, null safety guarantees, and seamless Java interoperability. The K2 compiler β stable since Kotlin 2.0 β brings significantly faster compilation and unified behaviour across all platforms. Understanding Kotlin's type system and its convention-based approach (where language features like operator overloading and property delegation are implemented through specific naming conventions) is key to writing idiomatic, expressive code across Android, server-side, and Kotlin Multiplatform projects.
What This Cheat Sheet Covers
This topic spans 22 focused tables and 167 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Null Safety Features
| Feature | Example | Description |
|---|---|---|
var name: String? = null | β’ Append ? to any type to allow null valuesβ’ compiler enforces explicit handling before access. | |
val length = name?.length | β’ Returns null if the receiver is nullβ’ chains safely without throwing NullPointerException. | |
val len = name?.length ?: 0 | Provides default value when the left-hand expression evaluates to null. | |
if (x != null) x.length | Compiler automatically casts to non-nullable type after a null check β no explicit cast needed. |