Skip to content

Language guide

Learn Kotlin

The modern language for Android, fully interoperable with Java.

Kotlin on SkillAIVibe

Written guide

SkillAIVibe does not run Kotlin in the browser yet, so this page is a written guide: what the language is, a complete first program, how to run it on your own computer, and a learning order. Languages that do run here are listed on the Learn to Code hub.

What Kotlin is

Kotlin is a statically typed language that runs on the Java Virtual Machine and is designed to be concise and safe: the compiler knows the type of every value, refuses null where you have not allowed it, and infers most types so you rarely write them out. It is the language Android's own tooling and documentation prefer, and it works alongside existing Java code without a translation layer. Writing Kotlin feels like a tidier Java with modern features such as data classes, lambdas, extension functions and coroutines, and the same code can be compiled for the JVM, Android, the web or native targets.

Where Kotlin is used

Android apps
Android's official documentation and Android Studio treat Kotlin as the primary language, and the Jetpack Compose toolkit for building interfaces is designed around it.
Server-side services
Backends are written in Kotlin with Ktor, or with Java frameworks such as Spring, and can use any existing Java library directly.
Code shared across platforms
Kotlin Multiplatform lets one module of logic, such as networking, storage or validation, be compiled for Android, iOS, desktop and the web while each platform keeps its own native interface.
Build scripts and tooling
Gradle, the build tool used for Android and most Kotlin projects, can be configured in Kotlin itself, so the build file uses the same language as the app.
Anything the JVM already does
Command-line tools, desktop applications and data pipelines that would once have been Java can be Kotlin, because the compiled output is the same kind of bytecode.

Your first Kotlin program

Saved as hello.kt. Run it with the steps in the next section.

Kotlin
fun main() {
    val name = "Lena"
    val year = 2026
    val items = listOf("tea", "bread", "rice")

    println("Hello, $name.")
    println("In five years it will be ${year + 5}.")
    println("You have ${items.size} items on your list.")
}

What it prints

Output
Hello, Lena.
In five years it will be 2031.
You have 3 items on your list.
  1. Line 1 declares main, the function the program starts in. fun introduces a function, and the braces enclose its body.
  2. Lines 2 to 4 declare three values with val, which means they cannot be reassigned. Kotlin infers the types (String, Int and a List of String) from the right-hand side, so none is written.
  3. Line 6 prints a line. Inside a string, $name is a template: the value of the variable is inserted into the text at that point.
  4. Line 7 uses the longer template form. When you want an expression rather than a plain name, wrap it in ${...} and Kotlin works it out in place.
  5. Line 8 reads the size property of the list. It is a property rather than a method, so there are no brackets after it.

Run Kotlin on your own computer

Kotlin is a compiled language, so running a program is two steps, compile then run, unless an IDE does both for you. The command-line compiler is the smallest setup and is enough for everything on this page; an IDE becomes the better choice once you build an app.

  1. Install a JDK

    Kotlin's compiler and the programs it produces run on the Java Virtual Machine, so install a current Java Development Kit first if this command does not already report one.

    Shell
    java --version
  2. Install the Kotlin command-line compiler

    Download the compiler from the releases page linked from the Kotlin documentation and add its bin folder to your PATH, or install it through one of the package managers the documentation lists. Then confirm it is found.

    Shell
    kotlinc -version
  3. Compile the file into a jar

    Save the first program above as hello.kt. The -include-runtime flag bundles Kotlin's standard library into the jar so it can run on its own.

    Shell
    kotlinc hello.kt -include-runtime -d hello.jar
  4. Run it

    The jar is an ordinary Java program, so the java command runs it.

    Shell
    java -jar hello.jar
  5. Use an IDE for anything bigger

    IntelliJ IDEA, from the same company that makes Kotlin, has Kotlin support built in and compiles and runs a file with one click. For Android apps install Android Studio, which is built on it and adds the Android SDK and emulator. The playground on kotlinlang.org runs small programs in the browser with nothing installed.

A learning order for Kotlin

