Getting Started
Kotlin Introduction
Learn Kotlin — the modern, concise language that is now Google's preferred language for Android.
What is Kotlin?
Kotlin is a modern, statically typed programming language developed by JetBrains. It runs on the Java Virtual Machine (JVM) and is fully interoperable with Java. Google announced Kotlin as the preferred language for Android development in 2019.
Why Kotlin?
- Concise: Reduces boilerplate by up to 40% compared to Java
- Safe: Null safety built into the type system
- Interoperable: 100% Java interoperability
- Versatile: JVM, Android, JavaScript, Native (multiplatform)
- Modern: Coroutines, extension functions, data classes, sealed classes
Kotlin vs Java
Kotlin compiles to the same JVM bytecode as Java but with:
- Much less verbosity
- Null safety by default
- Functional programming features
- No checked exceptions
Example
kotlin
// Kotlin is concise
fun main() {
println("Hello, Kotlin!")
// val = immutable (like final in Java)
val name = "Kotlin"
// var = mutable
var version = 1.9
// Type annotation (optional when inferred)
val language: String = "Kotlin"
var count: Int = 0
// String templates
println("Hello from $name $version!")
println("Length: ${name.length}")
// Multi-line string
val text = """
|Line 1
|Line 2
|Line 3
""".trimMargin()
println(text)
}Try It Yourself