Kotlin is everywhere. But what is Kotlin? How to begin with Kotlin? and where do we use Kotlin? In this blog we try to answer all relevant questions about same.

What is Kotlin?

Kotlin is an OSS statically typed programming language that targets the JVM, Android, JavaScript, and Native language. It is developed by JetBrains. The project started in 2010 and was open source from its initial days. The first official 1.0 release was in February 2016. Kotlin does not aim to be unique but it draws inspiration from decades of language development. It exists in variants that target the JVM (Kotlin/JVM), JavaScript (Kotlin/JS), and Native code (Kotlin/Native).

Why Kotlin?

Kotlin provides some powerful features that tend to be extremely beneficial and also significantly improves the productivity of developers.

Concise: Kotlin drastically reduces the amount of boilerplate code. The fewer lines of code mean that you spend less time to write, read, and debug the code. The best example to demonstrate conciseness is the way of creating a class (also known as POJO for Java users) with the getters, setters, equals(), hashCode(), toString(), and copy() methods. This operation can be performed by using the following line of code:

data class User(val name: String, val email: String, val address: String)

Null safe: The NullPointerException exceptions are extremely infuriating for developers. The Kotlin’s type system is aimed to eliminate the occurrence of NullPointerException from every code. It distinguishes between references that can hold null (known as nullable references) and those that cannot hold null values (known as non-null references). Therefore, Kotlin protects you from mistakenly operating on nullable types.

val name: String? = null // Nullable type
println(name.length()) // Compilation error

Interoperable- Kotlin allows you to use any existing libraries on the JVM because it provides 100% compatibility and SAM support. It is also possible to target either the JVM or JavaScript. You can write code in Kotlin and decide where to deploy. For instance:

import kotlin.browser.window

fun onLoad() {
   window.document.body!!.innerHTML += “<br/>Hello, Kotlin!”

Extensions: Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use design patterns such as Decorator. This is done by using special declarations called extensions. For example, you can write new functions for a class from an external library that you cannot modify. These types of functions can be called in the usual way if they are the methods of the original class. This mechanism is called extension functions. There are also extension properties that allow you to define new properties for existing classes.

Kotlin is highly tool-friendly in terms of functionality. It offers coroutines, high-order functions, lambdas and much more.


A Complete Guide on Getting Started with Kotlin [Cheat Sheet included]
2.15 GEEK