Kotlin lessons
Modern JVM / Android language
Kotlin was introduced by JetBrains in 2011 and rapidly spread after Google declared it the official language for Android in 2017. It runs on the virtual machine that Java runs on, uses Java libraries directly, but requires writing much less code.
Kotlin's main claim to fame is eliminating Java's boilerplate patterns. A data class that takes twenty lines in Java is a single line in Kotlin. Semicolons are not mandatory, it features type inference, and null safety is built directly into the language's type system — the null reference error, which is the most common cause of crashes in Java, is caught at compile time.
It is also used outside of Android: server-side code can be written with Ktor and Spring, and business logic can be shared between iOS and Android using Kotlin Multiplatform. Still, its primary use case is Android app development.
- •→
Introduction to Kotlin
First Kotlin program: printing to the screen using the main function and println.
- •→
Variables (val / var)
Holding immutable values with val and mutable values with var; type inference and naming conventions.
- •→
Data Types
Int, Double, Boolean, String; type conversion and Kotlin's null safety.
- •→
Strings
String concatenation, template expressions, length, and commonly used string functions.
- •→
Lists
Immutable lists with listOf, mutable lists with mutableListOf; element access and size.
- •→
Conditions (if / when)
Decision making with if-else, if returning a value, and multi-branched when structure.
- •→
Loops (for / while)
For loops with ranges and lists, conditional repetition with while.
- •→
Functions
Defining functions with fun, parameters, return type, default values, and single-expression bodies.
What you will learn
- Printing output with println and the distinction between val and var
- Null safety and the safe call operator
- Writing functions, default and named parameters
- Operations like map and filter on lists and maps
- Creating data-carrying classes with data class
- Making multi-branched decisions with the when expression
- Adding behavior to existing types with extension functions
Who is this for?
- Those who want to develop Android apps
- Developers who know Java and want to do the same work with less code
- Back-end developers looking for a modern language on the JVM
When to use?
Kotlin is the default choice for new Android projects. It also offers significant readability improvements over Java for backend services running on the JVM.
If you are targeting only iOS, Swift is required. There are also more suitable languages for data science, embedded systems, and browser-side development.
Frequently asked questions
Do I need to know Java to learn Kotlin?
No, you can start Kotlin from scratch. However, since a significant portion of the documentation and legacy code you will encounter in the Android ecosystem is in Java, being able to read Java code provides a major advantage.
Has Kotlin replaced Java?
On the Android side, largely yes—Google writes its new guides in Kotlin. On the server side, Java is still very widespread; Kotlin is a growing but minority choice there. Since both run on the same virtual machine, they can also be used together in the same project.
What is the difference between val and var?
A name defined with val cannot be reassigned a value, whereas var can be reassigned. Using val by default is recommended in Kotlin: immutable values make it easier to track what the code holds at any point and reduce sources of error in concurrent execution.
What does null safety provide in practice?
For a variable to be nullable, its type must include a question mark. If you try to directly access a potentially null value, the code will not compile. In Java, the same error would crash the program at runtime; Kotlin moves this to the compile-time phase.
Summary
Kotlin works in full compatibility with Java while allowing you to write much shorter and safer code; it is the official language of Android. In this tutorial, we progress from basic syntax to data classes and extension functions.