Kotlin Tutorial: Kotlin Architecture & Interoperability

In this tutorial, we will discuss the architecture of Kotlin programming language and its Interoperability feature. As you know we write Kotlin code in .kt file. Kotlin compiler converts that Kotlin code written in .kt file into byte code. That byte code is exactly the same as Java compiler generates for .java class file. That means the byte code can run of JVM (Java Virtual Machine) the same way as the java byte code can run on it. The following image explains the Kotlin Architecture.

Kotlin Architecture

Why Kotlin is Called Interoperable Language?

Interoperability in programming languages means that the ability of a programming language to interact with the other programming languages. As you can see in the above picture, the Kotlin compiler generates the JVM compatible byte code the same as the Java byte code. That means both codes can communicate with each other and hence we say that Kotlin is an Interoperable programming language.

No More Null-Safety While Calling Java Code

As we discussed in the previous tutorial that Kotlin is a null safe language but if we call Java code from Kotlin, we will not be able to enjoy this Kotlin feature of Null-Safety and we can face NullPointerException causes by Java code.

How Kotlin Interacts with Javascript?

Kotlin is also Interoperable to Javascript. It works in a way that Kotlin has 2 compilers, one we discussed before which converts Kotlin code into JVM compatible byte code. But there is another compiler that converts Kotlin code into Javascript and generates Javascript classes, functions, etc. That’s why we can easily call Javascript from Kotlin and vice versa. But as we discussed in the previous tutorial Kotlin is a statically-typed programming language, but JavaScript is a dynamically-typed language, which means its compiler does not check data types in compile-time. But still, we can call JavaScript from Kotlin via dynamic types. We also can create Kotlin headers for JavaScript libraries to use the Kotlin type system.


Android Studio Installation Guide for Kotlin Development

Please share this post:
Native Mobile Application Developer (Android + IOS) having experience in Java, Swift, Kotlin, Objective C, Unity, C#, C/C++, NODE JS & PHP.

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: