Part 2 · 1 chapters · ~8 min
The JVM and Kotlin Runtime
Kotlin compilation to JVM bytecode and the K2 compiler, what data classes, properties and lambdas compile to (javap), the kotlin-stdlib, Java interop and annotations, inline functions and reified generics, garbage collection and JIT shared with Java, startup and native images (GraalVM), and Kotlin Multiplatform.
3
What the compiler emits
code
kotlinc-jvm Transfer.kt -d out && javap -p out/Transfer.class
# public final class Transfer {
# private final java.lang.String id; private final long amountKobo; …
# public final java.lang.String getId(); ← properties become getters
# public final Transfer copy(java.lang.String, long, Channel, Status);
# public boolean equals(java.lang.Object); public int hashCode(); public java.lang.String toString();
# public final java.lang.String component1(); ← destructuring support
# }
inline fun <reified T> parse(json: String): T = mapper.readValue(json, T::class.java) // reified: T known at runtime
@JvmOverloads fun charge(amount: Long, currency: String = "NGN") { … } // Java sees two overloadsBecause Kotlin runs on the JVM, the Java course's parts on the JVM, garbage collectors, virtual threads, profiling and production apply unchanged. Kotlin coroutines and Java 21 virtual threads both solve blocking I/O at scale; coroutines add structured concurrency and Flow (next part).
KOTLIN ON THE JVM
the same bytecode, extra runtime pieces
swipe the figure sideways, or tap expand for full screen
1/4
compile
Kotlin compiles to ordinary JVM bytecode (the K2 compiler is the default since Kotlin 2.0), so it runs anywhere Java runs and benefits from the same JIT and garbage collectors (Java course P2).
plain JVM bytecodeK2 since 2.0