Learn Kotlin from the Ground Up
Official Kotlin tour content with an interactive multi-file editor. Practice challenges with run and submit validationโlearn by doing.
- Beginner ยท 1
Hello world
Here is a simple program that prints "Hello, world!":...
Start Lesson - Beginner ยท 2
Basic types
Every variable and data structure in Kotlin has a type. Types tell the compiler what you are allowed...
Start Lesson - Beginner ยท 3
Collections
Kotlin provides collections for grouping data: Lists (ordered, allow duplicates), Sets (unordered, u...
Start Lesson - Beginner ยท 4
Control flow
Like other programming languages, Kotlin is capable of making decisions based on whether a piece of ...
Start Lesson - Beginner ยท 5
Functions
You can declare your own functions in Kotlin using the fun keyword. Parameters go in (), each with a...
Start Lesson - Beginner ยท 6
Classes
Kotlin supports object-oriented programming with classes and objects. Objects store data; classes de...
Start Lesson - Beginner ยท 7
Null safety
Kotlin allows null values when something is missing or not yet set. Null safety detects potential nu...
Start Lesson
- Intermediate ยท 1
Extension functions
In this chapter, you'll explore special Kotlin functions that make your code more concise and readab...
Start Lesson - Intermediate ยท 2
Scope functions
In this chapter, you'll build on your understanding of extension functions to learn how to use scope...
Start Lesson - Intermediate ยท 3
Lambda expressions with receiver
In this chapter, you'll learn how to use receivers with another type of function, lambda expressions...
Start Lesson - Intermediate ยท 4
Classes and interfaces
In the beginner tour, you learned how to use classes and data classes to store data. Eventually, you...
Start Lesson - Intermediate ยท 5
Objects
In this chapter, you'll expand your understanding of classes by exploring object declarations. This ...
Start Lesson - Intermediate ยท 6
Open and special classes
In this chapter, you'll learn about open classes, how they work with interfaces, and other special t...
Start Lesson - Intermediate ยท 7
Properties
Properties have default get() and set() (getters and setters) that use a backing field to store the ...
Start Lesson - Intermediate ยท 8
Null safety
This chapter covers common use cases for null safety and how to make the most of them....
Start Lesson - Intermediate ยท 9
Libraries and APIs
Use existing libraries and APIs so you can spend more time coding and less time reinventing the whee...
Start Lesson
- Advanced ยท 1
Coroutines basics
Kotlin provides only minimal low-level APIs in its standard library to enable other libraries to uti...
Start Lesson - Advanced ยท 2
Coroutines and channels โ tutorial
In this tutorial you'll learn how to use coroutines in IntelliJ IDEA to perform network requests wit...
Start Lesson - Advanced ยท 3
Cancellation and timeouts
Cancellation lets you stop a coroutine before it completes. It stops work that's no longer needed, s...
Start Lesson - Advanced ยท 4
Composing suspending functions
This section covers various approaches to composition of suspending functions....
Start Lesson - Advanced ยท 5
Coroutine context and dispatchers
Coroutines always execute in some context represented by a value of type CoroutineContext. The main ...
Start Lesson - Advanced ยท 6
Asynchronous Flow
A suspending function returns a single value asynchronously. To return multiple asynchronously compu...
Start Lesson - Advanced ยท 7
Channels
Deferred transfers a single value between coroutines. Channels transfer a stream of values....
Start Lesson - Advanced ยท 8
Coroutine exception handling
This section covers exception handling and cancellation on exceptions. A cancelled coroutine throws ...
Start Lesson - Advanced ยท 9
Shared mutable state and concurrency
Coroutines running in parallel (e.g. Dispatchers.Default) face the same concurrency issues as multi-...
Start Lesson - Advanced ยท 10
Select expression (experimental)
Select expression lets you await multiple suspending functions at once and use the first result that...
Start Lesson - Advanced ยท 11
Debug coroutines using IntelliJ IDEA
This tutorial shows how to create Kotlin coroutines and debug them in IntelliJ IDEA. You should alre...
Start Lesson - Advanced ยท 12
Debug Kotlin Flow using IntelliJ IDEA
This tutorial shows how to create Kotlin Flow and debug it in IntelliJ IDEA. You should already know...
Start Lesson - Advanced ยท 13
Sealed classes & exhaustive when
A sealed class (or sealed interface) restricts which classes can extend it: every direct subclass mu...
Start Lesson - Advanced ยท 14
Data classes deep dive
A data class declares a value carrier โ a class whose identity is its data, not its address. The com...
Start Lesson - Advanced ยท 15
Generics, variance & reified
A generic class or function parameterizes over a type: class Box<T>(val value: T). The compiler inst...
Start Lesson - Advanced ยท 16
Sequences: lazy collection processing
Collection operations on a List (map, filter, โฆ) are EAGER: each step materialises a brand-new List....
Start Lesson - Advanced ยท 17
Delegation: class & property
Kotlin builds delegation into the language with the `by` keyword. There are two flavours: CLASS dele...
Start Lesson - Advanced ยท 18
Operator overloading & value classes
Kotlin lets you give meaning to operators on your own types by implementing well-named operator func...
Start Lesson - Advanced ยท 19
Enum classes: methods, companions, and beyond
Enums in Kotlin are full classes: they can have constructors, properties, methods, companion objects...
Start Lesson - Advanced ยท 20
Result & error-handling patterns
Kotlin gives you three ways to express failures: throw exceptions (familiar from Java), return null ...
Start Lesson - Advanced ยท 21
StateFlow & SharedFlow
Flow (covered earlier) is COLD: a new collector restarts the upstream. For UI state and event buses ...
Start Lesson - Advanced ยท 22
Type system extras: typealias, smart casts, contracts
Three small-but-mighty Kotlin features that make types feel friendlier: type aliases for readability...
Start Lesson - Advanced ยท 23
Testing: JUnit, kotlin.test, kotest
Three popular testing frameworks dominate Kotlin testing. They all coexist; pick one per module:...
Start Lesson - Advanced ยท 24
Building DSLs with lambdas with receiver
A DSL (domain-specific language) is a focused mini-language inside Kotlin: HTML builders (kotlinx.ht...
Start Lesson - Advanced ยท 25
Inline functions: reified, crossinline & noinline
Every higher-order function normally allocates an object for its lambda and pays a virtual call per ...
Start Lesson - Advanced ยท 26
Collection power operations
Beyond map/filter, Kotlin's standard library ships a deep toolbox of collection operators. Reaching ...
Start Lesson - Advanced ยท 27
Destructuring declarations & component functions
A destructuring declaration splits an object into several variables in one statement: val (name, age...
Start Lesson - Advanced ยท 28
Infix functions & the invoke operator
An infix function lets you call a single-parameter member or extension function without the dot and ...
Start Lesson - Advanced ยท 29
Tail-recursive functions (tailrec)
Deep recursion on the JVM risks a StackOverflowError: every call adds a stack frame. Kotlin offers `...
Start Lesson - Advanced ยท 30
Advanced generics: star-projection & bounds
This lesson builds on declaration-site variance (in/out) with the rest of Kotlin's generic toolkit: ...
Start Lesson - Advanced ยท 31
Functional programming: composition & currying
Functions are first-class values in Kotlin: you can store them in variables, pass them as arguments,...
Start Lesson - Advanced ยท 32
Comparable, Comparator & sorting idioms
Two abstractions drive ordering in Kotlin. Comparable<T> defines a type's *natural order* via compar...
Start Lesson - Advanced ยท 33
Structured concurrency: scopes & supervision
Structured concurrency is the rule that every coroutine lives inside a scope and a parent never comp...
Start Lesson - Advanced ยท 34
Contracts & smart-cast flow analysis
Kotlin's compiler tracks what it knows about a variable as code flows along โ that's how smart casts...
Start Lesson - Advanced ยท 35
Type aliases & functional-type modeling
A type alias gives an existing type a new name: typealias Name = Existing. It introduces no new type...
Start Lesson - Advanced ยท 36
Function composition & pipelines
Composition is the act of gluing small functions together so the output of one feeds the input of th...
Start Lesson - Advanced ยท 37
Recursion & memoization
A recursive function solves a problem by calling itself on smaller inputs until it hits a base case....
Start Lesson - Advanced ยท 38
Flow operators & backpressure
A Flow is a cold asynchronous stream of values produced over time. Like a sequence it is lazy โ noth...
Start Lesson - Advanced ยท 39
Time & Duration (kotlin.time)
kotlin.time gives you a type-safe Duration instead of bare Long milliseconds. A Duration knows its o...
Start Lesson - Advanced ยท 40
Bit manipulation & flags
Integers are sequences of bits, and Kotlin exposes named infix operators to work on them directly: `...
Start Lesson - Advanced ยท 41
Custom iterators & the iterator builder
Any type that provides an `operator fun iterator(): Iterator<T>` can be used in a `for (x in thing)`...
Start Lesson - Advanced ยท 42
Kotlin Regex Essentials
Regular expressions in Kotlin live entirely in the standard library through the `kotlin.text.Regex` ...
Start Lesson - Advanced ยท 43
Exceptions in Depth: try/catch, Custom Errors, Nothing, and Result
Programs fail. A number string is malformed, a file is missing, a balance is too low. Kotlin models ...
Start Lesson - Advanced ยท 44
Equality and Hashing: == vs ===, the equals/hashCode Contract
Kotlin distinguishes two kinds of equality, and confusing them is a classic source of bugs. Structur...
Start Lesson - Advanced ยท 45
Nested, Inner, Anonymous, and Local Classes
Kotlin lets you declare a class inside another class, or even inside a function body. This is useful...
Start Lesson - Advanced ยท 46
Grouping and Aggregation
Real programs rarely want a raw list; they want a summary of it: how many sales per region, the tota...
Start Lesson - Advanced ยท 47
Idiomatic Algorithmic Patterns in Kotlin
Great competitive and interview code is rarely about clever tricks. It is about recognizing a small ...
Start Lesson - Advanced ยท 48
String Mastery: Templates, Builders, and Character Wizardry
A Kotlin `String` is an immutable sequence of characters: once created it never changes, and every "...
Start Lesson - Advanced ยท 49
Ranges & Progressions: Counting the Kotlin Way
A range in Kotlin is a tiny but mighty value that represents "every element from here to there." You...
Start Lesson - Advanced ยท 50
Collection Builders: buildList, buildMap, buildSet & buildString
Kotlin loves immutability, but real data rarely arrives ready-made. You loop, you branch, you skip d...
Start Lesson - Advanced ยท 51
Mastering `when`: Kotlin's Swiss-Army Branch
If `if` is a light switch, Kotlin's `when` is a whole control panel. It started life as a nicer-look...
Start Lesson - Advanced ยท 52
Annotations and Runtime Introspection on the Standard Library
Annotations are metadata you bolt onto your code: little structured stickers that travel with classe...
Start Lesson - Advanced ยท 53
Dynamic Programming in Kotlin: Memoization vs Tabulation
Dynamic programming (DP) sounds intimidating, but the idea is almost embarrassingly simple: solve ea...
Start Lesson - Advanced ยท 54
Backtracking in Kotlin: Choose, Explore, Un-choose
Backtracking is the art of building a solution one decision at a time, and quietly undoing each deci...
Start Lesson - Advanced ยท 55
Stacks & Queues with ArrayDeque
Two of the most useful data structures in all of programming are the stack and the queue, and the wo...
Start Lesson - Advanced ยท 56
Beyond find: Binary Search Patterns in Kotlin
`find` and `indexOf` walk a collection element by element. That is fine for a quick lookup, but it i...
Start Lesson - Advanced ยท 57
Grids and Matrices: 2D Arrays, Transpose, Rotation, and Flood Fill
Grids are everywhere in real software: pixels in an image, tiles in a game map, cells in a spreadshe...
Start Lesson - Advanced ยท 58
Build Your Own Structures: Linked Lists and Binary Trees
Kotlin hands you `List`, `MutableList`, `Map` and `Set` for free, so why would you ever build a data...
Start Lesson - Advanced ยท 59
Kotlin Maps in Depth: Lookups, Caching, and Transformations
A map is Kotlin's dictionary: a collection of key-value pairs where every key is unique. You build a...
Start Lesson - Advanced ยท 60
Type Checks, Casts, and Smart Casts
Every value in a Kotlin program carries its real type at runtime, and Kotlin gives you elegant tools...
Start Lesson - Advanced ยท 61
Local Functions, Closures, and Labels
Kotlin lets you declare a function *inside* another function. These nested helpers are called local ...
Start Lesson - Advanced ยท 62
Defensive Preconditions and Everyday Idioms
Good Kotlin code fails fast and fails loudly. Instead of letting a bad value silently corrupt your p...
Start Lesson - Advanced ยท 63
Numbers and Conversions: Ints, Doubles, and Safe Arithmetic
Kotlin gives you a small, sharp toolbox of numeric types, and choosing the right one is the first de...
Start Lesson - Advanced ยท 64
Sets and Set Algebra in Kotlin
A `Set` is Kotlin's collection for a bag of *distinct* values. Where a `List` happily stores `["red"...
Start Lesson - Advanced ยท 65
Interview Hashing Patterns in Kotlin
Almost every coding interview eventually hinges on one question: can you trade memory for time? The ...
Start Lesson - Advanced ยท 66
Greedy Interview Classics in Kotlin
A greedy algorithm builds a solution one step at a time, always taking the choice that looks best ri...
Start Lesson - Advanced ยท 67
Graphs in Kotlin: Adjacency Lists, BFS, DFS, and Shortest Paths
A graph is just a set of nodes (vertices) connected by edges, and it is one of the most common data ...
Start Lesson - Advanced ยท 68
Heaps and Priority Queues in Kotlin
A heap is a binary tree kept in an array where every parent is ordered relative to its children: in ...
Start Lesson - Advanced ยท 69
Interval Interview Problems in Kotlin
Interval problems are one of the most reliable families of questions in coding interviews, and once ...
Start Lesson - Advanced ยท 70
Disjoint Set Union (Union-Find) in Kotlin
Disjoint Set Union (DSU), also called Union-Find, is one of those deceptively small data structures ...
Start Lesson - Advanced ยท 71
Fan-out / Fan-in with Coroutines and Channels
Imagine a pile of work that needs processing: 10,000 image thumbnails to generate, a batch of HTTP r...
Start Lesson - Advanced ยท 72
Limiting Concurrency: Semaphores and Bounded Worker Pools
The first thing every developer does with coroutines is fan out: take a list of 10,000 user IDs, map...
Start Lesson - Advanced ยท 73
Parallel Decomposition: async + awaitAll on Dispatchers.Default
Some problems are 'embarrassingly parallel': you can chop the input into independent pieces, compute...
Start Lesson - Advanced ยท 74
Resilient Suspend Calls: Retry with Backoff and Timeouts
Real systems are flaky. A network blip, a momentarily overloaded service, or a database that is brie...
Start Lesson - Advanced ยท 75
Throttling Coroutine Work: Rate Limiters and Load Shedding
Real systems almost never let you run as fast as you want. A payment gateway allows 10 calls per sec...
Start Lesson - Advanced ยท 76
Single-Flight: Deduplicating Concurrent Identical Requests
Picture a cache miss arriving for the same key from ten coroutines at once. A user-profile screen, t...
Start Lesson - Advanced ยท 77
apply vs let: A Decision Guide to Kotlin's Scope Functions
Kotlin's five scope functions (let, run, with, apply, also) do not give you new powers. They restruc...
Start Lesson - Advanced ยท 78
Immutable Updates with data class copy()
In Kotlin, the idiomatic way to "change" a data class is to not change it at all. Instead of mutatin...
Start Lesson - Advanced ยท 79
Building Objects Fluently with apply
Kotlin's `apply` is one of the five scope functions, and it has a single, very focused job: it runs ...
Start Lesson - Advanced ยท 80
Kotlin in Production: A Field Guide to the Features That Actually Dominate Real Backends
Kotlin is a big language, but a real codebase only leans on a small, repeating subset of it. This le...
Start Lesson - Advanced ยท 81
Annotation Use-Site Targets: @field:, @get:, @set:, @param:
In most languages an annotation has exactly one thing to attach to. In Kotlin a single property decl...
Start Lesson - Advanced ยท 82
The Kotlin/JVM Testing Toolkit: JUnit 5, MockK, StepVerifier & Testcontainers
When you ship Kotlin on the JVM, your tests lean on a small, well-worn stack: **JUnit 5** as the run...
Start Lesson - Advanced ยท 83
Under the Hood of suspend: CPS, State Machines, and Why Coroutines Don't Block Threads
The JVM has no native notion of "suspend". At the bytecode level there is no instruction that pauses...
Start Lesson - Advanced ยท 84
CoroutineContext, the Job Tree, and Structured Cancellation
A CoroutineContext is the single most important object in structured concurrency, yet it is conceptu...
Start Lesson - Advanced ยท 85
Coroutine Dispatchers in Depth: Default, IO, Unconfined, Main, and Thread Confinement
A dispatcher is the part of a coroutine's context that answers a single question: on which thread wi...
Start Lesson - Advanced ยท 86
Cold vs Hot Flows: Flow, StateFlow, and SharedFlow Internals
A cold Flow is a recipe, not a running process. Writing flow { ... } allocates an object that captur...
Start Lesson - Advanced ยท 87
Flow Backpressure, Buffering, Conflation & Context
A Flow is cold and strictly sequential. Until you change something, there is no extra thread and no ...
Start Lesson - Advanced ยท 88
Coroutine Footguns: Races, Scopes, Cancellation, and Error Handling
Coroutines make concurrency look sequential, and that is exactly why they are dangerous: the suspend...
Start Lesson