Look At All the Kotlins!

This book is focused on Kotlin syntax, so you understand how to read and write Kotlin code. However, usually, if you are writing Kotlin code, the point behind the code is not for it to just sit there. Most likely, you plan to run that code.

Programming languages sometimes have a variety of ways that their code can be run. For example, Ruby code can be run on a few Ruby interpreters, or on the Java Virtual Machine (JVM) via JRuby, or possibly compiled into native code. Of those options, the standard Ruby interpreter is the most common, and is the one that people tend to think of. Similarly, despite NodeJS’s popularity, when a lot of people think about running JavaScript code, they will think of doing so inside of a Web browser.

Similarly, Kotlin has a few “runtime environments” to consider.

Kotlin/JVM

If you just hear the name “Kotlin”, without any qualifiers, it is likely that the person in question is referring to the original form of Kotlin, which ran on the JVM. Kotlin’s compiler would create Java bytecode from the Kotlin source code, just as Java’s compiler creates Java bytecode from Java source code. The resulting bytecode can be used by java and similar tools, regardless of whether it was written in Java, Kotlin, or something else.

In particular, if you are interested in Android app development, when you think of Kotlin, most likely you are thinking of Kotlin being compiled in an Android project. In that case, while Android does not use the JVM, the same basic mechanism is applied: Kotlin’s compiler generates Java bytecode, which the Android build process then converts into Dalvik bytecode for use in Android apps.

Kotlin/JS

For the first few years of Kotlin’s development, Kotlin simply was Kotlin/JVM.

In 2014, Kotlin/JS was introduced. This allows Kotlin’s compiler to “compile” Kotlin source code into JavaScript source code, with an eye towards that code being used in an environment like NodeJS. The JavaScript that you get from the compilation process is not necessarily going to be easily readable by ordinary humans, but that’s not the goal. The goal is to be able to write in Kotlin and run it in a traditional JavaScript runtime environment.

Kotlin/Native

More recently, the Kotlin team has added Kotlin/Native. This compiles Kotlin code to native opcodes, the same as you might find with a C/C++ compiler. In particular, Kotlin/Native is designed to generate code that can run on iOS and macOS, interoperating with Objective-C.

Kotlin/Common

Kotlin/Common does not represent a new runtime environment for Kotlin, at least in the strict sense. Kotlin/Common is the term given to a type of library that limits itself to using Kotlin classes and functions that exist for all Kotlin runtime environments. Such a library can be used by a Kotlin/JVM project as easily as by a Kotlin/JS or Kotlin/Native project, for example.

Kotlin/Multiplatform

Kotlin/Multiplatform also is not a new runtime environment for Kotlin. Rather, it is a way of setting up a project such that some core app logic is written in a Kotlin/Common library, while other “modules” are set up for specific runtime environments. Overall, the entire project can target 2+ runtime environments, such as using Kotlin as the foundation for both an Android (Kotlin/JVM) and iOS (Kotlin/Native) app.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.