Why Java and Kotlin can work together

Why Java and Kotlin can work together

If you are new to Java or Kotlin, you might be wondering what creates the good flow between those two languages. Before we get to the advanced and more awesome stuff, it is important for a beginner to grasp the concept of how it works behind the hood. I will explain it to you in the matter of two minutes of your lifetime: Inside of Android Studio for example, you can seamlessly convert between the two languages and even combine them. This obviously has a reason.


The JVM (Java Virtual Machine) is a virtual machine (who would have guessed it?), which runs beneath Java and Kotlin. Java and Kotlin are smart. They use what is called Bytecode. Bytecode is a set of instructions, which are platform independent. This means, that they can be reused on Linux, Windows or Macintosh.

As soon as you compile Java or Kotlin, instead of looking at the machine you are running on and having to spit out different instructions for different machines, they convert the language to Bytecode Instructions, which can be used anywhere.

Now comes the JVM into play.

The JVM is reponsible for converting Bytecode into the machine specific instructions. It looks on which machine it is running and then converts the Bytecode instructions to chip-specific ones. This can be a reason why Java and Kotlin have a bit of a delay between actually compiling your program and executing it on your machine.



This is a simplified graph-flow, which illustrates what I just explained to you. But despite all things going on, the JVM itself is pretty quick. A reason for this is, that it is able to take in all instructions and seamlessly convert them, without having to go through a syntax check.

And this very simple yet important concept is why Java and Kotlin work together: They get converted into the exact same Bytecodes, which then get processed by the JVM. Thus, giving us the power we need to create applications.

But it is really a good idea to mix Java and Kotlin together?

From my point of view, it is not. Why should you? Java is old and robust, but Kotlin gives us the power to achieve results in a more conventient way, and allowing us to do so, while preseventing us from runtime errors. The good thing is, that inside of Android Studio you can go from a Java file to a Kotlin file in the click of a button.

Not interfering with any behaviour of your program!

Leave a Reply

Your email address will not be published. Required fields are marked *