Kotlin Reference

This section documents Kotlin 2.4.x on the JVM, as published at kotlinlang.org, which is the reference these pages are written and verified against.

This content was generated with the assistance of AI and should be verified against kotlinlang.org before being relied on in production.

This section’s bibliography lists the reference material consulted while preparing these pages.

Welcome to the Kotlin reference. Kotlin is a modern, statically-typed language for the JVM (and, via Kotlin Multiplatform, JS/Native/Wasm) created by JetBrains — concise syntax, null safety built into the type system, and full Java interoperability. This section documents Kotlin 2.4.x on the JVM, written and verified against kotlinlang.org.

If you are new to Kotlin, read Getting Started and Kotlin and the JVM first, then the Language fundamentals pages in order, followed by Object-oriented and functional programming — from there the remaining groups (the type system, collections and metaprogramming, error handling, coroutines, and Kotlin on Android and tooling) can be read in any order as you need them. For Kotlin’s server-side use, see Java or Kotlin for Spring Boot?.

What’s covered

Getting started

  • Getting Started — what Kotlin is, installing it, kotlinc, the Kotlin REPL, the Kotlin Playground, and "Hello, World".

  • Kotlin and the JVM — Kotlin/JVM bytecode, Java interoperability, where Kotlin/JVM runs, and Kotlin Multiplatform’s other targets.

Language fundamentals

  • Lexical Structure and Style — file/package structure, identifiers, comments, optional semicolons, literals, and the official coding conventions.

  • Basic Types and Variables — val/var, type inference, the built-in number/Boolean/Char types, Any/Unit/Nothing, arrays, and unsigned integers.

  • Strings and Text — string templates, raw/triple-quoted strings, and common String operations.

  • Operators and Ranges — arithmetic/comparison/logical operators, ranges and progressions, and infix notation.

  • Control Flow — if/when as expressions, for/while, and labeled break/continue.

  • Functions — default and named arguments, single-expression functions, vararg, local functions, and tailrec.

Object-oriented and functional programming

Type system

Collections and metaprogramming

Error handling

Coroutines

Kotlin on Android & tooling

  • Kotlin for Android — Android KTX, Jetpack pointers, and coroutines on Android.

  • Build and Tooling — the Gradle Kotlin DSL, Maven’s Kotlin plugin, IDE support, and static analysis.

  • Testing — kotlin.test, JUnit 5 with Kotlin, MockK, and kotlinx-coroutines-test.

Reference

  • Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography

The book above is a consulted reference, not the primary source for this section; on any discrepancy, or wherever it is silent on a feature introduced after it was written, the official Kotlin documentation wins.