Signup/Sign In

Introduction to Kotlin

Welcome to Kotlin tutorial series. Kotlin is a relatively new programming language that targets the Java platform. We can use Kotlin almost everywhere in the place of Java. Kotlin can be used for developing server-side applications, android applications, in the data science field, and many more. Kotlin code can also be transpiled into JavaScript code. It is good to have some background knowledge in Java, but if you don’t have any prior knowledge in Java, it won’t be a problem.

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 History

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.

  • Kotlin v1.1 was released in March, 2017. The main features added in this release were introducing interoperability with JavaScript and support for coroutines (not stable though). Now developers can compile Kotlin code to JS and to run it in their browser.

  • 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.

3. Interoperable

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.

4. JavaScript Transpilation

You can transpile your Kotlin code to JavaScript code. So, we can write our code in Kotlin, transpile it to JavaScript and run it on browsers. It has one disadvantage though. When we transpile Kotlin code to JS, all the code in the project as well as standard libraries used are converted into JS code. But it will exclude any Java framework or library used. So, this might cause problem if you’re using Java libraries.

Kotlin has other features also like extension functions, named arguments and default arguments, data classes etc. We’ll cover them in later sections.

Summary

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?



About the author:
I'm a writer at studytonight.com.