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.ktsfiles 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.
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.
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
- Kotlin Tutorial — syntax, variables, types, control flow, arrays, loops and functions.
- Kotlin OOP — classes, constructors, inheritance, interfaces and Kotlin's special class kinds.
- Kotlin Idioms — null safety, collections, lambdas, extension and scope functions: what makes code feel "Kotlin-like".
- Kotlin Advanced — coroutines, Android and Multiplatform.
- Practice — exercises and a step-by-step mini project.
Test yourself
Which company created Kotlin?
- Oracle
- JetBrains
- Microsoft
Where must the main function be declared in Kotlin?
- Inside a class called Main
- At the top level of a file — no class needed
- Inside an object
- In a separate file called main.kt
Can Kotlin code use existing Java libraries?
- No, never
- Only with a special converter
- Yes, Kotlin is fully interoperable with Java
- Only on Android