Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Kotlin
Stage 5: Specialization

Part 12 / Topic 7 of 7

Using a plain JDK API from Kotlin

Most of "the JVM ecosystem" is simply this: huge, battle-tested Java libraries (starting with the JDK itself) that Kotlin uses with zero wrapper code, because Kotlin is JVM bytecode underneath. java.text.NumberFormat and java.time need nothing Kotlin-specific at all:

val indiaLocale = Locale.Builder().setLanguage("en").setRegion("IN").build()
val formatter = NumberFormat.getCurrencyInstance(indiaLocale)
println(formatter.format(140.0))

val joinedOn = LocalDate.of(2023, 11, 20)
val referenceDate = LocalDate.of(2026, 12, 1)
val membership = Period.between(joinedOn, referenceDate)
println("Member for ${membership.years} years, ${membership.months} months")
₹140.00
₹1,999.50
Member for 3 years, 0 months

(The older Locale("en", "IN") two-string constructor still compiles, but kotlinc flags it deprecated — Locale.Builder() is the current, warning-free way to build one.) Stage 4's design notes make the same point about java.util.PriorityQueue: when Kotlin's own standard library doesn't have something, reaching for the JDK (or a Java library from Maven Central) is the normal, idiomatic choice — not a fallback to apologize for.

Full file: examples/interop-project/PlainJdkApi.kt.

Done here? The practice set for Part 12 — including the solutions — is on the part page.

Search the guide