Introduction to Kotlin and the JVM
What Kotlin is, its relationship to Java and the JVM, and where it's used.
What you'll learn
- Explain what Kotlin is and how it relates to Java and the JVM
- Identify the two major contexts Kotlin is used in today: Android and backend services
- Describe what makes a minimal Kotlin program (fun main())
Explanation
Kotlin is a statically-typed language that runs primarily on the Java Virtual Machine (JVM), fully interoperable with existing Java code and libraries -- a Kotlin file can call Java classes directly, and vice versa. It was created by JetBrains and is now Google's preferred language for Android development, while also seeing growing use for backend services (with frameworks like Ktor and Spring).
Kotlin's main pitch over Java is conciseness and safety: less boilerplate for common patterns, and a type system that catches null-pointer errors at compile time rather than runtime (covered in detail in the next module). Because it compiles to the same JVM bytecode as Java, a Kotlin program has access to the entire mature Java ecosystem of libraries and tools.
A minimal Kotlin program is just a top-level function: fun main() { println("Hello, Kotlin!") } -- no enclosing class is required, unlike Java's mandatory public static void main. This is a small but telling example of Kotlin's general philosophy: keep the ceremony out of the way of the actual logic.
This platform can't safely compile or execute real Kotlin code in your browser, so instead of a live runner, each lesson gives you real Kotlin source code and asks you to work out what it does.
Guided lab
Predict: A minimal Kotlin program
Read this program and predict exactly what it prints.
fun main() {
println("Hello, Kotlin!")
val sum = 2 + 2
println("2 + 2 = $sum")
}Stuck? Get a hint.
Common mistakes
- Assuming Kotlin code must be wrapped in a class like Java's `public static void main` -- a top-level `fun main()` is valid and idiomatic Kotlin.
- Thinking Kotlin and Java can't interoperate directly -- they compile to the same bytecode and can call each other freely.
- Assuming Kotlin is Android-only -- it's increasingly used for backend services too (Ktor, Spring).
Knowledge check
Takeaway
Kotlin runs on the JVM, interoperates directly with Java, and needs no enclosing class for a program's entry point.
Summary
Kotlin is a concise, null-safety-focused JVM language used for Android and increasingly backend development, fully interoperable with Java.
References
Your notes
Notes save automatically.
Finished this lesson?
Mark it complete to track your progress and schedule a future review.
AI tutor
The optional AI tutor isn't enabled in this deployment. All lessons, exercises, quizzes, and search work fully without it.