This article originally featured in our other blog. Has been added here for continuity and in context of android app development.
It’s that time of the year again. One of the major computing firms has put its weight behind yet another programming language and you are wondering why.
Kotlin as a new official Android development language
Meet Kotlin – Google’s new love . Its main development is run from a team of JetBrains developers based out of Russia. Kotlin version 1.0 was released on February 15, 2016 which is really recent. This is considered to be the first officially stable release of the language. Kotlin has since then been gaining support and is now, one of the official Development languages for Android, as announced by Google.
This is what Google Developer Product Group had to say about Kotlin: “We believe Kotlin is an excellent fit for Android not only because it gives developers what they want, but also because it matches the spirit of Android.”
Kotlin was announced as an official Android development language at Google I/O 2017. It has became the third language fully supported for Android, in addition to Java and C++.
The first thing to remember is that the key phrase here: “one of the”. So it’s not as if someone is taking away your choice to code in Java or C++. In fact as you will see below – choice and flexibility has actually increased.
Android App Development with Kotlin ?
We asked our developers to look at Kotlin , talk around and discuss among peers what they make of Kotlin.
We actually found that those that have used the language didn’t find the learning curve steep at all.
And that Kotlin added some capabilities which Java didn’t have, saving them time and effort.
Some of these capabilities were:
- Null safety through nullable and non-nullable types, safe calls and safe casts
- Extension functions
- Lambda expressions or Higher order Functions
- Data classes
- Type Aliases
Kotlin is fully compatible with Android Studio IDE and very importantly has full Java compatibility. This makes learning and getting used to it really easier and speeds up development. Any Java developer can get used to Kotlin within a matter of hours and you can even use both Kotlin and Java files in the same Android project.
Using Java libraries with Kotlin-based projects works flawlessly as well. And the reverse is also true.
Now lets look at some aspects of Java. To begin with, one of the feedback we get repeatedly from developers is that Java’s syntax is pretty verbose and that at it’s core – it’s still a procedural language. It still lacks some pretty stable features such as lambda expressions and functional interfaces.
This is where Kotlin Scores.
Kotlin for Android App Development – Features
Null Safety: Null safety is an interesting aspect of Kotlin where references that can be null have different type , and are thus enforced only during compilation. We get Null Pointer Exception free code and no run-time overhead due to extra Option wrapper.
Extension Functions: Extension functions are a feature that was missing in Java. With Kotlin, you can add behaviour to a class without directly extending it or using a design pattern like Decorator.
Data Classes: Let’s face it. No one likes creating classes with only properties (and many of them repetitive), to hold data. It can be tedious and boring but needs to be done for most business apps. But in Kotlin, you can declare the class and all it’s properties in a single line of code.
As another example specifically for Android, Kotlin also allows you to call reference to view implicitly to an activity which reduces boilerplate code. For example the code:
TextView text = (TextView) findViewById(R.id.myTextView); text.setText("Hi Folks");
myTextView.setText("Hi Folks") showing the brevity it brings
Cons with Kotlin for Android
There aren’t many cons with Kotlin, especially due to its inter-operability with Java. The only ones that one can think of are maybe the larger file package size than one built purely on Java – because of it’s own standard library. But also, Kotlin is little slower on Android studio.
The other issue with Kotlin is that it’s developer community and help resources are somewhat lesser currently, although this will definitely increase in the future.
Beginner and Intermediate Developers on Android
Have you just started to build android apps, or just starting learning android with Java as a base?
And suddenly Kotlin has come to the scene. What do you do now ? We’d suggesting sticking with Java because most likely you already had a Java base. Java on Android will remain and grow for a long time. Resources, tutorials and libraries on Kotlin are scarcer than for Java. Java has a strong base as an Object oriented language so definitely you should learn that. Switching into Kotlin will come naturally once you have worked on a few android apps at-least.
Conclusion: SO should you use Kotlin or Java for Android app development? Our thinking is that Java will be there for a long time to come, but that Kotlin can be a good second language to master for android developers. Java will see good support and investment from Oracle in the coming months and features which it lacks are likely to be added quicker than before.
From the end user point of view both would be pretty much equivalent, but it may be time saving for developers to code in Kotlin once they get used to it.
Incidentally, our Delhi based mobile app development company will be happy to assist on any questions or consultations you have in mind.