Kotlin Introduction
What Kotlin is, its JVM interop and role as the default Android language, and your first program.
What is Kotlin?
Kotlin is a statically-typed, modern language created by JetBrains, first released in 2011 and reaching 1.0 in 2016. It runs on the JVM (compiling to the same bytecode as Java), and can also compile to native binaries (Kotlin/Native) or JavaScript (Kotlin/JS) — but its primary home, and the reason most people learn it, is the JVM and Android.
Kotlin was designed as a more concise, safer alternative to Java, fixing several of Java's long-standing pain points — verbose boilerplate, and especially NullPointerException, which Kotlin's type system prevents at compile time in ordinary code (covered in depth on the next page).
JVM interop and Android
Because Kotlin compiles to standard JVM bytecode, it's fully interoperable with Java: a Kotlin file can call any Java class, and a Java file can call any Kotlin class, in the same project, with no wrapper or bridge code needed. This interop is a large part of why Kotlin adoption spread so fast — teams could adopt it file-by-file inside existing Java codebases rather than rewriting everything at once.
In 2019, Google made Kotlin its preferred language for Android development, ahead of Java — new Android documentation, sample code, and Jetpack libraries (like Jetpack Compose, Android's modern declarative UI toolkit) are written Kotlin-first. If you're building a native Android app today, Kotlin is the default choice.
Kotlin isn't limited to Android, though — it's a strong general-purpose choice for backend services too, particularly with frameworks like Spring Boot and Ktor.
Trying Kotlin
You don't need a full IDE setup to start experimenting — the official Kotlin Playground (play.kotlinlang.org) runs Kotlin code directly in the browser with no install. For real project work, IntelliJ IDEA (also from JetBrains) has first-class Kotlin support built in.
To install the compiler directly:
macOS (Homebrew):
brew install kotlin
Linux/Windows (SDKMAN):
sdk install kotlin
Verify:
kotlinc -version
Hello, World
fun main() {
println("Hello, World!")
}
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar
Hello, World!
fundeclares a function —fun main()is the program's entry point, and unlike Java, it doesn't need to live inside a class at all.printlnwrites a line to standard output, automatically appending a newline (Java's equivalent isSystem.out.println).- No semicolons are required at the end of statements (though they're legal, just unidiomatic).
- No
public static voidboilerplate — Kotlin infers visibility (publicby default) and doesn't require a wrapping class for a simple script's entry point.
Common mistakes
- Expecting to need a class wrapper around
main()out of Java habit — Kotlin's top-level functions don't require one. - Assuming Kotlin is "just Android" — it's a fully general-purpose JVM language used for backend services, scripting, and multiplatform code too.
- Forgetting Kotlin and Java interoperate directly — there's rarely a need to rewrite an entire existing Java codebase before introducing Kotlin into it.
Interview questions
Q: Why did Google make Kotlin the preferred language for Android over Java?
Kotlin's null-safety model eliminates a huge share of Android's historically most common crash (NullPointerException) at compile time, its conciseness cuts down significantly on Java's boilerplate, and it interoperates directly with the existing Java-based Android SDK and libraries — so teams could adopt it incrementally without a full rewrite.
Q: What does it mean that Kotlin is "fully interoperable" with Java? A Kotlin file can call Java classes and libraries directly, and Java code can call Kotlin classes directly, within the very same project — both compile to standard JVM bytecode, so there's no wrapper, bridge, or translation layer needed at the call site.