43 lessons

Kotlin Tutorial for Beginners

Learn Kotlin programming step by step, from your first program to classes, null safety, coroutines and unit testing, with runnable Kotlin examples, exercises and quizzes.

Browse all 43 lessons by stage

Lessons
43
Code examples
94
Exercises
143
Quiz questions
161

Kotlin course at a glance

Who it's for

Complete beginners, Android developers who want a solid grasp of the language, Java developers moving to Kotlin, and backend developers using Spring Boot or Ktor.

Prerequisites

None for the core lessons. Basic computer skills are enough, and the in-depth guides list the lessons to finish before you start them.

What you need

The online Kotlin Playground to start, then IntelliJ IDEA Community Edition or Android Studio, both free, with a JDK 17 or later.

How long it takes

About two months for the 25 core lessons at five hours a week, plus a few weeks for the in-depth guides you need for your projects.

Kotlin roadmap: beginner to advanced

Work through the 25 core chapters in the first three stages in order, then use the reference stages to go deeper. Each reference lesson links to its prerequisite and includes examples, practice and a quiz.

2

Intermediate

Lists, maps, collection operations, lambdas, classes, data classes, interfaces, objects and sealed classes.

  1. 9ListsStore ordered items in read-only and mutable lists, read them by index, add, remove and update items, and use the most common list functions.
  2. 10Maps & SetsStore key-value pairs in maps and unique values in sets, read and update them safely, loop over entries, and count and group with maps.
  3. 11Collection OperationsTransform, filter, sort, group and summarise collections in one readable line with map, filter, sumOf, sortedBy, groupBy, associate and friends.
Show all 9 lessonsShow fewer
  1. 12LambdasWrite functions as values with lambdas, pass them to other functions, use it and trailing lambda syntax, return functions, and reference existing functions with ::.
  2. 13Classes & ObjectsModel real things with classes: primary constructors, properties with val and var, methods, init blocks, custom getters and setters, and private members.
  3. 14Data ClassesHold data with one line of code using data classes, which generate toString, equals, hashCode, copy and component functions for destructuring.
  4. 15Inheritance & InterfacesReuse and extend behaviour with open classes, override and super, define contracts with interfaces, share code with abstract classes, and use polymorphism.
  5. 16Objects & CompanionsCreate singletons with object declarations, add class-level functions and constants with companion objects, build factory functions, and make one-off anonymous objects.
  6. 17Enums & Sealed ClassesModel a fixed set of options with enum classes and a fixed set of related types with sealed classes and interfaces, then handle every case with an exhaustive when.
3

Advanced

Exceptions, extension functions, generics, scope functions, coroutines, flows, files and testing.

  1. 18ExceptionsHandle errors with try, catch and finally, use try as an expression, throw and create your own exceptions, validate with require and check, and wrap risky calls with runCatching and Result.
  2. 19Extension FunctionsAdd new functions and properties to existing classes, even ones you didn't write, with extension functions, and learn how they're resolved and where to put them.
  3. 20GenericsWrite classes and functions that work with any type safely, using type parameters, upper bounds, variance with in and out, star projections and reified types.
Show all 8 lessonsShow fewer
  1. 21Scope FunctionsWrite tidier code with let, run, with, apply and also, and learn exactly how they differ in what they return and how they refer to the object.
  2. 22CoroutinesWrite asynchronous code that reads like normal code with coroutines: suspend functions, runBlocking, launch, async and await, delay, structured concurrency, dispatchers and timeouts.
  3. 23FlowsHandle streams of values over time with Kotlin Flow: building flows, collecting them, transforming with map and filter, combining flows, handling errors, and holding state with StateFlow.
  4. 24Files & I/ORead and write text files in Kotlin with File, readText, readLines, writeText and appendText, process big files lazily with useLines, close resources with use, and parse CSV and JSON-like data.
  5. 25TestingCheck your code automatically with unit tests: @Test functions, assertEquals and assertFailsWith, test setup, testing coroutines with runTest, fakes for dependencies, and running tests with Gradle.
4

Language reference

Arrays, packages and visibility, smart casts, delegated properties, interface delegation, nested classes, inline functions, operators, sequences, equality and regex.

  1. 26Arrays and primitive arraysChoose fixed-size arrays deliberately and understand primitive storage, copying, nested arrays and content equality.
  2. 27Packages and visibilityOrganize declarations with packages and control public, internal, protected and private access at the appropriate boundary.
  3. 28Type checks and castsNarrow unknown values with is, use as? for optional casts and understand when compiler smart casts remain safe.
