Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Kotlin JVM and Kotlin Native?

So I know Kotlin Native is obviously Native and Kotlin JVM isn't but is the code between Kotlin JVM and Kotlin Native: 1. Different Compiler and Different Code 2. Different Compiler and Similar Code 3. Different Compiler and Same Code 4. None of the above (please explain)

like image 975
SmushyTaco Avatar asked Mar 28 '19 21:03

SmushyTaco


People also ask

Does Kotlin native use JVM?

Kotlin is an open-source statically typed programming language that targets the JVM, Android, JavaScript and Native. It's developed by JetBrains. The project started in 2010 and was open source from very early on.

Is Kotlin native faster than Kotlin JVM?

Any relatively large relatively long-running application will be more effective in JVM. In cases, where you need something very small or short, yes, Kotlin-Native is a very good candidate. The performance will be similar to Go though slower (in general) than Kotlin-JVM.

What is Kotlin JVM?

Kotlin is a general purpose, free, open source, statically typed “pragmatic” programming language initially designed for the JVM (Java Virtual Machine) and Android that combines object-oriented and functional programming features. It is focused on interoperability, safety, clarity, and tooling support.

Do I need JVM for Kotlin?

As already mentioned, Kotlin JVM requires the JVM to work. Kotlin compiles to JVM bytecode, which means it has the same requirements as Java (runtime and development kit).


1 Answers

The Kotlin/JVM and Kotlin/Native compilers share the front-end (the part that performs code parsing, name resolution, type inference etc.), but the compiler back-ends that translate the internal program representation to the target code (the JVM bytecode and LLVM bitcode, respectively) are different.

The Kotlin language accepted by the two compilers is the same, but some of the features and checks are platform-specific. Also, the standard libraries for Kotlin/JVM and Kotlin/Native are sufficiently different, see the APIs available on each platform here: Kotlin Standard Library.

Another big difference is the memory model: Kotlin/JVM uses the Java memory model, while Kotlin/Native offers its own concurrency and memory model.

Also, the dependencies that one can use in Kotlin/JVM and Kotlin/Native projects are different. In addition to the projects built using the same Kotlin target:

  • Kotlin/JVM can also use any libraries built for the JVM (written in Java, Scala etc.)

  • Kotlin/Native can also interoperate with native libraries written in C (or at least having C headers) using the C interop tools.

  • Both Kotlin/JVM and Kotlin/Native can use Kotlin Multiplatform libraries. Given that a dependency is a multiplatform library, one can entirely reuse the code working with it between Kotlin/JVM and Kotlin/Native.

like image 107
hotkey Avatar answered Oct 26 '22 07:10

hotkey