Kotlin on JVM: A Beginner-Friendly Guide

Kotlin on JVM: A Beginner-Friendly Guide

Ever wondered on how does Kotlin works on JVM? Isn’t only Java supposed to work on JVM?

If you ever thought so this article will help you clear those questions.

Quick overview on what JVM is. JVM stands for Java Virtual Machine and it provides a run time environment for java bytecode to run. Earlier it was only used for Java but nowadays languages such as Kotlin, Scala etc also uses JVM to run it’s code.

No alt text provided for this image

All Kotlin class files has?.kt?extension and this is equivalent to the?.java?extension whenever you write code in Java. As JVM only understands bytecode, kotlin compiler converts all?.kt?files which are human readable code into?.class?files which are files containing machine instructions. Once?.class?files is created the next step is to package all the?.class?files into a jar. After the jar is ready we can run in it Java Runtime Environment.

As JVM defines how binary?class?files needs to be executed along with certain other instructions. It translates to JVM is programming language independent and only requires proper?class?files. Thus, making Kotlin run on JVM.

Summary

At times it is interesting to look what happens in the background. By compiling Kotlin code into bytecode it makes it compatible with JVM.

Now, we have learned about on how Kotlin works on JVM. Stay tuned for next to learn about variables in Kotlin!

要查看或添加评论,请登录

Manpreet Kaur的更多文章

社区洞察

其他会员也浏览了