Getting Started

This section documents Kotlin 2.4.x on the JVM, as published at kotlinlang.org, which is the reference these pages are written and verified against.

This content was generated with the assistance of AI and should be verified against kotlinlang.org before being relied on in production.

This section’s bibliography lists the reference material consulted while preparing these pages.

Kotlin is a modern, statically-typed programming language created by JetBrains and released under the Apache 2.0 license. It first shipped in 2011, reached 1.0 in 2016, and became an Apache-licensed, open-source project governed with community input from the start. Kotlin is interoperable with Java and targets several platforms through Kotlin Multiplatform, but the JVM has always been its first and most mature target — this whole section documents Kotlin on the JVM (see Kotlin and the JVM for how the other targets relate).

Installing Kotlin

You rarely install a standalone Kotlin compiler on its own — most projects get it transitively through a build tool or an IDE — but three options exist:

  • SDKMAN (Linux/macOS/WSL) — the simplest command-line install:

    curl -s "https://get.sdkman.io" | bash
    sdk install kotlin
  • Homebrew (macOS/Linux):

    brew install kotlin
  • IntelliJ IDEA / Android Studio — both ship a bundled Kotlin plugin and toolchain, so no separate install is needed when you create a project from the IDE.

See Working with command-line compiler for platform-specific installer downloads (a .zip/.tar.gz release) if you prefer a manual install.

kotlinc, the Compiler

kotlinc compiles .kt files to JVM class files, exactly as javac does for .java files:

kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

-include-runtime bundles the small Kotlin standard-library runtime into the jar so it runs standalone; without it, kotlin-stdlib.jar must be on the classpath separately (which is what a Gradle/Maven build does for you automatically — see Build and Tooling).

The Kotlin REPL and the Kotlin Playground

kotlinc with no arguments starts an interactive REPL (read-eval-print loop), useful for quick experiments:

$ kotlinc
Welcome to Kotlin version 2.4.0 (JRE 21.0.4+7)
Type :help for help, :quit for quit
>>> val greeting = "Hello"
>>> println("$greeting, Kotlin!")
Hello, Kotlin!

No local install is needed at all to try Kotlin: the Kotlin Playground runs and shares snippets entirely in the browser, against a real (if sandboxed) Kotlin compiler — the fastest way to try an idea from this section without touching a project.

"Hello, World"

A complete Kotlin program can be a single top-level function — no enclosing class, and no access modifier, is required:

fun main() {
    println("Hello, World!")
}

Compare this to Java’s mandatory public class Main { public static void main(String[] args) { …​ } } boilerplate — Kotlin’s fun main() compiles to a real public static void main(String[]) method on a synthetic class (named after the file, e.g. HelloKt), it just doesn’t make you write that ceremony by hand. main may optionally take args: Array<String> when command-line arguments are needed.

Compiling to JVM Bytecode

kotlinc compiles Kotlin source to the same .class bytecode format the JVM already runs and javac already produces — there is no separate "Kotlin runtime" the way, say, a scripting language needs an interpreter. This is the foundation for everything in Kotlin and the JVM: full Java interoperability, running anywhere a JVM runs, and using the entire Java ecosystem (libraries, application servers, profilers) unmodified.

kotlinc hello.kt -d out/
javap -c out/HelloKt.class | head -5

See Also

  • Kotlin and the JVM — what compiling to JVM bytecode buys you, and Kotlin’s other compile targets.

  • Build and Tooling — using Kotlin from Gradle/Maven instead of kotlinc directly, plus IDE support and static analysis.

  • Lexical Structure and Style — file/package layout and the official coding conventions.