Beginner 5 min readKotlin 2.0

Getting Started with Kotlin โ€” Your First Program

The fastest way to start writing Kotlin is in the browser. This tutorial shows you three ways to run Kotlin and explains your first program line by line.

What You Will Learn

  • Write your first Kotlin program
  • Understand the main function
  • Use the Kotlin Playground
  • Create a project in IntelliJ IDEA
  • Run a Kotlin file from the command line

Option 1: Kotlin Playground (No Setup)

The quickest way to run Kotlin is the official browser playground at play.kotlinlang.org. No installation needed. Just open the site, type your code, and click Run.

Hello World in the Playground

kotlin
fun main() {
    println("Hello, Kotlin!")
}
Output
Hello, Kotlin!

fun declares a function. main is the required entry point. println prints text and adds a newline. This is the minimal complete Kotlin program.

Beginner Tip: The Kotlin Playground auto-saves your code in the URL. You can share your code by copying the browser URL.

Option 2: IntelliJ IDEA (Recommended for Projects)

For real projects, download IntelliJ IDEA Community Edition (free) from jetbrains.com/idea. Create a new Kotlin project with "New Project โ†’ Kotlin โ†’ JVM | IntelliJ". IntelliJ gives you: - Auto-completion and refactoring - Integrated debugger - Run configurations - Built-in Kotlin support (no plugins needed)
Best Practice: Use IntelliJ IDEA for anything beyond quick experiments. The IDE integration makes Kotlin much more productive.

Option 3: Command Line

Install the Kotlin compiler via SDKMAN or Homebrew: ``` sdk install kotlin # SDKMAN brew install kotlin # macOS Homebrew ``` Then create a file called Hello.kt and compile it:

Running from the Command Line

kotlin
// Hello.kt
fun main() {
    println("Running from the terminal!")
}
Output
Running from the terminal!

Save as Hello.kt, compile with: kotlinc Hello.kt -include-runtime -d Hello.jar, then run with: java -jar Hello.jar

Understanding Your First Program

Every line in a Kotlin program has a purpose. Here is a detailed breakdown:

Program Breakdown

kotlin
// This is a comment โ€” the compiler ignores it
fun main() {               // entry point function
    val message = "Kotlin"  // declare a read-only variable
    println("Hello, $message") // print with string template
}
Output
Hello, Kotlin

// starts a single-line comment. fun main() is the required entry point. val declares a read-only variable. The $ inside a string inserts the variable value.

Beginner Tip: In Kotlin you do not need semicolons at the end of lines. The language is designed to be concise.

Practice Exercise

Exercisepredict output

What does this program print? fun main() { val name = "World" println("Hello, $name!") }

Quick Quiz

Quick Quiz

Which website lets you run Kotlin in the browser without any installation?

Frequently Asked Questions

Related Tutorials

Last updated: 2026-05-01Kotlin 2.0

Written by KotlinGuide Editorial Team ยท Reviewed by KotlinGuide Technical Review