Free tutorial · 31 lessons
Kotlin Tutorial
Learn Kotlin step by step: variables and types, null safety, functions and lambdas, classes, data and sealed classes, extensions, collections and sequences, scope functions, generics, error handling, delegation, coroutines and Flow, context parameters and testing. Every example is compiled with Kotlin 2.4 and run.
Kotlin Basics
- Kotlin Introduction — What Kotlin is, where it's used (Android, servers, multiplatform), and what a Kotlin program looks like.
- Kotlin Get Started — Install Kotlin, create a project with Gradle or IntelliJ IDEA, and compile and run a program.
- Kotlin Syntax and Output — Statements, comments, println and print, and string templates for formatted output.
- Kotlin Variables: val and var — Declare read-only variables with val and mutable ones with var, and let type inference do the work.
- Kotlin Data Types — Numbers, booleans, characters and strings, type conversion, and how Kotlin maps them to the JVM.
- Kotlin Strings — Work with strings: templates, common functions, multiline raw strings and building strings efficiently.
- Kotlin if and when — Branch with if and when, both of which are expressions that return a value.
- Kotlin Loops and Ranges — Loop with for over ranges and collections, while and do-while, and control loops with break and continue.
- Kotlin Functions — Declare functions with fun, use default and named arguments, single-expression functions and varargs.
- Kotlin Null Safety — Nullable types, safe calls, the Elvis operator, smart casts and why Kotlin code rarely throws NullPointerException.
- Kotlin History & Versions — How Kotlin grew from a JetBrains project into Google's preferred language for Android, the K2 compiler, Kotlin Multiplatform, the release cadence, and which version to use today.
Object-Oriented Kotlin
- Kotlin Classes and Properties — Define classes with primary constructors, properties, init blocks, custom getters and visibility modifiers.
- Kotlin Data Classes — Data classes generate equals, hashCode, toString, copy and destructuring for classes that hold data.
- Kotlin Inheritance and Interfaces — Classes are final by default: use open, abstract classes and interfaces to share behaviour and types.
- Kotlin Objects and Companion Objects — Singletons with object declarations, companion objects for factory functions, and object expressions.
- Kotlin Enums and Sealed Classes — Model fixed sets of values with enum classes and closed hierarchies with sealed classes and exhaustive when.
- Kotlin Extension Functions — Add functions and properties to existing types, including ones you don't own, without inheritance.
Functional Kotlin and Collections
- Kotlin Lambdas and Higher-Order Functions — Function types, lambdas, the it parameter, trailing lambdas, function references and closures.
- Kotlin Collections: List, Set and Map — Read-only and mutable lists, sets and maps, how to create them, and how to access their elements.
- Kotlin Collection Operations — Transform and query collections with map, filter, sortedBy, groupBy, associate, fold, partition and more.
- Kotlin Sequences — Process large or infinite data lazily with sequences instead of building intermediate lists.
- Kotlin Scope Functions: let, run, apply, also, with — Use let, run, apply, also and with to work with an object inside a block, and know which one to pick.
Advanced Kotlin
- Kotlin Generics — Generic classes and functions, type constraints, variance with in and out, and reified type parameters.
- Kotlin Exceptions and Result — Throw and catch exceptions, use try as an expression, preconditions with require and check, and runCatching.
- Kotlin Delegation: by lazy and Delegated Properties — Delegate interface implementations with by, and properties with lazy, observable and map-backed delegates.
- Kotlin Coroutines — Write asynchronous code that reads like sequential code with suspend functions, launch, async and structured concurrency.
- Kotlin Flow — Handle streams of values asynchronously with Flow: building, transforming, collecting and StateFlow.
- Kotlin Context Parameters — Pass dependencies such as a logger or a transaction implicitly with context parameters, stable since Kotlin 2.4.
Kotlin Projects
- Kotlin Testing — Write unit tests with kotlin.test and JUnit, assert results and exceptions, and test coroutines.
- Kotlin with Gradle, Android and Multiplatform — How real Kotlin projects are organised: Gradle builds, Android apps, server frameworks and Kotlin Multiplatform.
- Kotlin Next Steps — Where to go after this tutorial: idiomatic Kotlin, Android with Compose, coroutines in depth and related courses.