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.

Create a free account to save this page, take notes and track your progress. Sign in

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 kotlinc is 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:

Example 1
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?

  1. pom.xml
  2. build.gradle.kts
  3. Cargo.toml
  4. package.json
Show answer

Answer: build.gradle.kts

Was this page helpful?