Programming languages

Kotlin

A modern concise language for the JVM, Android and multiplatform development, fully interoperable with Java.

What it is

JetBrains created Kotlin. It was announced in 2011, and stable 1.0 shipped in 2016. In 2019 Google made Kotlin the preferred language for Android development.

It compiles to JVM bytecode, and also to JavaScript and native code (Kotlin Multiplatform). Kotlin and Java code call each other freely, so migration can be gradual.

The language removes typical Java noise: data classes, null safety in the type system, extension functions, coroutines for async. It is used for Android, backends (Spring, Ktor) and Compose Multiplatform.

Use it when

  • A native Android app: it is the recommended language.
  • A JVM backend where you want less boilerplate than Java.
  • Shared business logic across Android, iOS and web with Kotlin Multiplatform.

Avoid it when

  • A team with no JVM experience and a need for minimal build time: compilation is slower than Java.
  • Tight limits on binary size or startup, as in small CLIs.

Key concepts

Null safety
A String cannot be null, a String? can. The compiler forces you to check.
Data class
A data holder class with automatic equals, hashCode, toString and copy.
Coroutines
Lightweight async through suspend functions instead of callbacks and threads.
Extension function
Adds a method to an existing type without inheritance.
Kotlin Multiplatform
Shared code for JVM, Android, iOS and web with platform-specific parts.

Example

A data class and safe handling of a nullable value.

Interview questions

  1. 1. How does Kotlin handle null?

    Nullable types are marked with ?. The compiler does not allow calling a method on a nullable without a check, and the ?., ?: and let operators make it convenient. This removes most NullPointerExceptions.

  2. 2. What are coroutines?

    An async mechanism where a suspend function can pause without blocking a thread. Code reads sequentially, and runs through launch or async in a scope.

  3. 3. val or var?

    val is an immutable reference, var is mutable. Kotlin style prefers val by default.

  4. 4. Can Kotlin and Java mix in one project?

    Yes, they compile to the same bytecode and call each other. That is why projects migrate gradually.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).