AnyCompiler

Your First Kotlin Program

Every Kotlin program needs a main() function — that's where execution starts. Unlike Java, it doesn't need to live inside a class, and it doesn't need to be marked public static void — Kotlin's compiler generates all of that for you behind the scenes.

Compiling happens first

When you hit run, the compiler checks your entire file and compiles it to JVM bytecode before a single line executes. If there's a type error or a syntax mistake anywhere, nothing runs at all — you get a compiler error instead of output.

Comments

Comments work like in most C-family languages: anything after // on a line is ignored completely, existing purely so humans reading the code later understand why something is written the way it is.

Run it yourself

Here's a small program with a comment and two println calls. This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.

fun main() {
    // This is a comment -- ignored by the compiler
    println("Hello, world!")
    println("Learning Kotlin one step at a time.")
}
Output
Hello, world!
Learning Kotlin one step at a time.

Next: variables and types — val versus var, and Kotlin's primitive types.

Practice exercise

Add a comment above your code, then print "Learning Kotlin one step at a time."