All lessons

Your First Program

6 min · Kotlin

Write and run your very first Kotlin program, right here on the page.

Kotlin · Your First Program0/5 cleared

Enemy 1 of 5

Every Kotlin program needs a starting point, and that starting point is a function called main. When you run a Kotlin program, fun main() is the first thing that executes — everything else happens because main calls it, directly or indirectly. The curly braces { } after it mark the block of code that belongs to main; anything you want to run at startup goes between them.

println is how you print a line of text to the screen. Unlike Rust's println!, Kotlin's println is a completely ordinary function — no exclamation mark needed — which reflects Kotlin's general design philosophy of keeping syntax as plain and readable as possible. Whatever text sits inside the parentheses and double quotes gets printed exactly as written.

Notice there's no semicolon required at the end of the println line. Kotlin, like Python, treats a line break as the natural end of a statement, so semicolons are optional (you can add one, but you almost never need to). This is one of the first things people coming from Java, C, or Rust notice and appreciate about Kotlin's syntax.

You
Binary Treant

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, World!