Part 01 / Topic 5 of 9
The Kotlin script runner: .kts files
A .kts file is a Kotlin script: no fun main() wrapper, just statements at the top level, run
directly with the kotlin launcher instead of compiled by hand first.
println("Hello, Kotlin!")
println("Welcome to Kotlin Step by Step")
$ kotlin 02_hello_script.kts
Hello, Kotlin!
Welcome to Kotlin Step by Step
One command, no visible .jar or .class file left behind (the launcher compiles it to a temporary
location and runs that, then discards it). This is the right tool for a quick throwaway check; it's
also slower to start than a pre-compiled jar, because the compile step happens every time you run
it, not once up front. For anything you'll run more than a couple of times, compile it properly with
kotlinc instead (section 4).
Full program: examples/02_hello_script.kts.
Done here? The practice set for Part 1 — including the solutions — is on the part page.