Kotlin Introduction

Kotlin · Lesson 1 of 29 7 min read Updated

Kotlin is a modern programming language that runs almost everywhere: on Android phones, on web servers, on desktop computers, in the browser and even inside iPhone apps. If you use a banking app, a food delivery app or a cab booking app on Android, there is a good chance part of it was written in Kotlin.

In this lesson you will learn what Kotlin is, where it is used, how a Kotlin program runs, and why it has become so popular. You will also read your first few lines of Kotlin code.

What is Kotlin?

Kotlin is a general-purpose, statically typed programming language. General-purpose means you can use it to build many kinds of software, not just one. Statically typed means every value has a type (a number, a piece of text, a list) that the compiler checks before your program runs, so many mistakes are caught early.

Kotlin was created by JetBrains, the company that makes the IntelliJ IDEA code editor. The project was announced in 2011, and version 1.0 was released in February 2016. The language is open source under the Apache 2.0 licence, and the Kotlin Foundation (set up by JetBrains and Google) looks after its future.

Here is a complete Kotlin program. You do not need to understand every word yet.

Kotlin
fun main() {
    val city = "Pune"
    val students = 42
    println("Hello from $city!")
    println("Our batch has $students students.")
}
Output
Hello from Pune!
Our batch has 42 students.

fun main() is where the program starts. val creates a named value, and println prints a line. The $city inside the text is a string template: Kotlin replaces it with the value of city. Notice there are no semicolons at the end of lines; Kotlin does not need them.

Where Kotlin is used

Kotlin started as a better language for the Java Virtual Machine (JVM), but today it has several targets, which means it can be turned into code for different platforms:

TargetWhat it producesTypical use
Kotlin/JVMJava bytecode that runs on the JVMAndroid apps, web servers, desktop apps
Kotlin/NativeMachine code for a specific systemiOS apps, command-line tools
Kotlin/WasmWebAssembly for browsersWeb apps
Kotlin/JSJavaScriptWeb front ends

The three biggest areas are:

  • Android. Google announced official Kotlin support for Android in 2017, and in 2019 it said Android development would be Kotlin-first. Jetpack Compose, Android's modern toolkit for building screens, works only with Kotlin.
  • Servers. Kotlin runs on the JVM, so it works with the huge Java ecosystem. Spring Boot fully supports Kotlin, and Ktor is a server framework built by JetBrains in Kotlin.
  • Multiplatform. With Kotlin Multiplatform, you write business logic once and share it between Android, iOS, desktop and web apps. Compose Multiplatform lets you share the user interface too.

You will meet Android and Multiplatform near the end of this course in Android with Jetpack Compose and Kotlin Multiplatform.

How a Kotlin program runs

You write Kotlin in files that end with .kt. A program called the compiler (kotlinc, or the one built into your editor) reads these files, checks them for errors and translates them. For the JVM target, the result is bytecode packed into a .jar file, which the Java runtime then runs. This is the same runtime that runs Java programs, which is why Kotlin and Java code can live in one project and call each other.

The current compiler is called K2. It became the default in Kotlin 2.0 (May 2024), and it is faster and smarter than the old one. You will learn what changed in The K2 Compiler & What Changed.

Why developers like Kotlin

Less code for the same job

Here is a small Java class that stores a student's name and marks. It needs a constructor, getters and a toString method:

Java
public class Student {
    private final String name;
    private final int marks;

    public Student(String name, int marks) {
        this.name = name;
        this.marks = marks;
    }

    public String getName() { return name; }
    public int getMarks() { return marks; }

    @Override
    public String toString() {
        return "Student(name=" + name + ", marks=" + marks + ")";
    }
}

In Kotlin, one line gives you all of that, plus equality checks and a copy function:

Kotlin
data class Student(val name: String, val marks: Int)

fun main() {
    val ananya = Student("Ananya", 91)
    println(ananya)
    println(ananya.copy(marks = 95))
}
Output
Student(name=Ananya, marks=91)
Student(name=Ananya, marks=95)

Modern Java has records, which also shorten this class. Kotlin's advantage is that this kind of brevity runs through the whole language.

Safety from null errors

In many languages, a variable can secretly hold "nothing" (null), and using it crashes the program. Kotlin's type system tracks which values may be null and forces you to handle them.

Kotlin
fun main() {
    val nickname: String? = null
    println(nickname?.length ?: 0)
}
Output
0

The ? after String says "this may be null". ?. and ?: handle the missing value safely. You will learn these properly in Null Safety.

Other strengths

  • Java interoperability: you can use any Java library from Kotlin, and Java code can call Kotlin.
  • Coroutines: a simple way to write code that waits for networks or files without freezing your app.
  • Great tools: IntelliJ IDEA and Android Studio understand Kotlin deeply, with smart completion and refactoring.

Kotlin versions

This course teaches Kotlin 2.4. Kotlin 2.4.0 came out in June 2026, and small bug-fix updates such as 2.4.21 follow it. JetBrains ships a new language version (2.2, 2.3, 2.4...) about every six months, with tooling and bug-fix releases in between.

Common mistakes

  • Thinking Kotlin is only for Android. Android is its best-known use, but Kotlin is equally at home on servers, desktops and in shared multiplatform code.
  • Thinking you must learn Java first. You do not. This course starts from zero. Knowing a little Java helps with interop later, but it is not required.
  • Adding semicolons everywhere. They are allowed but not needed. Leave them out, as Kotlin developers do.

Key points

  • Kotlin is a modern, statically typed, open-source language created by JetBrains (1.0 in 2016).
  • It compiles to JVM bytecode, native machine code, WebAssembly and JavaScript.
  • Android development is Kotlin-first, and Jetpack Compose works only with Kotlin.
  • Kotlin is also used for servers (Spring Boot, Ktor) and shared code with Kotlin Multiplatform.
  • Its main strengths are concise code, null safety, Java interop and coroutines.
  • This course teaches Kotlin 2.4, which uses the K2 compiler.

Exercise

Look at the first program in this lesson. Without running it, write down what it would print if you changed city to "Kochi" and students to 35. Then write a new main function that stores your own name and favourite cricket player in two vals and prints one sentence using both.

Show solution

After the change, the program prints Hello from Kochi! and Our batch has 35 students.

Kotlin
fun main() {
    val name = "Rohan"
    val player = "Smriti Mandhana"
    println("$name's favourite player is $player.")
}
Output
Rohan's favourite player is Smriti Mandhana.

Each $name inside the quotes is replaced by the value stored in that val.

Quick Quiz

1. Which company created Kotlin?

2. What does "statically typed" mean?

3. Which file extension do Kotlin source files use?

4. What does Kotlin/JVM produce?

Learn Kotlin with a mentor

Free lessons get you started. Our Programming & Software Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call