Does JVM use kotlinc for Kotlin?

1.2k views Asked by At

I do have a little question about JVM and Kotlin. The JVM uses the Javac compiler to compile the Java code to bytecode. How does this work for Kotlin? Will the JVM use the Kotlinc compiler or will it still use the Javac compiler as Kotlin can be compiled to Java?

1

There are 1 answers

3
yole On

The JVM does not use the javac compiler. The process works differently: first, the developer runs javac to compile .java files to Java bytecode (.class files), and then the JVM loads the .class files and executes the bytecode.

To compile Kotlin code, you use the kotlinc compiler, which compiles .kt files to .class files. The JVM executes the bytecode from the .class files in exactly the same way; it does not care which compiler produced the .class files.

When compiling pure Kotlin projects, javac is not used in any way. When you compile a mixed-language project which contains both Java and Kotlin source files, the javac compiler is used to compile Java, and the kotlinc compiler is used to compile Kotlin.