🐰 Kotlin — Learn From Zero
Playground: Kotlin Playground — click, type, run.
What is Kotlin?
Kotlin is a modern, concise language on the JVM, fully interoperable with Java. Official language for Android.
- Android apps
- Backend (Ktor, Spring)
- Multiplatform (KMM)
- Scripting
Run Online — No Install
Use the playground links above.
🟢 Beginner — Core Basics
Your First Program
kotlin
fun main() {
println("Hello, world!")
}Top-level fun main().
Variables
kotlin
val name = "Ada"
var age = 36
val height = 1.78Prefer val over var.
If / Else
kotlin
val age = 18
val msg = if (age >= 18) "Vote" else "Too young"
println(msg)If is an expression.
Loops
kotlin
for (i in 0..5) println(i)
for (n in list) println(n)Ranges with 0..5 (exclusive end).
Functions
kotlin
fun greet(name: String): String = "Hello, $name!"Expression-bodied functions.
Null Safety
kotlin
var s: String? = null
s?.length
val len = s?.length ?: 0? marks nullable types.
🟡 Intermediate — Building Real Programs
Classes & Data
kotlin
data class Person(val name: String, val age: Int)Data classes auto-generate methods.
OOP
kotlin
interface Animal { fun speak() }
class Dog : Animal { override fun speak() {} }Inheritance with :.
Collections
kotlin
val nums = listOf(1, 2, 3)
val even = nums.filter { it % 2 == 0 }Functional collection ops.
Lambdas
kotlin
val add: (Int, Int) -> Int = { a, b -> a + b }First-class functions.
Scope Functions
kotlin
val p = Person("Ada", 36).apply { println(name) }let, run, apply.
🔴 Advanced — Pro Concepts
Coroutines
kotlin
suspend fun load(): String { delay(100); return "x" }
launch { val d = load() }Lightweight concurrency.
Generics
kotlin
class Box(val value: T) Type parameters.
Sealed Classes
kotlin
sealed class Result { data class Ok(val v: Int): Result()
object Err: Result() }Restricted hierarchies for when.
Delegation
kotlin
interface Base { fun f() }
class Impl : Base { override fun f() {} }
class Wrapper(b: Base) : Base by bClass delegation via by.
What's Next?
- Build a tiny project: Calculator, To-Do App, Weather Widget
- Read the official docs and a good book
- Solve Exercism exercises
- Join a community & share your code
Practice daily for 20 minutes. Consistency > intensity.