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)
Hello World in the Playground
fun main() {
println("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.
Option 2: IntelliJ IDEA (Recommended for Projects)
Option 3: Command Line
Running from the Command Line
// Hello.kt
fun main() {
println("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
Program Breakdown
// 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
}// 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.
Practice Exercise
What does this program print? fun main() { val name = "World" println("Hello, $name!") }
Quick Quiz
Which website lets you run Kotlin in the browser without any installation?
Frequently Asked Questions
Related Tutorials
Written by KotlinGuide Editorial Team ยท Reviewed by KotlinGuide Technical Review