Kotlin
Overview
Kotlin is a concise, statically typed, multiplatform language developed by JetBrains. It runs primarily on the JVM with full two-way interoperability with Java, and also targets Android, native, and other platforms. It emphasizes null safety, expressive syntax, and structured concurrency via coroutines. Read this for null safety, coroutines, and the recommended getting-started path.
Official sources
Install / setup
Kotlin ships with every IntelliJ IDEA and Android Studio release, so installing one of those IDEs is the recommended way to start (per the getting-started page). To install the standalone command-line compiler via SDKMAN! (per https://kotlinlang.org/docs/command-line.html):
sdk install kotlin
Core concepts
- Null safety: types are non-nullable by default; nullable types are marked with
?, and the compiler forces you to handle null.
- Concise syntax: type inference, data classes, properties, and expression bodies reduce boilerplate versus Java.
- Java interoperability: Kotlin calls Java and Java calls Kotlin seamlessly, easing incremental adoption in existing JVM codebases.
- Coroutines: lightweight, structured concurrency with
suspend functions for non-blocking asynchronous code.
- Extension functions: add functions to existing types without inheritance or modifying the original class.
- Immutability by default intent:
val (read-only) vs. var (mutable); prefer val.
- Smart casts and
when: after a type/null check the compiler auto-casts; when is a powerful expression-based branch.
Best practices
- Prefer
val over var and immutable collections to make state explicit and reduce bugs.
- Use the null-safety operators (
?., ?:, !! sparingly) instead of defensive null checks; avoid !! except where null is truly impossible.
- Use coroutines with structured concurrency (scopes) for async work rather than raw threads or callbacks.
- Model data with
data class and represent restricted hierarchies with sealed classes for exhaustive when.
Common pitfalls
- Overusing the
!! not-null assertion → it throws NPE at runtime, defeating null safety; prefer ?./?: or restructure.
- Platform types from Java (
String!) → Java values have unknown nullability; annotate or guard them at the boundary.
- Launching coroutines without a proper scope → can leak work; use lifecycle/structured scopes so they are cancelled correctly.
- Assuming
== is identity → in Kotlin == calls equals (structural); use === for referential equality.
Examples
fun greet(name: String?): String {
return "Hello, ${name ?: "guest"}"
}
fun main() {
println(greet("Ada"))
println(greet(null))
}
Further reading
Related skills
- ../java — the JVM language Kotlin interoperates with
1---2name: kotlin3description: Concise, modern JVM language fully interoperable with Java; consult for null safety, coroutines, and tooling.4domain: language5category: language6tags: [kotlin, jvm, null-safety, coroutines, multiplatform]7official_sources:8 - https://kotlinlang.org/docs/home.html9 - https://github.com/JetBrains/kotlin10 - https://kotlinlang.org/docs/getting-started.html11verified: 2026-06-1612metadata:13 source: https://skillmd.com/skills/gabriel7silva/kotlin14---1516# Kotlin1718## Overview19Kotlin is a concise, statically typed, multiplatform language developed by JetBrains. It runs primarily on the JVM with full two-way interoperability with Java, and also targets Android, native, and other platforms. It emphasizes null safety, expressive syntax, and structured concurrency via coroutines. Read this for null safety, coroutines, and the recommended getting-started path.2021## Official sources22- Docs: https://kotlinlang.org/docs/home.html23- Repo: https://github.com/JetBrains/kotlin24- Getting started: https://kotlinlang.org/docs/getting-started.html2526## Install / setup27Kotlin ships with every IntelliJ IDEA and Android Studio release, so installing one of those IDEs is the recommended way to start (per the getting-started page). To install the standalone command-line compiler via SDKMAN! (per https://kotlinlang.org/docs/command-line.html):28```bash29sdk install kotlin30```3132## Core concepts33- Null safety: types are non-nullable by default; nullable types are marked with `?`, and the compiler forces you to handle `null`.34- Concise syntax: type inference, data classes, properties, and expression bodies reduce boilerplate versus Java.35- Java interoperability: Kotlin calls Java and Java calls Kotlin seamlessly, easing incremental adoption in existing JVM codebases.36- Coroutines: lightweight, structured concurrency with `suspend` functions for non-blocking asynchronous code.37- Extension functions: add functions to existing types without inheritance or modifying the original class.38- Immutability by default intent: `val` (read-only) vs. `var` (mutable); prefer `val`.39- Smart casts and `when`: after a type/null check the compiler auto-casts; `when` is a powerful expression-based branch.4041## Best practices42- Prefer `val` over `var` and immutable collections to make state explicit and reduce bugs.43- Use the null-safety operators (`?.`, `?:`, `!!` sparingly) instead of defensive null checks; avoid `!!` except where null is truly impossible.44- Use coroutines with structured concurrency (scopes) for async work rather than raw threads or callbacks.45- Model data with `data class` and represent restricted hierarchies with `sealed` classes for exhaustive `when`.4647## Common pitfalls48- Overusing the `!!` not-null assertion → it throws NPE at runtime, defeating null safety; prefer `?.`/`?:` or restructure.49- Platform types from Java (`String!`) → Java values have unknown nullability; annotate or guard them at the boundary.50- Launching coroutines without a proper scope → can leak work; use lifecycle/structured scopes so they are cancelled correctly.51- Assuming `==` is identity → in Kotlin `==` calls `equals` (structural); use `===` for referential equality.5253## Examples54```kotlin55fun greet(name: String?): String {56 return "Hello, ${name ?: "guest"}"57}5859fun main() {60 println(greet("Ada"))61 println(greet(null))62}63```6465## Further reading66- Kotlin Tour: https://kotlinlang.org/docs/kotlin-tour-welcome.html67- Coroutines guide: https://kotlinlang.org/docs/coroutines-guide.html6869## Related skills70- ../java — the JVM language Kotlin interoperates with