Kotlin code is turned into JVM bytecode so it can run on any device with a Java Virtual Machine. This makes Kotlin programs work on many platforms easily.
How Kotlin compiles to JVM bytecode
kotlinc MyProgram.kt -include-runtime -d MyProgram.jar java -jar MyProgram.jar
kotlinc is the Kotlin compiler command.
-include-runtime adds the Kotlin runtime to the output jar so it can run standalone.
Hello.kt to a jar file and run it with Java.kotlinc Hello.kt -d Hello.jar java -jar Hello.jar
MyApp.kt including Kotlin runtime in the jar, so it runs without extra setup.kotlinc MyApp.kt -include-runtime -d MyApp.jar java -jar MyApp.jar
This simple Kotlin program prints a message. When compiled, it becomes JVM bytecode that the Java Virtual Machine can run.
fun main() { println("Hello from Kotlin JVM bytecode!") }
The Kotlin compiler converts your Kotlin code into JVM bytecode, which is a set of instructions the Java Virtual Machine understands.
You can run the compiled Kotlin program anywhere Java runs, making Kotlin very flexible.
Using -include-runtime helps create a jar file that runs without needing to add Kotlin libraries separately.
Kotlin code is compiled into JVM bytecode to run on the Java Virtual Machine.
This allows Kotlin programs to work on many devices and platforms that support Java.
The Kotlin compiler command kotlinc creates the bytecode and packages it for running.