SyntaxStudy
Sign Up
Kotlin Beginner 8 min read

Introduction to Kotlin

Kotlin is a modern, statically typed programming language that runs on the JVM. It is 100% interoperable with Java and is now the preferred language for Android development. Kotlin is concise, expressive, and safe — it eliminates many common programming mistakes like null pointer exceptions.

Example
// Main.kt
fun main() {
    println("Hello, Kotlin!")

    // Variables: val (immutable), var (mutable)
    val name = "Alice"  // immutable
    var age  = 30       // mutable
    age = 31

    // String templates
    println("My name is $name and I am $age years old.")
    println("Next year I'll be ${age + 1}")

    // Null safety
    var nullable: String? = null
    println(nullable?.length)  // safe call: prints null
    println(nullable ?: "default")  // elvis operator

    // When expression (switch replacement)
    val day = 3
    val dayName = when(day) {
        1 -> "Monday"
        2 -> "Tuesday"
        3 -> "Wednesday"
        in 4..5 -> "Thursday or Friday"
        else -> "Weekend"
    }
    println(dayName)
}