beginner15 min

Java Interop and Where Kotlin Is Used Today

How Kotlin and Java code call each other, and Kotlin's real-world usage today.

What you'll learn

  • Explain how Kotlin code can call Java libraries and vice versa
  • Describe Kotlin's role in modern Android development
  • Identify backend frameworks (Ktor, Spring) that support Kotlin

Explanation

Because Kotlin compiles to the same JVM bytecode as Java, interop is seamless in both directions: a Kotlin file can call any Java class or library directly with no wrapper needed, and Java code can call Kotlin classes and (top-level) functions almost as naturally (Kotlin generates the necessary JVM-compatible signatures automatically). This is a major reason Kotlin was adoptable incrementally -- an existing Java codebase can introduce Kotlin file-by-file without a disruptive rewrite.

Android: Google announced Kotlin as a first-class language for Android development in 2017 and now recommends it as the preferred language for new Android apps, with Jetpack Compose (Android's modern UI toolkit) built Kotlin-first.

Backend: Kotlin is increasingly used server-side too, with frameworks like Ktor (a lightweight framework built specifically for Kotlin, using coroutines for async request handling) and Spring (the long-established Java framework, which added first-class Kotlin support).

One practical consequence of interop: when calling into Java code from Kotlin, a Java type without Kotlin's null-safety annotations is treated as a "platform type" -- Kotlin can't guarantee whether it's nullable, so you're responsible for handling it carefully (the null-safety guarantees from earlier in this course apply fully within Kotlin code, but are less automatic right at a Java interop boundary).

Guided lab

Predict: Calling a Java-style utility from Kotlin

KotlinNot executed
This lab does not run in your browser or on VisaSparkSchools's servers. Read the code, predict what it does, then reveal the real expected output.

This models a Kotlin file calling a method on a Java-style utility class (java.time.LocalDate is a real JDK class). Predict what it prints.

import java.time.LocalDate

fun main() {
    val today = LocalDate.of(2026, 8, 7)
    val nextWeek = today.plusDays(7)
    println("Today: $today")
    println("Next week: $nextWeek")
}

Stuck? Get a hint.

Common mistakes

  • Assuming Kotlin requires rewriting an entire existing Java codebase before it can be introduced -- interop allows adopting it file-by-file.
  • Assuming Kotlin's null-safety guarantees automatically extend to values coming from Java code -- Java types crossing into Kotlin are 'platform types' needing careful handling.
  • Thinking Kotlin is Android-only in practice today -- Ktor and Spring both support real backend development in Kotlin.

Knowledge check

Knowledge check

1. Can a Kotlin file call a Java library directly, with no wrapper code?
2. Which of these is a Kotlin-first backend web framework?
3. What is a 'platform type' in Kotlin?

Takeaway

Kotlin interoperates directly with Java (enabling incremental adoption), and is used today for both Android (its original strength) and backend services (via Ktor/Spring).

Summary

Kotlin/Java interop is bidirectional and seamless; Kotlin is Android's preferred language and is increasingly used for backend services via Ktor and Spring.

References

Your notes

Notes save automatically.

Finished this lesson?

Mark it complete to track your progress and schedule a future review.