liveBook · Manning

Kotlin compiler

As explained in Kotlin in Action, 2E

The Kotlin compiler translates Kotlin source code into executable output for supported target platforms and performs compile-time checks.

The Kotlin compiler analyzes Kotlin source and translates it into executable output for several targets. For Kotlin/JVM, it turns .kt files into .class files that the JVM can run, then packages them using the application’s standard procedure. section 1.5.2

Compile and run a JVM program

A minimal command-line workflow is: kotlinc <source file or directory> -include-runtime -d <jar name> java -jar <jar name> The compiler produces JVM bytecode and the packaged JAR includes the Kotlin runtime library. That library supplies Kotlin classes such as Int and String and extensions to standard Java APIs. The JVM does not need to know whether the bytecode began as Java or Kotlin. section 1.5.2

Compilation also removes mechanical boilerplate from Kotlin source. The compiler can generate methods such as equals, hashCode, and toString for data-oriented classes. It also determines whether properties need backing fields: referencing field or using a default accessor requires storage, while a purely computed property does not. section 4.3 section 4.2.4

kotlinc <source file or directory> -include-runtime -d <jar name>
java -jar <jar name>

Use the command listing to navigate the complete compile-and-run workflow for a Kotlin/JVM program. section 1.5.2

How Kotlin in Action, 2E covers it

How deep it goes
Explains JVM compilation, runtime packaging, generated methods, and backing-field decisions, but defers detailed treatment of non-JVM targets.
Examples
Uses kotlinc and java commands, generated data-class methods, and properties with explicit or absent backing fields.
What it assumes
Assumes familiarity with Kotlin source files and JVM execution while introducing bytecode, JAR packaging, and runtime dependencies.
What you can do after
Operate/configure it via kotlinc and java to package and run Kotlin/JVM programs with the Kotlin runtime.
How it connects
Ties compilation to JVM bytecode, Java interoperability, Android Runtime, Kotlin runtime libraries, properties, data classes, and delegation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kotlin in Action, 2E. The section links point to the parts of the book it draws on.