Kotlin Tutorial · Kotlin Basics · Lesson 2 of 31
Kotlin Get Started
Install Kotlin, create a project with Gradle or IntelliJ IDEA, and compile and run a program.
Tools
- IntelliJ IDEA (or Android Studio for Android) is the main IDE; it bundles the Kotlin compiler.
- Gradle builds Kotlin projects; the build script itself is usually written in Kotlin (
build.gradle.kts). - The command-line compiler
kotlincis handy for single files. You need a JDK (17 or newer) installed.
kotlinc hello.kt -include-runtime -d hello.jar # compile to a runnable jar
java -jar hello.jar
A Gradle project
gradle init (choose application, Kotlin) creates app/src/main/kotlin/App.kt and a build file:
plugins {
kotlin("jvm") version "2.4.21"
application
}
application { mainClass = "AppKt" }
./gradlew run compiles and runs it. The program inside is plain Kotlin:
fun main() {
println("Hello from my first Kotlin project!")
}
Output
Hello from my first Kotlin project!
Run this on your computer — see “Get Started” for setup.
Test yourself
Which file format do modern Kotlin projects use for the Gradle build script?
pom.xmlbuild.gradle.ktsCargo.tomlpackage.json
Show answer
Answer: build.gradle.kts