KtKotlin · Lesson 1 of 8

Hello, Kotlin

Kotlin's pitch in one file: everything Java does, in half the lines. main doesn't need a class, printing doesn't need System.out, and semicolons are optional.

Kotlin
// hello.kt
fun main() {
    println("Hello, World!")

    val name = "Ada"        // val = read-only (use by default)
    var age = 17            // var = mutable
    age = 18                // ok
    // name = "Bob"         // error: val cannot be reassigned

    println("I'm $name, age $age")          // string templates
    println("Next year: ${age + 1}")        // expressions in {}
}

Types are inferred: val name = "Ada" is a String without saying so. You can be explicit — val name: String = "Ada" — and must be when there's nothing to infer from. Prefer val everywhere; reach for var only when reassignment is genuinely needed.

Kotlin
fun main() {
    val int: Int = 42
    val long: Long = 42L
    val double: Double = 3.14
    val bool: Boolean = true
    val char: Char = 'A'
    val text: String = "hello"

    // No implicit numeric conversions — convert explicitly:
    val d: Double = int.toDouble()

    // Multi-line strings:
    val poem = """
        Roses are red,
        code compiles blue.
    """.trimIndent()
    println(poem)
}
◆ Note
Kotlin compiles to JVM bytecode — the same thing Java compiles to. That's why interop is seamless: Kotlin calls Java classes directly and vice versa, and Android's entire Java API is available.