Introduction to Kotlin
Kotlin has many features like its concise code, null safety, pragmatic nature etc. It is also completely interoperable with Java. So, it also supports all existing Java libraries and framework.
Kotlin language was created by JetBrains (same company which developed famous Java IDE IntelliJ IDEA) in 2010. It has been open sourced since 2012.
Kotlin get its name from an island named Kotlin island in Russia. The first version of kotlin was released in 2016 and latest version (in 2020) is Kotlin v1.3.
Brief history regarding Kotlin versions:
Kotlin v1.0, the first version of Kotlin was released in February, 2016. It was officially the first stable version of Kotlin.
The next version of Kotlin, Kotlin v1.2 was released in November, 2017. It allows developers to share same code between different platforms. We can write the business logic of your application once, and reuse it across all tiers of our application – the backend, the browser frontend and the Android mobile app.
Kotlin v1.3 was released in October, 2018. In this release coroutines were made stable. Now it was easier to read and write on-blocking code.
Kotlin v1.4 is under development and will be released in 2020.
In 2017, due to its gaining popularity, Google announced first-class support for Kotlin. In 2019, Google made Kotlin programming language as preferred language for android app development.
Features of Kotlin
Kotlin provides many features over Java. The main features why Kotlin is preferred over other languages are:
1. Concise code
The size of the code plays an important role in developer’s life. Suppose you joined a company where you’re assigned a task to replace an old functionality with new one or probably fix it. The first thing you’re required to do is to go through the codebase. As said earlier, If the size of codebase is huge, you’ll spend more time understanding the code than writing it. The simpler and concise the code is, the faster you’ll understand it.
Kotlin makes sure that each line of code carries some meaning with it. All the boilerplate code which is required in case of Java like getters, setters, assigning constructor parameter to fields etc is not required in Kotlin.
2. Null Safe
Kotlin make sure that our program does not throw NullPointerException at runtime. The type system of Kotlin tracks values that can be null. If any operation is performed on that value, which can lead to NullPointerException, Kotlin forbids it and gives error to avoid the error. We’ll discuss more about null safety in a separate section.
This is one of the most admired features of Kotlin. Kotlin is fully interoperable with Java. It means you can use Java libraries, call Java methods, extend Java classes, implement Java interfaces etc in your Kotlin codebase. You can have one class of your project written in Java and other one in Kotlin. They both will be able to use each other’s functionality.
Kotlin has other features also like extension functions, named arguments and default arguments, data classes etc. We’ll cover them in later sections.
In this tutorial, we had a quick look at what Kotlin language is, discussed its history and explored its features. If any of the feature discussed doesn't make sense right does, don't worry. We'll explore them in detail later.
Next, we'll see how to setup IDE for Kotlin and write our first hello-world program in Kotlin.
Also Read :- Java vs Kotlin: What is difference between Kotlin and Java?