Chapter 1 of 12 ~10 min read

Introduction to Kotlin

What is Kotlin, why Java developers should adopt it, and your first Hello World comparison.


What is Kotlin?

Kotlin is a modern, statically typed programming language developed by JetBrains (the creators of IntelliJ IDEA) and first released in 2016. It runs on the JVM, compiles to the same bytecode as Java, and was officially designated as Google's preferred language for Android development in 2019.

Key Insight for Java Developers

Kotlin is not a replacement for Java — it's a companion. You can have Java and Kotlin files in the same Android project, and Kotlin can call any Java library directly. This means you can migrate incrementally, file by file.

Kotlin vs Java: Key Differences at a Glance

Feature Java Kotlin
Null Safety No built-in null safety → NullPointerException at runtime Compile-time null safety with ? types
Boilerplate Getters, setters, constructors, toString() — all manual Auto-generated with data class
Semicolons Required at end of every statement Optional (usually omitted)
Static members static keyword companion object
Immutability final keyword val (immutable) vs var (mutable)
String formatting String.format("%s %d", name, age) "Hello $name, age $age"
Async code Threads, ExecutorService, RxJava Coroutines (structured concurrency)
Default class Open (can extend by default) Final by default (must mark open)
Checked exceptions Enforced at compile time Not required (unchecked only)

Hello World: Java vs Kotlin

Let's start with the most fundamental program and immediately spot the differences:

Java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Kotlin
fun main() {
    println("Hello, World!")
}
What changed?
  • No class wrapping needed — fun main() is a top-level function
  • println() replaces System.out.println()
  • No public static, no String[] args, no semicolons
  • Kotlin 2.x: main() with no parameters is valid

Where Does Kotlin Run?

Android
Primary use case. First-class Jetpack Compose, coroutines, and KMM support.
JVM Backend
Spring Boot, Ktor — Kotlin compiles to JVM bytecode just like Java.
Multiplatform
Kotlin Multiplatform (KMP) shares business logic across Android, iOS, and Web.

Setting Up

If you already develop Android apps in Java, you're ready to start writing Kotlin today — no extra setup needed.

Android Studio — Java project
// app/build.gradle (existing Java project)
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}
Add Kotlin to Existing Project
// app/build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.android") version "2.2.0"
}
kotlin {
    jvmToolchain(17)
}
// ✅ Now .kt files are recognized alongside .java
Android Studio Tip

In Android Studio, you can instantly convert any Java file to Kotlin: open it, then go to Code → Convert Java File to Kotlin File (or press Ctrl+Alt+Shift+K). It's not always perfect, but it's a great learning tool.

Frequently Asked Questions

Yes, for Android specifically. Kotlin is Google's preferred language since 2019. All new Jetpack APIs are Kotlin-first, and Jetpack Compose (the modern UI toolkit) is Kotlin-only. New Android projects should default to Kotlin.

Yes, 100%. Kotlin has full Java interoperability. You can call Retrofit, Gson, OkHttp, Room, or any Java-based library directly from Kotlin. The Java and Kotlin ecosystems are unified.

Most Java developers are productive in Kotlin within 1–2 weeks. The basic syntax takes a day or two, null safety takes practice, and coroutines are the steepest learning curve. This course covers all of it in ~3 hours of reading.