Stages, not a timetable. Each one exists because the next would not make sense without it, and how long each takes depends on how much you write.

  1. Stage 1. Values, types and output

    • fun main() and println
    • val and var
    • Int, Double, String and Boolean
    • string templates
    • readln() for input

    Kotlin asks you to decide up front whether a value can change, and that habit shapes everything later. The basic types and templates are enough to write small useful programs straight away.

  2. Stage 2. Control flow

    • if as an expression
    • when
    • for over ranges and collections
    • while and do-while
    • ranges: .., ..<, downTo and step

    Kotlin's if and when return values, which removes a lot of temporary variables. Ranges replace the counting loop of other languages, so it is worth learning their forms properly.

  3. Stage 3. Null safety and functions

    • nullable types with ?
    • safe calls ?. and the Elvis operator ?:
    • functions, default and named arguments
    • single-expression functions
    • lambdas and higher-order functions

    Null safety is the reason many people choose Kotlin, and it is easier to learn early than to bolt on later. Lambdas come here because the collection functions in the next stage depend on them.

  4. Stage 4. Collections

    • List, Set and Map
    • read-only versus mutable collections
    • map, filter, forEach and sortedBy
    • destructuring and Pair
    • sequences for large data

    Most program logic is transforming collections of things. Kotlin's read-only-by-default collections and its chain of map and filter calls are the idiomatic way to do it.

  5. Stage 5. Classes and objects

    • classes and constructors
    • data classes
    • inheritance and interfaces
    • object and companion object
    • enum and sealed classes
    • extension functions

    Data classes and sealed classes are Kotlin's tools for modelling the states an app can be in, and Android code leans on them heavily. Extension functions explain a lot of code you will read.

  6. Stage 6. Coroutines, tooling and a first app

    • Gradle projects
    • unit tests with kotlin.test or JUnit
    • coroutines and suspend functions
    • a first Android app with Jetpack Compose, or a Ktor server
    • the Java interoperability rules

    Real projects are built with Gradle and do work in the background, which is what coroutines are for. Choosing Android or the server at this point sets the direction for what you learn next.

Mistakes beginners make in Kotlin

Assigning null to a variable that does not allow it
var city: String = null is refused at compile time with a message that null cannot be a value of the non-null type String. This is the whole point of Kotlin's type system, not the compiler being awkward. If a value can be missing, declare it as String? and handle the missing case where you use it.
Calling a method on a nullable value
Given var city: String?, writing city.length fails with the message that only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver. Use city?.length, which gives null when city is null, or check for null with if first; inside that block the compiler treats city as non-null (a smart cast).
Reaching for !! to make the error go away
The !! operator tells the compiler you are certain a value is not null. If you are wrong, the program crashes with a NullPointerException at run time, exactly the failure the type system was preventing. Treat !! as a last resort rather than a fix.
Writing a Java-style for loop
for (i = 0; i < 10; i++) does not exist in Kotlin and produces a confusing syntax error. Loop over a range instead, for (i in 0 until 10) or for (i in 0..<10), or use repeat(10) { } when the index does not matter.
Expecting kotlinc hello.kt to run the program
That command only compiles: it writes HelloKt.class to the current folder and exits without printing anything. To see output, compile with -include-runtime -d hello.jar and run java -jar hello.jar, or let an IDE do both steps.

Strengths and trade-offs

Where it is strong

  • Null safety is built into the types, so a whole class of crashes is caught by the compiler before the program runs.
  • Concise without being cryptic: type inference, data classes, default arguments and string templates remove much of the boilerplate of Java.
  • Full access to the Java ecosystem, plus first-class support in Android's official tooling.
  • Coroutines let asynchronous code (network calls, timers, background work) read almost like ordinary sequential code.

Where it is not

  • Compile and build times are longer than for interpreted languages, and Gradle-based projects can take a while to set up and understand.
  • The language has many features, including operator overloading, extension functions, delegation and DSL builders, and code that uses all of them can be hard for a beginner to read.
  • Outside Android and the JVM, Kotlin is a smaller world. Kotlin Multiplatform is maturing, but for iOS-only work, web front ends or data science, other languages have the depth.
  • Learning Kotlin for Android also means learning Android itself: activities, lifecycles, Compose and Gradle. That is a larger job than the language.

Who Kotlin is for

Kotlin is the right choice if you want to build Android apps: it is what the platform's documentation, samples and tooling assume. It is also a strong next language for anyone who knows Java or works with JVM systems, and a reasonable first language if you like a compiler that catches mistakes before the program runs. Look elsewhere if your goal is iPhone apps only (Swift), the web front end (JavaScript or TypeScript) or data and machine learning (Python); Kotlin can reach some of those, but it is not the natural fit.

Questions about learning Kotlin

Do I need to learn Java before Kotlin?
No. Kotlin is a complete language with its own syntax and standard library, and Android's own tutorials teach it directly. Knowing Java helps you read older Android code and library documentation, which is often written for Java, but you can pick that up as you go rather than first.
Can I build iPhone apps with Kotlin?
Partly. Kotlin Multiplatform lets you share the non-visual parts of an app, such as data, networking and business rules, between Android and iOS, and Compose Multiplatform extends that to shared user interface. Many teams still write the iOS interface in Swift and share only the logic. If iOS is your only target, Swift is the direct route.
Is Kotlin only for Android?
No. It began as a general JVM language and is used for servers, command-line tools and build scripts. Android is where most Kotlin developers are, so most learning material leans that way, but the language itself is not tied to it.
Why does nothing happen when I run kotlinc hello.kt?
Because that only compiles. It produces a class file (HelloKt.class) and exits. To run the program, either compile into a jar with -include-runtime -d hello.jar and run java -jar hello.jar, or open the file in an IDE and press Run, which does both steps. This catches nearly everyone the first time.

The primary source

When this guide and the official documentation disagree, the documentation is right and we would like to hear about it.

Other languages

All languages and paths · Programming glossary · Your progress