Kotlin
Google's official language for Android development. Modern, concise and safe β Kotlin replaces Java on Android with less code, fewer crashes and happier developers.

Quick facts
What is Kotlin?
The modern language taking over Android development
Kotlin was created by JetBrains (the company behind IntelliJ IDEA) and released in 2011. It was designed to be 100% interoperable with Java while fixing many of Java's pain points β verbose code, null pointer exceptions and slow development speed.
In 2017, Google announced Kotlin as an official language for Android development. By 2019 Google went Kotlin-first β all new Android APIs, documentation and samples are written in Kotlin. Java is still supported, but Kotlin is the future of Android.
Kotlin's standout feature is null safety. In Java, accessing a null value causes a crash. Kotlin eliminates this at the language level β variables cannot hold null unless you explicitly use a ? suffix. This makes Kotlin apps far more stable.
Beyond Android, Kotlin runs anywhere the JVM runs β servers, web backends with Ktor and Spring Boot, and shared multiplatform code between Android and iOS with Kotlin Multiplatform.
What you will learn
- 1Variables β val (immutable) and var (mutable)
- 2Data types β Int, String, Boolean, Double
- 3String templates with $variable
- 4Control flow β if, when, for, while
- 5Functions with default parameters
- 6Null safety β ? and !! operators
- 7Classes and objects
- 8Data classes β auto-generated methods
- 9Collections β List, Map, Set
- 10Lambda expressions and higher-order functions
Taste of Kotlin
Your first Kotlin program
Notice how clean Kotlin is β no semicolons, no verbose boilerplate, and string templates make printing variables effortless.
Reference
Kotlin Syntax Reference
The most important Kotlin syntax at a glance. Bookmark this β you will use it constantly.
val name = "Alice"Immutable variable β value cannot changevar age = 20Mutable variable β value can be reassignedval x: Int = 5Explicit type declaration"Hello $name"String template β embed variable in string"Sum: ${a + b}"String template with an expressionif (x > 0) { }If condition blockval r = if (x > 0) 1 else -1If used as expression β returns a valuewhen (x) { 1 -> "one" }When expression β replaces switch/casefor (i in 1..10) { }For loop with range 1 to 10 inclusivefor (item in list) { }For loop over every item in a listwhile (x > 0) { }While loopfun greet(name: String) { }Function declarationfun add(a: Int, b: Int): IntFunction with explicit return typefun fn(x: Int = 0) { }Function with default parameter valuevar s: String? = nullNullable type β can hold nulls?.lengthSafe call β only runs if s is not nulls!!.lengthNon-null assertion β crashes if nullclass Person(val name: String)Class with primary constructordata class User(val id: Int)Data class β auto generates equals, toStringlistOf(1, 2, 3)Create an immutable listmutableListOf(1, 2, 3)Create a mutable listmapOf("key" to value)Create an immutable maplist.filter { it > 2 }Filter list β keep items matching conditionlist.map { it * 2 }Transform each element with a lambda// commentSingle-line comment β ignored by compilerFAQ
Common questions about Kotlin
What is Kotlin used for?
Kotlin is primarily used for Android app development β it is the official language recommended by Google for building Android apps. It also runs on the JVM so it can be used for server-side development (Ktor, Spring Boot), multiplatform development (Kotlin Multiplatform), and even web frontends (Kotlin/JS).
Do I need to know Java before learning Kotlin?
No. You can learn Kotlin as your first language. It is actually more beginner-friendly than Java β less boilerplate, cleaner syntax and built-in null safety. However, since Kotlin runs on the JVM and interoperates with Java, understanding Java helps when reading Android documentation or working on existing Java projects.
What is the difference between val and var in Kotlin?
val declares an immutable (read-only) variable β once assigned, you cannot change its value. var declares a mutable variable β you can reassign it at any time. The Kotlin convention is to use val by default and only use var when you specifically need to change the value. This makes your code safer and more predictable.
What is null safety in Kotlin?
Null safety is one of Kotlin's biggest advantages. In Java, accessing a null value crashes the program with a NullPointerException. In Kotlin, variables cannot hold null by default β you must explicitly declare a variable as nullable using a ? suffix (e.g. String?). The compiler forces you to handle the null case before using the value.
Is Kotlin better than Java for Android?
For new Android projects, yes. Kotlin is the recommended choice. It produces the same bytecode as Java so performance is identical, but code is roughly 40% more concise. Google has been Kotlin-first since 2019, meaning new Android APIs and documentation are Kotlin-first. Java is still fully supported but Kotlin is the future.
Can I run Kotlin in my browser?
Kotlin requires the JVM or compilation, so it cannot run live in a browser like JavaScript. On CodeLearn Pro, every Kotlin example shows the expected console output next to the code so you can follow along and understand exactly what each program produces.
Ready to learn Kotlin?
10 beginner-friendly examples. Each one shows the code and the exact console output. No installation needed.
Start the Kotlin tutorial βThe Story of Kotlin
Real history, real companies, and an honest look at where Kotlinshines and where it doesn't β not just a feature list.
Where it came from
JetBrains β the company behind IntelliJ IDEA β released Kotlin in 2011 as a modern alternative to Java, aiming to fix well-known Java pain points like verbose null-handling while staying fully compatible with existing Java code and libraries. Google made it an officially supported Android language in 2017, and in 2019 declared it Android's preferred language over Java.
How itβs actually used today
Kotlin is now the default choice for new Android app development β Google's own apps, Pinterest, Trello, and Netflix's Android client are all built with it. Because it interoperates directly with Java, companies with large existing Java codebases can adopt Kotlin gradually rather than rewriting everything at once, which is a big part of why adoption spread so fast.
Strengths & trade-offs
Kotlin fixes several long-standing Java annoyances β its null-safety system in particular prevents an entire class of crashes that used to be routine in Android apps. The trade-off is a smaller (though rapidly growing) hiring pool compared to Java, and slightly slower compile times on very large projects.
What to learn next
Since Kotlin's main use case is Android, learning the Android SDK and Jetpack Compose (Google's modern UI toolkit) is the natural next step. Knowing Java also helps, since a lot of real-world Android code and documentation still uses it.