← Back to Kotlin Course | Chapter 1: Setup & Basics | Lesson 1 of 7

Introduction to Kotlin

Kotlin is a friendly programming language that lets you give a computer clear, step-by-step instructions, and it also runs on Android phones.

What is Kotlin?

Kotlin is a general-purpose, statically-typed programming language created by JetBrains as a more concise and safer alternative to Java. It runs on the Java Virtual Machine (JVM), so it can use any existing Java library, but it adds modern features like null safety, data classes, and extension functions.

Note: You don't need Android Studio to try Kotlin -- the standalone kotlinc compiler runs plain .kt files from any terminal.

Example: What is Kotlin?

markup
fun main() {
    println("Kotlin is a modern programming language")
    println("It runs on the JVM and beyond")
}

Why Kotlin Was Created

JetBrains built Kotlin to fix pain points they experienced writing Java every day, such as verbose boilerplate and the risk of null pointer exceptions. Kotlin keeps full interoperability with Java while adding safer defaults and much more concise syntax.

Example: Why Kotlin Was Created

markup
fun main() {
    val goals = listOf("conciseness", "safety", "interoperability")
    for (goal in goals) {
        println("Design goal: $goal")
    }
}

Where Kotlin Is Used

Kotlin is the preferred language for Android app development, but it is also used for server-side backends (with frameworks like Ktor and Spring), for multiplatform mobile code shared between iOS and Android, and for general scripting.

Example: Where Kotlin Is Used

markup
fun main() {
    val usedFor = listOf("Android apps" to "Google apps", "Backend" to "Ktor servers", "Scripting" to "build scripts")
    for ((area, example) in usedFor) {
        println("$area: $example")
    }
}

Compiled on the JVM

Kotlin source code is compiled into JVM bytecode before it runs, just like Java. This lets the compiler catch many mistakes, such as type errors, before your program ever executes, and it lets Kotlin call Java code and vice versa without any extra work.

Note: Running kotlinc file.kt -include-runtime -d app.jar then java -jar app.jar compiles and runs in two quick steps.

Example: Compiled on the JVM

markup
fun main() {
    println("This code is compiled to JVM bytecode")
    println("The compiler already checked it for errors")
}
Common Mistakes
  1. Assuming Kotlin is only for Android apps and cannot be used for backend, scripting, or plain command-line programs.
  2. Confusing Kotlin with Java; Kotlin is a separate, newer language with its own syntax even though it runs on the same JVM.
  3. Thinking Kotlin code always needs Android Studio to run, when a plain .kt file can be compiled and run from a terminal.
Chapter Summary
  • Kotlin is a modern, statically-typed language created by JetBrains and released in 2011.
  • It runs on the JVM, compiles to JavaScript, and compiles natively via Kotlin/Native.
  • Google made Kotlin an officially supported language for Android development in 2017.
  • Kotlin interoperates fully with Java, so existing Java libraries can be used directly from Kotlin code.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.