I tried the Kotlin notebook extension and I wonder what is going under the hood.
I have used notebooks with python and because python is an interpreted language it seems natural that it works in the notebook.
My understanding is that after writing the Kotlin code I need to compile it (No?) before I execute it. But in notebook, if I create a class in one cell, I am able to instantiate an object in the next cell and I can't figure out how is this working.
EDIT: It appears there are IPYTHON kernels for many of the compiled languages. However the question remains "How do compiled programming languages work in the interactive jupyter notebook environment"?
Yes, when targeting the JVM, Kotlin is compiled to JVM *. class files, which is a bytecode format that can later be either interpreted by a JVM, or compiled to the machine code by the JVM during the program run (JIT), or even compiled ahead-of-time (AOT) down to the machine code.
Kotlin lets you choose the version of JVM for execution. By default, the Kotlin/JVM compiler produces Java 8 compatible bytecode. If you want to make use of optimizations available in newer versions of Java, you can explicitly specify the target Java version from 9 to 18.
Kotlin used the Java programming language for its initial implementation, then most of the Kotlin compiler's source code got rewritten to Kotlin.
The Kotlin compiler for JVM compiles Kotlin source files into Java class files. The command-line tools for Kotlin to JVM compilation are kotlinc and kotlinc-jvm . You can also use them for executing Kotlin script files.
Kotlin has a special scripting mode (apart from the ordinary compiled mode), we often name a Kotlin script with the suffix .kts
.
You can try this with a command line Kotlin compiler:
println("hello world")
in a.kts
kotlinc -script a.kts
And you'll see hello world
printed on screen.
If you have IntelliJ IDEA, try right-clicking on a .kts
file and select Run
option. You'll see command line output.
How do compiled programming languages work in the interactive jupyter notebook environment?
There's nothing to do with "compiled" here. This is a special function of Kotlin compiler (running kotlin codes as script).
Not all languages have such feature. This isn't general-purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With