Kotlin was announced as an official Android development language at Google I/O 2017. It became the third language fully supported for Android, in addition to Java and C++. At first when i saw this, i was sceptical about the whole Kotlin stuff maybe because i was already familiar with java. After a while, i decided to read extensively on Kotlin and Android, maybe i would find it interesting. To my amazement, Kotlin won my heart in few days!!!
Oh my that was pretty fast!!!
In this article, i will be sharing everything you need to know about Kotlin and Android. Trust me, you don’t wanna miss out on the amazing stuffs Kotlin has to offer android developers.
Kotlin is now an official language on Android. It’s expressive, concise, and powerful. Best of all, it’s interoperable with the existing Android languages and runtime. Isn’t this amazing?What this imply is that, you can use both java and Kotlin to build an android app. Let say you have MainActivity.java in your project, you can as well have LoginActivity.kt.
Why every developer needs Kotlin in their android development
Modern. Expressive. Safe.
Kotlin is concise while being expressive. It contains safety features for nullability and immutability, to make your Android apps healthy and performant by default.
- Safer Code: You can write safer code and avoid NullPointerExceptions in your app.
https://gist.github.com/Temidtech/111b8e47a71360e282144f92351f3600
- Say Goodbye to
findViewById:
Usually, if i want to avoid findViewById, i use ButterKnife, a dependency Injection library for views. With Kotlin, you can completely avoidfindViewById()
calls in your code without the help of a library, All you have to do is grab a cup of anything maybe coffee and focus on writing your logic with less verbosity. For me, this saves me some stress of writing lots of code just to perform a basic operation.
https://gist.github.com/Temidtech/59c3970f9c27edaa4ebf2f5e8ccd945e
- Readable and Concise: Another interesting thing is that you can focus majorly on expressing your ideas and write less boilerplate code.
https://gist.github.com/Temidtech/4a482ebe7b2f93ae7176fbf74e55232chttps://gist.github.com/Temidtech/003da0bcd46e616ea575b20ef393d2cd
With Kotlin, you can also reduce the number of overloaded functions by using default arguments. Call functions using named arguments to make your code more readable.
https://gist.github.com/Temidtech/b5b44af86ca486c9d7282a5f85e869dc
- Extend functionality without inheritance: In java, if you want to extend properties and functions you will have to inherit, thanks to Kotlin, you easily extend functionality of classes without inheriting from them. Calling code is readable and natural.
https://gist.github.com/Temidtech/e7b6b234d7e90bb8aa8a0f412cd25756
- 100% Interoperable with Java: When i read that Kotlin is interoperable with java, there was no time for doubt, i immediately tried it out, it worked!!!. You can add as little or as much of Kotlin as you want. Kotlin is a JVM language that’s completely interoperable with Java.
https://gist.github.com/Temidtech/3a71fc8399bfa701528131e0e4ec8549
In my next article, you will see Kotlin in action!!! We are going to build a simple app with a login page. This will help beginners to get started with kotlin. And if you want to try something more complex and interesting, i have an open source app you might want to try out.
You can check out the project on Github. This project is open to beginner, intermediate and advanced android developers. For updates on the project join other contributors on slack.
No Comment! Be the first one.