Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
The Fundamentals  ›  Lesson

Kotlin or Java?

Kotlin 10 minNew Android code is written in Kotlin, while Java remains fully supported and can live in the same project because both compile to the same bytecode.

Kotlin or Java?

You are about to build Sprout, a small app that reminds you when to water your plants. Before the first line, you must pick a language. Android gives you two real choices, and the decision is easier than it looks.

The rule

Write new code in Kotlin; Java still runs beside it.

Kotlin is Google's recommended language for Android. Most new libraries, documentation and samples are written for it, and Jetpack Compose, the modern way to build screens, can only be used from Kotlin.

Java was Android's original language. Millions of lines of existing apps are written in it, and it is still fully supported.

The two are not rivals inside a project. Both compile to JVM bytecode, which the Android build then turns into DEX files that the device runs. So a Kotlin class can call a Java class and the other way round:

// Kotlin file calling an old Java helper
val days = WateringCalculator.daysUntilDry(plant) // WateringCalculator.java

Kotlin also removes whole groups of bugs: types are non-null unless you add ?, so the compiler catches many null mistakes before the app ever runs.

The shortcut

Ask one question: is this new code, or existing code?

Choosing a language for SproutStep 1 of 4
  1. New screen

    You are writing the plant list from scratch. New code → Kotlin, and you can use Compose.

The trap is thinking you must rewrite a Java app before adding Kotlin. You never have to: mixing is normal.

Drills

Answer fast — trust the rule.

quick drill

Which language does Google recommend for new Android code?

quick drill

A project has 40 Java files. Can you add a new Kotlin file to it?

quick drill

Why can Kotlin code call a Java class directly?

quick drill

You want to build Sprout's screens with Jetpack Compose. Which language must those screens use?

Remember

  • Write new code in Kotlin; Java still runs beside it.
  • New code → Kotlin. Existing working Java → leave it, convert when you touch it.
  • Never rewrite a Java app just to start using Kotlin.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainAdvise a new teammate

A new teammate asks whether they should learn Kotlin or Java to start building Sprout, an app whose older screens are written in Java. Advise them and explain why the Java code does not have to be rewritten first.