EMZETT.
Login

Kotlin

In short: A modern, more concise alternative to Java on the JVM — Google’s recommended language for native Android development since 2019.

In more detail: Kotlin is compatible with Java (can produce the same bytecode, interact with Java libraries), but avoids many of Java’s weaknesses and awkwardness (e.g. built-in null safety against NullPointerExceptions, shorter syntax). Increasingly used outside Android too, as a general-purpose JVM language.

In Depth

Null safety as a core feature

fun greeting(name: String?): String {
    return "Hello, ${name ?: "Unknown"}"
}
 
// Data class - considerably shorter than Java's equivalent
data class User(val name: String, val age: Int)
 
val user = User("Anna", 28)
val (name, age) = user // destructuring

Kotlin’s best-known improvement over Java is built-in null safety: in Kotlin’s type system, the type of a value already states whether it’s allowed to be null (String?) or is guaranteed not to be null (String) — the compiler refuses code that tries to access a possibly-null value without a prior check. This takes the wind out of the sails of the notorious NullPointerException (jokingly called the “billion-dollar mistake” in Java circles, since its inventor Tony Hoare himself called its 1965 introduction his most expensive mistake) already at compile time.

More concise syntax

Besides null safety, Kotlin generally considerably reduces boilerplate code compared to Java: data classes (data class) automatically generate a constructor, getters, equals(), hashCode() and toString(), for which Java would need considerably more manually written (or generated) code. Missing semicolons, automatic type inference (val x = 5 instead of int x = 5), and lambda expressions as a first-class feature also often make typical Kotlin code 30-40% shorter than equivalent Java code.

Interoperability and gradual migration

Because Kotlin is 100% interoperable with Java (both compile to the same JVM bytecode, can call each other within the same project), it can be introduced gradually into existing Java projects — writing new classes in Kotlin while old Java code keeps running unchanged, instead of having to do a risky complete migration all at once. This was an important reason for its rapid adoption since Google declared Kotlin the preferred language for native Android development in 2019 (before that, Java was the de-facto standard for native Android apps).

Beyond Android

Kotlin originally comes from the company JetBrains (maker of well-known development environments like IntelliJ IDEA) and is increasingly used outside Android too, as a general-purpose JVM language — for backend development (e.g. with the Spring framework), or even, via Kotlin Multiplatform, for code that runs simultaneously on Android, iOS and the web.

See also: Android, Java