Skip to main content

Why Kotlin instead of Java?

Short answer

Kotlin is usually the better choice for a new Android project. It catches more mistakes at compile time, needs less repetitive code, has built-in coroutine support, and works with existing Java code. Java is still supported, so an existing project does not need an immediate rewrite.

The practical decision is not “Is Java bad?” It is “Will Kotlin make this team safer and more productive without creating an unnecessary migration cost?”

1. Kotlin makes nullability visible​

val length: Int? = user.nickname?.length
val displayLength: Int = length ?: 0

2. Kotlin removes repetitive code​

data class UserUi(val id: Long, val name: String)

Kotlin generates useful behavior such as equals, hashCode, toString, destructuring functions, and copy. The main benefit is not simply fewer lines—it is that the code clearly says, “This class represents data.”

Open in Kotlin Playground

3. Coroutines make asynchronous work easier to structure​

A coroutine can pause while waiting without blocking its thread. Android scopes such as viewModelScope also give the work an owner: when the ViewModel is cleared, its child coroutines are cancelled.

fun refresh() = viewModelScope.launch {
val result = repository.refreshUser()
// update immutable UI state
}
Important limitation

Coroutines do not make blocking work non-blocking automatically. A blocking call still occupies its thread.

4. Incremental interoperability​

Kotlin and Java can coexist in one Android module. Add accurate Java nullability annotations, prevent platform types from spreading, and test APIs from both languages when both are consumers.

Should an existing Java app be rewritten?​

Usually, no. Keep stable Java code that works. Introduce Kotlin for new features or while changing code for a real reason. A migration is valuable when it improves safety, maintenance, or delivery—not merely because Kotlin is newer.

Interview-ready answer

Kotlin is preferred for modern Android because it has null-safety, concise data and collection APIs, coroutines, strong Android tooling, and full Java interoperability. Java remains supported. For an existing app, I would migrate incrementally instead of rewriting stable code without a business reason.

Interview question​

Is Kotlin always faster and completely safe from NPEs?

No. Performance depends on generated bytecode, allocations, algorithms and workload. Kotlin can still encounter NPEs through not-null assertions, platform types, Java interoperability, initialization mistakes, or explicit throws.