From zero to your first running program. No prior experience required — just curiosity and a few minutes.
You can write and run Kotlin in several ways:
For this guide we start with the simplest path, then show local setup.
Create a file named Hello.kt:
fun main() { println("Hello, Kotlin!") }
Compile and run from the terminal (after installing the compiler):
kotlinc Hello.kt -include-runtime -d Hello.jar java -jar Hello.jar
val name = "Kotlin" // immutable (preferred) var count = 0 // mutable count += 1
fun greet(name: String): String { return "Hello, $name!" } // Single-expression form fun double(x: Int) = x * 2
var a: String = "not null" // cannot be null var b: String? = null // can be null // Safe call println(b?.length) // Elvis operator — provide a default val len = b?.length ?: 0
class User(val id: Int, var name: String) data class Point(val x: Int, val y: Int) val p1 = Point(1, 2) val p2 = p1.copy(x = 10) println(p1) // Point(x=1, y=2)
Most real projects use Gradle. A minimal layout looks like this:
my-app/
├── build.gradle.kts
├── settings.gradle.kts
└── src/
└── main/
└── kotlin/
└── Main.kt
Minimal build.gradle.kts:
plugins {
kotlin("jvm") version "2.0.21"
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
Follow the Installation guide to set up the compiler and IDE.
Dive into the Coding guide for collections, coroutines, DSLs, and more.
Use the Docs overview as a map to official and community resources.