KtKotlin

Learn Kotlin – tutorial, cheatsheet & exercises

Kotlin is a modern, statically typed language from JetBrains. It runs on the JVM (and also compiles to JavaScript and native code), is 100 % compatible with Java, and is Google's recommended language for Android. The code is considerably more compact and safer than classic Java.

Kotlin's hallmarks: null safety built into the type system (no unexpected NullPointerException), data class, extension functions, expressive collections, when, and coroutines for simple concurrency. Kotlin is used for Android apps, backends (Spring Boot, Ktor), and cross-platform projects (Kotlin Multiplatform).

AndroidBackend (Spring, Ktor)Multiplatform

Hello World in Kotlin

fun main() {
    println("Hello World!")
}

No class wrapper, no semicolons: main can live directly at the top level.

How to get started with Kotlin

The easiest way to get started without installing anything is the Kotlin Playground at play.kotlinlang.org – your code runs right in the browser. For real projects, use IntelliJ IDEA (the Community Edition is free and Kotlin is built in) or Android Studio for apps: choose "New Project" → Kotlin.

For the command line, install the compiler, e.g. with brew install kotlin (Mac), with SDKMAN (sdk install kotlin), or with winget/Scoop on Windows. You also need a JDK (version 17 or 21). Check the installation:

kotlinc -version
java --version

Compile and run: the compiler produces a JAR with the Kotlin runtime built in, which you start with java -jar. Small scripts (.kts) can also be run directly:

kotlinc hallo.kt -include-runtime -d hallo.jar
java -jar hallo.jar

kotlinc -script skript.kts

For projects with dependencies (e.g. coroutines), use Gradle with the Kotlin DSL (build.gradle.kts). IntelliJ sets this up automatically when you create a project. Coroutines are a separate library (kotlinx-coroutines-core) that you add as a dependency.

TipStart in the Kotlin Playground or with a single file hallo.kt. You do not need a class or a project structure to get started: functions can live directly at the top level.

Kotlin learning path

Beginner
Intermediate
Advanced

At a glance

First released2011
CreatorJetBrains
ParadigmMulti-paradigm (OOP, functional)
TypingStatic, strong, type inference
ExecutionJVM, JS, Native
File extension.kt

Test & practice

Interactive quiz, timed exam with certificate, and exercises with an editor:

Kotlin compared

Hello World: Kotlin comparedVariables: Kotlin comparedConditionals: Kotlin comparedLoops: Kotlin comparedFunctions: Kotlin comparedLists and Arrays: Kotlin comparedDictionaries and Maps: Kotlin comparedClasses and Objects: Kotlin comparedError Handling: Kotlin comparedReading Files: Kotlin compared