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
Stringcannot be null, aString?can. The compiler forces you to check. - Data class
- A data holder class with automatic equals, hashCode, toString and copy.
- Coroutines
- Lightweight async through
suspendfunctions 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
Interview questions
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?.,?:andletoperators make it convenient. This removes most NullPointerExceptions.2. What are coroutines?
An async mechanism where a
suspendfunction can pause without blocking a thread. Code reads sequentially, and runs throughlaunchorasyncin a scope.3. val or var?
valis an immutable reference,varis mutable. Kotlin style prefersvalby default.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.
Related technologies
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).