When Kotlin was presented at the Google IO 2017 I was not sure if to be happy or to cry, from one hand I had Java that I am working with almost 8 years and from other hand Kotlin that should be easier and fun for coding. Community love Kotlin and I love community, so let check what we can get from this love story :)
Before we start, fun fact about Kotlin, it was named by the name of island, one of the language developers propose this idea to the team and everyone loved it, so it become the name of the language.
Kotlin was born at 2010, and in 2011 JetBrains published about it to the world, at 2016 we get 1.0 version of Kotlin and in 2017 it is officially supported as Android development language by Google. Java exist already many years and we have more complex problems that we need to solve, and it is hard to solve with Java. This is why we have new platforms like Scala, Groovy and other children, all this children live in JVM and Kotlin is part of this family.
Kotlin is a new language that will give you the ability to code and create your projects in a new way, you will write it like Java but with better syntax. It remind a little Scala but it is much easier.
I had not experienced Kotlin yet and it is a good opportunity to start a journey to learn and experiment together with you the abilities of the language. The language is totally compatible with java so we will not have any overhead of using it.
In upcoming series of my articles we will learn the basic abilities of the language and check some examples to see how good Kotlin.
I will use Android studio 3.0, it support kotlin out of the box, you don’t need to add additional plugins to it. just mark to include Kotlin support when you creating new project.
The project created automatically but lets check what extra we get in the project so it will able to support Kotlin and not only Java.
We get the Kotlin configuration in main project gradle file that have the Kotlin language plugin support.
And in app module gradle file we will have plugin kotlin added as well.
Now lets compare what the language syntax difference between Java and Kotlin.
If we will look in both examples it looks almost the same, beside couple of changes. the first thing that can be notice is that the method start with ‘fun’, It looks like fun way to write a code (or short name of function). Another interesting part is question mark in the Bundle parameter, this mean that it can be nullable, as a default in Kotlin it is non nullable.
More syntax changes is the extend changed to ‘:’ and definition of type is after the parameter name. One more small thing that you don’t need to put ‘;’ in the end of row.
This all for now, in upcoming articles I will be more focused on Kotlin structures and abilities, meanwhile you can create your first Android app in Kotlin.