I am learning Kotlin and would like to understand how the compiled code gets executed, and how is it different from Java code execution with Android.
I also want to know why we write MainActivity::class.java (class.java) to reference class file.
Thank you!
how is it different from Java code execution with Android
It isn't. Android doesn't execute Java code or Kotlin code. Instead there is the following chain:
Java/Kotlin/Scala/etc. compiler takes Java/Kotlin/Scala code and emits JVM bytecode in .class files.
Android Gradle plugin takes JVM bytecode, converts it to Dalvik bytecode (using dx program) and packs it into .apk.
When the .apk file is installed on device, ART converts Dalvik bytecode it contains to machine code.
It's that machine code (and/or Dalvik bytecode) which is executed. ART has no idea which language source code was in at step 1 and doesn't care.
I also want to know why we write MainActivity::class.java (class.java) to reference class file.
You don't. You write it to reference the Class object corresponding to the MainActivity class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With