Show all 11 lessonsShow fewer
  1. 29Delegated propertiesDelegate property behavior, initialize values lazily and distinguish deferred assignment from computed initialization.
  2. 30Interface delegationForward an interface to a composed object and understand overrides, delegate identity and explicit dependency ownership.
  3. 31Nested and inner classesGroup related types without accidental outer-instance capture and use inner only when a live outer relationship is intended.
  4. 32Inline functions and returnsUnderstand inlining as a calling contract, control non-local returns and choose noinline or crossinline for escaping callbacks.
  5. 33Operator overloadingImplement established operator conventions with clear domain meaning and avoid surprising mutation or comparison behavior.
  6. 34SequencesTrace when a lazy sequence performs work, stop after enough results, and recognize operations that still require memory.
  7. 35Equality and hashingDistinguish value equality from identity and design stable keys that remain findable in hash-based collections.
  8. 36Regex parsingChoose whole-input matching or searching, extract captures, and convert text safely without confusing syntax with business validity.

What is Kotlin?

Kotlin is a modern, concise programming language created by JetBrains and backed by Google as the preferred language for Android development. It runs on the Java Virtual Machine, so it works with every Java library, but its code is shorter and safer. The compiler catches the dreaded "null pointer" errors before your program ever runs.

Kotlin is a great first language and an even better second one. Its syntax is clean and readable, it has helpful features such as string templates and data classes, and it scales from tiny scripts to the apps used by millions of people.

This tutorial has three stages. The beginner stage covers your first program, variables, numbers, strings, null safety, decisions with if and when, loops and ranges, and functions. The intermediate stage teaches lists, maps and sets, powerful collection operations, lambdas, classes, data classes, interfaces, objects and sealed classes. The advanced stage covers exceptions, extension functions, generics, scope functions, coroutines and flows for asynchronous code, files and automated testing.

Every lesson has small examples with their output, common mistakes, exercises and a quiz. If you already know Java, you'll recognise many ideas and enjoy how much less code Kotlin needs.

How to follow this course

Work through the 25 core lessons in order, because each one builds on the last. After that, the in-depth guides answer the questions real projects raise. The language guides cover arrays, packages and visibility, smart casts, delegated properties such as lazy, inline functions, operator overloading, sequences, equality and regular expressions. The tooling and interoperability guides cover calling Java from Kotlin, Gradle's Kotlin DSL, JSON serialization and dates and time zones. The coroutine guides go further into supervision and cleanup, shared state with Mutex, and buffering and sharing flows. Each guide lists the core lessons to finish first.

What you will learn

10 practical skills, built one lesson at a time

  • Write and run Kotlin programs in the Playground or IntelliJ IDEA
  • Use variables, numbers, strings and string templates confidently
  • Prevent null errors with nullable types, safe calls and the Elvis operator
  • Control programs with if, when, loops and ranges
  • Write functions with default and named arguments
  • Store and transform data with lists, maps, sets and lambdas
  • Model data with classes, data classes, interfaces, enums and sealed classes
  • Use extension functions, generics and scope functions like apply and let
  • Write asynchronous code with coroutines and flows
  • Read and write files and test your code with kotlin.test
43 lessons94 examples143 exercises

Practise Kotlin your way

Learning sticks when you use it. Pick a mode.

Kotlin FAQ

Is Kotlin good for beginners?

Yes. Kotlin's syntax is short and readable, and its null safety means many common beginner mistakes are caught before the program runs. You can start in the online Kotlin Playground without installing anything.

Do I need to learn Java before Kotlin?

No. This course assumes no previous programming. Knowing Java helps when you read older Android code or documentation, and Kotlin and Java work together in the same project, so you can pick up Java later if you need it.

Is Kotlin only for Android?

No. Android is its best-known use, but Kotlin also powers web servers with frameworks like Spring Boot and Ktor, desktop apps, scripts and Kotlin Multiplatform projects that share code between Android, iOS and the web.

How long does it take to learn Kotlin?

With about an hour a day, most beginners finish the beginner stage in two weeks and the whole course in two to three months. Building a small app or command-line tool alongside the lessons is the fastest way to make it stick.

Should I learn Kotlin or Swift for mobile apps?

Kotlin is the language for Android and Swift is the language for iPhone and iPad. If you want to reach both, Kotlin Multiplatform can share logic between them, but most developers start with whichever platform they use themselves. See the Swift tutorial too.

Is this Kotlin course free?

Yes. All 25 core lessons, the 18 in-depth guides, the exercises, the quiz and the cheat sheet are free, with no account or sign-up needed.

Which Kotlin version does the course use?

The examples are written for Kotlin 2 and run on the JVM. Almost everything also works on late Kotlin 1.x releases; lessons point out the few features, such as the ..< range operator, that need a recent version.

Can I build Android apps after this course?

This course teaches the Kotlin language, which is the foundation for Android work. To build apps you'll also learn Jetpack Compose and the Android SDK, which become much easier once classes, lambdas, collections and coroutines feel natural.

Are coroutines hard to learn?

They're easier once you're comfortable with functions, lambdas and classes, which is why they come near the end. The core lessons cover launch, async and flows, and the coroutine guides then cover cancellation, supervision and shared state step by step.

More tutorials