TExcelTAD
Home › Kotlin › Kotlin Intro

Kotlin Introduction

Kotlin is a modern, statically typed programming language created by JetBrains, the company behind IntelliJ IDEA. It was announced in 2011, reached version 1.0 in 2016, and in 2019 Google declared it the preferred language for Android development. Today Kotlin runs on the Java Virtual Machine, in the browser (Kotlin/JS and Kotlin/Wasm) and natively on iOS, macOS, Linux and Windows (Kotlin/Native).

Kotlin was designed to fix the everyday annoyances of Java while staying 100% compatible with it. You can call any Java library from Kotlin, and Java code can call Kotlin — so teams can adopt it one file at a time.

What is Kotlin used for?

  • Android apps — most new Android code and Jetpack Compose UIs are written in Kotlin
  • Server-side back-ends with Spring Boot, Ktor or Quarkus
  • Multiplatform apps that share business logic between Android, iOS, desktop and web
  • Build scripts — Gradle's build.gradle.kts files are Kotlin
  • Command-line tools and data processing on the JVM

Why learn Kotlin?

Feature What it means for you
Concise Data classes, type inference and lambdas remove a lot of boilerplate
Null safe The type system separates String from String?, so most null-pointer crashes are caught at compile time
Interoperable Every Java library (and the whole JVM ecosystem) works out of the box
Expressive if and when are expressions, functions can have default arguments, collections have rich operations
Coroutines Asynchronous code that reads like ordinary sequential code
Multiplatform One language for Android, iOS, server, desktop and web

Your first Kotlin program

A Kotlin program starts in a top-level function called main. Unlike Java, it does not need to live inside a class. Press ▶ Run to compile and run it, then change the text and run it again.

kotlin · try it yourself
fun main() {
    println("Hello, Kotlin!")
}
Hello, Kotlin!

fun declares a function, main is its name, and println prints a line of text followed by a line break. There are no semicolons — Kotlin uses line breaks to end statements.

Tip: In every playground on ExcelTAD you can edit the code and press Ctrl+Enter to run it. The examples are compiled by JetBrains' official Kotlin Playground service.

A taste of what Kotlin can do

Here is a slightly bigger program. You don't need to understand every line yet — just notice how little code it takes to describe some data and work with it.

kotlin · try it yourself
data class Planet(val name: String, val moons: Int)

fun main() {
    val planets = listOf(
        Planet("Earth", 1),
        Planet("Mars", 2),
        Planet("Jupiter", 95)
    )
    for (p in planets) {
        println("${p.name} has ${p.moons} moon(s)")
    }
    val total = planets.sumOf { it.moons }
    println("Total moons: $total")
}
Earth has 1 moon(s)
Mars has 2 moon(s)
Jupiter has 95 moon(s)
Total moons: 98

In a few lines you defined a class with properties, built a read-only list, looped over it, used string templates ($total, ${p.name}) and summed a property with a lambda.

Kotlin vs. Java

Kotlin Java
Entry point top-level fun main() public static void main inside a class
Semicolons optional (almost never written) required
Variables val (read-only) / var (mutable) type name, final for read-only
Null handling nullable types String? checked by the compiler any reference may be null
Data holders data class in one line records (Java 16+) or lots of boilerplate
Runs on JVM, JS, Wasm, native JVM

Note: Kotlin compiles to the same JVM bytecode as Java. A Kotlin app on Android or on a server performs just like the equivalent Java code.

How this course is organised

  1. Kotlin Tutorial — syntax, variables, types, control flow, arrays, loops and functions.
  2. Kotlin OOP — classes, constructors, inheritance, interfaces and Kotlin's special class kinds.
  3. Kotlin Idioms — null safety, collections, lambdas, extension and scope functions: what makes code feel "Kotlin-like".
  4. Kotlin Advanced — coroutines, Android and Multiplatform.
  5. Practice — exercises and a step-by-step mini project.

Test yourself

Which company created Kotlin?

  1. Google
  2. Oracle
  3. JetBrains
  4. Microsoft

Where must the main function be declared in Kotlin?

  1. Inside a class called Main
  2. At the top level of a file — no class needed
  3. Inside an object
  4. In a separate file called main.kt

Can Kotlin code use existing Java libraries?

  1. No, never
  2. Only with a special converter
  3. Yes, Kotlin is fully interoperable with Java
  4. Only on Android