Learn Kotlin: Introduction

Learn Kotlin — the modern, concise and safe programming language — through this succint articles series.

Deddy Romnan Rumapea
3 min readFeb 11, 2021
A ship heading to Kotlin Island — Photo by Egor on Unsplash

Kotlin was created back in 2010 by JetBrains and named after an island located near their headquarter in St. Petersburg.

About seven years later — in 2017 — Google announces their support for Kotlin on Android Development. Two years after that, Google announces Android Development will be increasingly Kotlin first.

Now that you know a little bit of the Kotlin background and that Google puts priority on Kotlin instead of C++ or Java (which are also supported for Native Android Development), you might ask :

What’s so good about Kotlin then?

Or maybe

I’m already comfortable working with Java. Why should I bother learning Kotlin?

Well, let’s move on from “the what” and talk about “the why”. Shall we?

Why Kotlin.

Three words : concise, safe, and interoperable.

Concise

Kotlin is extremely concise compared to Java. If you are a Java developer, this is definitely something that you will notice when you first look at Kotlin code. For example let’s see a sample POJO class in Kotlin.

Sample POJO class

And that’s it, you only need to write a single line of code to create a POJO class. All the getters and setters is already available to use.

Want to create a singleton class? Easy peasy. In Kotlin, singleton is declared as object.

Sample singleton class

Kotlin get rid of boilerplates and let you just write more concise code.

Safe

Kotlin just won’t let you fall into the billion dollar mistake AKA Null Pointer Exception (NPE). Kotlin checks for null pointers in compile time and prevents you from running it. These are some examples on how Kotlin protect you from NPE :

You will get compilation error when you assign null to a non nullable type variable.

null can not be assigned to a non-nullable variable

You can declare a variable as a nullable. However, Kotlin protects you from mistakenly operating on nullable types since it will potentially throws NPE.

Kotlin won’t let you mistakenly operating nullable variables

Interoperable

You can use any existing library on the JVM (Java Virtual Machine), as there’s 100% compatibility, including SAM support. Target either the JVM or JavaScript. Write code in Kotlin and decide where you want to deploy to.

- kotlinlang.org

If you are not really sure what that means, just know that Kotlin can run on multiple platform mobile, server-side, web frontend, and of course Android.

So now you have learned about the what, when, and why of Kotlin. In the next article we will write and run our first code in Kotlin.

That’s it! I hope you guys got some value out of this article and if you did please leave a comment below, it means a lot to me. I’m open to any suggestion. Thank you for reading.

— Learn Kotlin Series —

  1. Learn Kotlin: Introduction (this article)
  2. Learn Kotlin: Hello World!
  3. Learn Kotlin: Variables
  4. Learn Kotlin: Data Types
  5. Learn Kotlin: Basic Operators
  6. Learn Kotlin: Functions

--

--