Learn Kotlin: Introduction
Learn Kotlin — the modern, concise and safe programming language — through this succint articles series.
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?
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?
Three words : concise, safe, and interoperable.
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.
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.
Kotlin get rid of boilerplates and let you just write more concise code.
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.
You can declare a variable as a nullable. However, Kotlin protects you from mistakenly operating on nullable types since it will potentially throws NPE.
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.