Lumenary CS · Programming languages
Kotlin
Concise, null-safe Kotlin 2 on the JVM, from a first program to data classes, sealed hierarchies, generics, coroutines and Java interoperability.
Kotlin is a statically typed language from JetBrains that compiles to Java bytecode (and also to native code, JavaScript and WebAssembly). It is the preferred language for Android, a popular choice for server-side development alongside Java, and the basis of Kotlin Multiplatform for sharing code between Android, iOS, desktop and the web. Its hallmarks are concise code, null safety checked by the compiler, and seamless use of every Java library.
This course is for anyone who can already write a small program with variables, decisions and loops, at the level of the Start level of Lumenary CS or equivalent experience; knowing Java helps but is not required. It goes from installing the compiler and a first program, through null safety, functions and lambdas, classes, data and sealed classes, collections and scope functions, to generics and variance, coroutines and structured concurrency, Java interoperability, Gradle and testing, ending with a complete small project.
To run the code, use the official Kotlin Playground in the browser, or install the compiler from the Kotlin website (or IntelliJ IDEA, which includes it) together with a JDK. Every complete program in these lessons was compiled with Kotlin 2.4 and run on JDK 21.
- Chloe · The Designer
“Why is the language built this way?” - Margaret · The Profiler
“What does it print, and what does it cost?” - Gideon · The Language Lawyer
“What exactly does the language guarantee?”
Foundations · 3 lessons
Foundations
Where Kotlin comes from and how to run it, values, types and null safety, and control flow, when expressions and functions with default arguments, extensions and lambdas.
- 1Why Kotlin, and a first programWhere Kotlin came from, where it is used, how to install it, and how a Kotlin source file becomes a running program on the JVM. 45 min
- 2Values, types and null safetyval and var, Kotlin's basic types and explicit conversions, strings and equality, and the type system's most famous feature, the separation of nullable and non-null types. 55 min
- 3Control flow, when and functionsExpressions instead of statements, the when expression, ranges and loops, and Kotlin's functions, from default and named arguments to extension functions and lambdas. 60 min
Practice · 3 lessons
Practice
Everyday Kotlin: classes, data classes, sealed classes and objects, collections, sequences and scope functions, and generics with declaration-site variance.
- 4Classes, data classes, sealed classes and objectsPrimary constructors and properties, final-by-default inheritance, interface delegation, data and value classes, enums, sealed hierarchies, and objects and companions. 60 min
- 5Collections, sequences and scope functionsRead-only and mutable collections, the standard library's rich set of transformations, lazy sequences, and the five scope functions and when to use each. 55 min
- 6Generics and varianceGeneric classes and functions with bounds, declaration-site variance with out and in, use-site projections, star projections, and reified type parameters. 60 min
Professional · 3 lessons
Professional
Coroutines and structured concurrency, working with Java code, Gradle and testing, and a complete project in idiomatic Kotlin.
- 7Coroutines and structured concurrencySuspend functions and how the compiler implements them, a hand-built scheduler, and the kotlinx.coroutines library's builders, scopes, cancellation, dispatchers and flows. 70 min
- 8Java interoperability, Gradle and testingCalling Java from Kotlin and Kotlin from Java, building with Gradle's Kotlin DSL, and testing with kotlin.test, JUnit and their relatives. 60 min
- 9A complete project, and where to go nextA small calculator language with variables, functions and helpful error messages, built from sealed types, data classes, recursion and lambdas, and a map of the Kotlin world beyond this course. 70 min
Further reading and resources
- Kotlin · JetBrainsThe official website.
- Kotlin documentation · JetBrainsThe language guide, standard library reference and tutorials.
- Kotlin language specification · JetBrainsThe precise definition of the language.
- Kotlin Playground · JetBrainsRun Kotlin in the browser.
- kotlinx.coroutines · JetBrainsThe official coroutines library and its guide.