Kotlin Playground

Setting Up a Kotlin Playground and Running Your First Program

The Kotlin Playground 25,990 at play.kotlinlang.org (https://play.kotlinlang.org/ 25,990 ) runs code from your browser, with a choice of compiler version (2.4.20 by default, 2.5.0-Beta1 on offer) and target. Offline, unzip kotlin-compiler-2.4.20.zip from GitHub 29 releases and add its bin folder to PATH, or run sdk install kotlin, brew 6,457 install kotlin or sudo snap install --classic kotlin; you also need a JDK (this book uses 17). A program starts at a top-level main function, with no class around it:

hello.kt: a first Kotlin programKotlin
fun main() {
    val app = "BookNest"
    val books = 6
    println("Welcome to $app: $books books in the catalog")
}
Output
$ kotlinc hello.kt -include-runtime -d hello.jar
$ java -jar hello.jar
Welcome to BookNest: 6 books in the catalog

-include-runtime bundles the standard library, which is why this JAR weighs 5.7 MB; Android builds shrink it with R8 234 instead (R8). For quick experiments, a script named *.main.kts runs directly with kotlin hello.main.kts, no JAR needed.