Setting up the Environment
You want to see the words "Pebble Café is open" appear on your screen, printed by a program you wrote. Before any of that, your computer needs two things: something that turns Kotlin into runnable code, and something that runs it.
The rule
JDK to run it, a compiler to build it, an editor to write it.
- JDK (Java Development Kit). Kotlin programs for the JVM run on a Java virtual machine, so you need a JDK installed. Any recent long-term-support version works.
- A compiler. The Kotlin compiler,
kotlinc, turns.ktfiles into JVM class files. IDEs and build tools bundle it for you. - An editor. IntelliJ IDEA (made by Kotlin's own authors) and Android Studio understand Kotlin deeply: completion, error highlighting and one-click running.
Three common ways to start:
| Setup | Best for | Install? |
|---|---|---|
| Kotlin Playground in the browser | Trying a few lines | Nothing |
| IntelliJ IDEA + Gradle project | Real applications | IDE (includes Kotlin) |
JDK + kotlinc in a terminal |
Servers, scripts, learning the steps | JDK and compiler |
The terminal route shows what the IDE does behind the scenes:
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jarThe first line compiles hello.kt into a jar file and packs the Kotlin runtime library inside it. The second line runs that jar on the JVM.
In a real project, a build tool such as Gradle does this for you. It downloads libraries, compiles every file and packages the result. Source files usually live in src/main/kotlin.
The shortcut
Match the setup to the size of the job: a few lines → browser; one file → kotlinc; a project → IDE + Gradle. Then check the chain from left to right: editor → compiler → JVM. If something fails, find the broken link.
Check the JVM
java -versionprints a version number. If it does not, install a JDK first.
A frequent stumble: leaving out -include-runtime. The jar then lacks Kotlin's standard library, and running it fails with a missing-class error.
Drills
Answer fast — trust the rule.
Why do you need a JDK to run Kotlin programs on the JVM?
You want to try three lines of Kotlin right now on a borrowed laptop. What is the quickest setup?
What does kotlinc hello.kt -include-runtime -d hello.jar do?
In a typical Gradle project, where do Kotlin source files live?
Remember
- JDK to run it, a compiler to build it, an editor to write it.
- Browser for a few lines,
kotlincfor one file, IDE plus Gradle for a project. - Compiling by hand? Add
-include-runtimeor the jar will not run.
