Kotlin is a programming language created at JetBrains. It was developed in 2011 to replace Java, which the company considered too verbose. The new language is 40% more compact than its predecessor, which helped speed up work on the main JetBrains product – the IntelliJ IDEA development environment. At the same time, Kotlin is fully compatible with Java because it runs on its virtual machine (JVM).
To provide a formal definition, Kotlin is an object-oriented language with static typing. What does this mean?
Object-oriented languages are languages in which all operations are performed with objects, which are blocks of code into which multiple values can be “stacked”. An object can be any entity with a defined set of properties. For example, a character in an online game or a sticker with SpongeBob in Telegram. All objects are designed in special patterns, which are called classes.
Static typing means that the types of variables are set by the developer before the program is executed. If you declare an integer variable, you can no longer put text in it – the compiler will immediately point out the error. This slows down development at the beginning, but adds reliability.
If you want to know more about typification and its types, read one of our previous articles – it’s clear and easy to understand there.
By the way, the roots of the now international JetBrains are in St. Petersburg. And they named their language after an island in the Gulf of Finland. In addition to hinting at St. Petersburg, this name also emphasizes the connection with Java (Java and Kotlin are both islands).
What you can write in Kotlin
Kotlin can potentially be used wherever Java works, which includes the backend, the web, the desktop, and a bunch of other tasks. As Andrei Breslav, the creator of the language, says, “Kotlin is a language for all platforms.” And there’s a lot of truth to that.
However, every language has its own niche – the area where most programmers use it. Kotlin so far has two of them – a server and mobile development. Although it is increasingly common in other areas – such as science and Data Science.
Let’s look at all areas in order.
Android applications
Until 2017, Java was the official language for Android apps, but then Google announced its mobile OS Kotlin-first:
partly because of a long trial with Oracle over the use of some Java mechanics;
partly because developers liked the new language, started spontaneously writing mobile apps in it, and regularly rubbed the corporation the wrong way: “You’re going to support Kotlin, aren’t you? Well, make it official! It’s good!”
Today, 80% of the most downloaded apps in the Play Market are written in Kotlin, including apps from Netflix, Twitter, Reddit and Google itself.
Server apps
Thanks to its JVM compatibility, Kotlin can run on any server that runs Java. This is why it is often used to create the backend – the part of the systems that runs on the server and is not visible to the average user. For example, Jira cloud services and some Adobe products are already running on Kotlin.
This niche is one of the priorities for the Kotlin team. And despite the popularity of Kotlin in mobile development, JetBrains DevRel teams talk about their language exclusively in the context of server-side development, without mentioning mobile at all.
Web applications (frontend)
In addition to the backend, there’s the frontend – the “frontend” side of the web. These are the different buttons, drop-down menus and windows with which users interact. Almost the entire frontend is written in the same language – JavaScript.
But Kotlin can compile into JavaScript, so you can use this version to write the frontend. That is, it is quite realistic to write the entire web application in it, both the logic and the interface.
Cross-platform mobile apps
Suppose we need to write a mobile app for scooter rentals. It should work equally well on iPhones and Android smartphones.
In this case cross-platform development can help us – it’s when we write the code once and then adapt it to multiple systems. Kotlin has a technology that allows us to do this, called Multiplatform.
Science and big data
If you’ve worked with data science, you probably know about Jupyter Notebook. It’s a development environment that can execute code piece by piece and produce results instantly. It’s often used in machine learning, statistics, and data visualization. Jupyter used to be written only in Python, Ruby and R, but now it’s also available in Kotlin. All you have to do is plug in a couple of libraries, and you can make your own Siri or Alice.
Kotlin vs Java
As we wrote above, Java and Kotlin are functionally compatible languages. They are indeed very similar: both are statically typed, support OOP and run on the JVM. In some development environments their functions and classes can even be mixed. Now let’s see how these languages differ.