Kotlin is a statically typed, general-purpose programming language developed by JetBrains that compiles to JVM bytecode, JavaScript, WebAssembly and native machine code. Among modern programming languages, it is best known as the preferred language for Android development and as a concise, safer alternative to Java that remains fully interoperable with existing Java code.
Kotlin combines object-oriented and functional programming, adds null safety to the type system and offers coroutines for asynchronous code. The project became open source in 2012, reached version 1.0 in 2016 and moved to the K2 compiler with Kotlin 2.0 in 2024.
How Kotlin compiles and runs
Kotlin source code is processed by a single compiler front end and then handed to one of several back ends, each targeting a different platform. The most widely used back end emits Java bytecode, so Kotlin programs run on any Java Virtual Machine and can call Java libraries directly, while Java code can call Kotlin classes in return.
The other back ends make Kotlin a multiplatform language. Kotlin/Native uses LLVM to produce standalone binaries for iOS, macOS, Linux and Windows, while Kotlin/JS and Kotlin/Wasm target browsers and JavaScript runtimes. The following table summarizes the compilation targets.
| Target | Output | Typical use |
|---|---|---|
| Kotlin/JVM | Java bytecode | Android apps, backend services |
| Kotlin/Native | Native binaries via LLVM | iOS apps, command-line tools |
| Kotlin/JS | JavaScript code | Web front ends, Node.js |
| Kotlin/Wasm | WebAssembly modules | High-performance browser code |
Kotlin Multiplatform builds on these targets by letting a project share business logic, networking and data layers across platforms, while each platform keeps its own native user interface. The expect and actual declarations define where shared code needs a platform-specific implementation.
Key language features
Kotlin was designed to remove common sources of boilerplate and runtime failures found in older JVM languages. Its features target safety, conciseness and readability rather than novelty, and most of them have no runtime cost.
| Feature | What it does | Problem it addresses |
|---|---|---|
| Null safety | Separates nullable String? from non-null String | Null pointer exceptions |
| Data classes | Generate equals, hashCode and copy automatically | Repetitive value-object code |
| Type inference | Derives types from assigned values | Verbose declarations |
| Extension functions | Add methods to existing classes | Utility classes and wrappers |
| Sealed classes | Restrict a hierarchy to known subtypes | Incomplete conditional handling |
| Coroutines | Write asynchronous code sequentially | Callback nesting and thread overhead |
Null safety is the most influential of these features. The compiler refuses to dereference a nullable value until the code proves it is not null, using safe calls (?.), the Elvis operator (?:) or smart casts after an explicit check. The non-null assertion operator !! bypasses this protection and should be rare in well-written code.
Coroutines provide lightweight concurrency built around suspending functions. Thousands of coroutines can run on a small thread pool, and structured concurrency ties each coroutine to a scope, so cancellation and error handling propagate predictably instead of leaking background work.
Kotlin compared with Java and other languages
Kotlin is most often compared with Java, because both share the same runtime and ecosystem, and with Swift, because the two languages fill similar roles on mobile platforms. The table below highlights the practical differences.
| Aspect | Kotlin | Java | Swift | Scala |
|---|---|---|---|---|
| Null handling | In the type system | Annotations and Optional | In the type system | Option type |
| Primary platforms | JVM, Android, multiplatform | JVM | Apple platforms | JVM |
| Asynchronous model | Coroutines | Virtual threads | async and await | Futures and libraries |
| Learning curve | Moderate | Moderate | Moderate | Steep |
| Java interoperability | Seamless | Native | None | Good |
Recent Java releases have narrowed the gap with records, pattern matching and virtual threads, so the choice between the two increasingly depends on team skills and platform rather than raw capability. Compared with Scala, Kotlin deliberately offers a smaller, more pragmatic feature set, which shortens onboarding and keeps compile times more predictable.
Where Kotlin is used
Kotlin is used wherever the JVM is used, and increasingly in cross-platform mobile projects. Google declared Kotlin the preferred language for Android in 2019, and modern Android libraries, including the declarative Jetpack Compose user interface toolkit, are designed Kotlin-first.
| Area | Typical tools | Why teams choose Kotlin |
|---|---|---|
| Android apps | Jetpack Compose, Android Studio | Official support and modern libraries |
| Backend services | Spring Boot, Ktor | Java ecosystem with less boilerplate |
| Shared mobile logic | Kotlin Multiplatform | One codebase for Android and iOS logic |
| Build scripts | Gradle Kotlin DSL | Type-checked, IDE-assisted configuration |
For backend work, Spring Boot supports Kotlin directly, and Ktor offers a lightweight, coroutine-based framework from JetBrains. Teams migrating from Java usually adopt Kotlin file by file, because both languages compile into the same project without wrappers.
Limitations and common mistakes
Kotlin has trade-offs that experienced teams plan for. Clean builds can be slower than equivalent Java builds, although the K2 compiler and incremental compilation reduce the difference considerably. Kotlin/Native and Multiplatform tooling are younger than the JVM toolchain, so some libraries remain JVM-only.
- Overusing `!!`: forcing non-null values reintroduces the null pointer exceptions the type system was meant to prevent.
- Platform types from Java: values returned by unannotated Java code have unknown nullability, so the compiler cannot protect them fully.
- Blocking inside coroutines: calling blocking input or output on the main dispatcher freezes the user interface; use
Dispatchers.IOinstead. - GlobalScope launches: starting coroutines outside a structured scope causes leaks and lost exceptions.
- Excessive cleverness: chaining many scope functions such as
let,applyandalsocan make code harder to read than plain statements.
The safest practice is to annotate Java APIs for nullability, keep coroutines inside lifecycle-aware scopes and agree on a team style guide for idiomatic but readable Kotlin.
In everyday language
Kotlin is a language programmers use to write apps, especially apps for Android phones. It was created to do the same jobs as Java, an older and very popular language, but with shorter and safer code.
Think of a modern kitchen fitted into an old house. The plumbing and wiring stay the same, so everything still works. The new tools simply make cooking faster and safer. Kotlin catches many mistakes before the app ever runs, which means fewer crashes for the people who use it.
Seen in the real world
A mid-sized bank maintains an Android banking app written in Java, with about 300,000 lines of code. Crash reports show that a large share of failures are null pointer exceptions, and the team also needs an iOS version that behaves identically when calculating fees and validating transfers.
The team adopts Kotlin gradually: new screens are written in Kotlin with Jetpack Compose, while existing Java classes keep working unchanged. Validation rules, fee calculations and API clients move into a Kotlin Multiplatform module that both the Android and iOS apps use, with each app keeping its own native interface.
Within a year, null-related crashes drop sharply because new code must handle missing values explicitly, data classes remove thousands of lines of boilerplate and business rules exist in one place, so an interest calculation fix ships to both platforms in a single change.