At Google I/O 2019, it was announced that Android has officially become Kotlin first for developers. This is a piece of exciting news for all mobile devs across the world.
Henceforth Kotlin is 100% supported and Google has started shipping powerful libraries built with Kotlin. A good example is **Android KTX**, a set of Kotlin extensions which is part of the Android Jetpack family. It has been discovered that Google has been releasing robust libraries that leverage Kotlin in order to ensure that all new Android features, the framework, the IDE and all their libraries work seamlessly with the new language.
For the next few months, I will be sharing some helpful tutorials on getting started with Kotlin for Android devs. Throughout this series, I’ll show you all you need to become a **Kotlinier**, so I really do hope that these tutorials will help you comprehend the several ways Kotlin can make your development faster and also make your code much concise.
But before I unbox all the goodies that come with Kotlin, let me quickly give you a brief overview of this language.
What is Kotlin?
Kotlin is a general purpose, open source, statically typed “pragmatic” programming language for the JVM(Java Virtual Machine) and Android that combines both object-oriented and core functional programming features. It is majorly focused on clarity, interoperability, safety, and tooling support.
Kotlin was developed by JetBrains team based in St Petersburg, Russia, the brain behind IntelliJ IDEA IDE. The Kotlin team currently has more than 20 full-time members from JetBrains, and the Kotlin project on GitHub has more than 100 contributors. JetBrains uses Kotlin in developing most of its products including its flagship IntelliJ IDEA.
Kotlin is a great fit for developing Android applications, bringing all of the advantages of a modern language to the Android platform without necessarily introducing any new curtailments
Let’s take a look at the awesome benefits Kotlin has to offer Android developers:
No need for new IDE. Kotlin works with existing IDEs for Android
Getting started with Kotlin is never a problem for Android developers because Android Studio can comprehend, compile and run Kotlin code seamlessly. And the support for this language comes from Google, although JetBrains develops the Android Studio IDE. So Android developers are a beneficiary of this feature.
Kotlin is intuitive, so Java developers can easily learn
This language wasn’t built on an entirely different structure. Most parts of the language are similar to what Java developers already know.
Interoperability with java
Converting your entire java codebase to Kotlin made easy. You don’t necessarily have to convert all at once, you can do that based on features on the app. That implies you can have both Kotlin and java in your codebase. Kotlin is completely interoperable with Java, allowing to use all existing Android libraries in a Kotlin application. This includes annotation processing, so data binding, and Dagger work too.
It’s compatible with JDK 6
This language is 100% compatible with JDK 6, ensuring that Kotlin apps can run on older Android devices with no hassle. What about a build system?No!!! You don’t need a new one, Kotlin tooling is fully supported in Android Studio and compatible with the Android build system. Perfect!
Kotlin is expressive
Another interesting thing is that you can focus majorly on expressing your ideas and write less boilerplate code. 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.
Why you need Kotlin?
Before we dive deeper into the heart of Kotlin language, let’s look at some interesting features available in Kotlin:
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/57d3733421f72f78fcb5a73131782831
Say Goodbye to `findViewById`
Usually, if you want to avoid findViewById, you can use ButterKnife, a Dependency Injection library for view binding. With Kotlin, you can completely avoid `findViewById()` calls in your code without an external library, All you have to do is to focus on writing your logic with less verbosity and allow Kotlin to perform magic.
https://gist.github.com/Temidtech/ab3c56fb81283ac182e216ddb9864bc2
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/1bf9e8d7c7dfe248cb024da882e203c1
Extend functionality without inheritance
In Java, if you want to extend properties and functions you will have to inherit, thanks to Kotlin, you can easily extend the functionality of classes without necessarily inheriting from them.
https://gist.github.com/Temidtech/4a928e8fe44ca9fde2f81ab768ed5840
That’s a wrap!
In the next article, we are going to dive into the nitty-gritty of Kotlin.
Get ready to break into code!
📝 Read this story later in Journal.
👩💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.
No Comment! Be the first one.