1 · Introduction

What is Kotlin?

Kotlin is a modern, statically‑typed language from JetBrains, running on the JVM and beyond (JavaScript, Native, WebAssembly). It emphasises conciseness, safety (null‑safety by design), and full interoperability with Java. Latest stable version (May 2025) is 2.0.0, featuring the new K2 compiler that unifies all back‑ends and dramatically reduces build time (up to 94 % faster on large projects) .

Note: If you know Java, you already understand ~90 % of Kotlin’s runtime ecosystem.

Key Design Goals

2 · Language Fundamentals

Variables & Types


// Immutable
val greeting: String = "Hello"
// Mutable
var counter = 0     // inferred Int

Control Flow


for (i in 1..3)   { println(i) }
when (score) {
	10  -> println("Perfect")
	in 0..4 -> println("Try again")
	else -> println("Nice")
}

Null‑Safety Basics

Kotlin models absence explicitly with ? types and safe‑call ?.:


val maybeName: String? = fetchName()
println(maybeName?.length ?: 0)

3 · Functions & Lambdas

Defining Functions


fun add(a: Int, b: Int): Int = a + b

Higher‑Order Functions


numbers.filter { it % 2 == 0 }
       .map    { it * it }

Note: Inline functions eliminate call‑site overhead – critical for HOF‑heavy code (e.g. DSLs).

4 · Classes & OOP

Data Classes


data class User(val id: Int, val name: String)

Sealed Hierarchies


sealed interface Result<T>
data class Success<T>(val data: T): Result<T>
data class Failure(val ex: Throwable): Result<Nothing>

Note: The compiler exhaustively checks when over sealed types – no else needed.

5 · Collections + Generics

Standard Ops


val names = listOf("Ada","Grace")
println(names.joinToString())

Generics & Variance


class Box<out T>(val value:T)

Use in / out for consumer‑producer variance instead of Java’s wildcards.

6 · Coroutines & Concurrency

Structured Concurrency


scope.launch {
	val weather = async { api.weather() }
	val news    = async { api.headlines() }
	show(weather.await(), news.await())
}

Flows

Cold asynchronous streams with operators (~Rx). Back‑pressure handled via suspending emissions.

7 · Multiplatform & Native

Kotlin Multiplatform (KMP)

Share business logic (commonMain) across Android, iOS, Desktop, Web, and Embedded targets. JetBrains’ 2025 roadmap focuses on Compose Multiplatform for seamless shared UIs and first‑party Swift‑export tooling .

Native Inter‑op

8 · Tooling & Build Systems

Gradle KTS


plugins{
	kotlin("jvm") version "2.0.0"
}
dependencies{
	implementation(platform(libs.kotlin.bom))
}

IDE Support

9 · Advanced Language Features

Context Receivers


context (Transaction, Logger)
fun Account.transfer(amount:Money, to:Account){ ... }

Value Classes & Inline Functions


@JvmInline
value class Email(val value:String)

Opt‑in & Explicit API Mode

Note: Adopt -Xexplicit-api=strict for library development to catch accidental public leaks.

10 · Ecosystem & Libraries

Core Stacks

Testing Tools

Use kotlin.test, JUnit5, MockK, and kotest for expressive DSLs.

11 · Best Practices & Style

Idiomatic Guidelines

Performance Tips

The K2 compiler removes a major bottleneck for incremental builds; migrate with the official guide .

12 · Latest Changes (1.9 → 2.0)

Highlights since 1.9 (2023‑07)

Roadmap 2025 → 2026

13 · Further Resources

Note: All examples compile under Kotlin 2.0 on the JVM with -Xcontext-receivers enabled.