Kotlin or Java? What language will work best for your next Android app development project? If you're a mobile app developer, Java is probably your go-to language for building Android apps. But there are new languages popping up all over the place that might challenge Java's dominance in the Android world. One of them is Kotlin, a relatively new programming language, which has been already announced by Google as a “first-class” language supported on Android.
What is Kotlin?
Kotlin was designed by programmers from JetBrains (the guys behind integrated development environments) to add some modern features to Java mobile development.
It has definitely gained momentum after being announced as an official programming language for Android at Google I/O in 2018. Google has also internally switched to using Kotlin instead of Java on Android.
Pros of Kotlin
- Kotlin has a lot of traction in Android development, but it’s also used in backend projects such as Spring 5;
- Thanks to the language’s scripting capabilities you can use Kotlin directly in your Gradle build scripts;
- Switching from Java to Kotlin is easy – just install the Kotlin plugin, add it to the Gradle build files, and click 'Convert';
- It supports modern programming concepts like extension functions, higher-order functions, delegates, and more out-of-the-box to help devs build clean APIs;
- Kotlin provides a built-in null safety support which is a lifesaver, especially on Android, which is full of old Java-style APIs
- It's way more concise and expressive than Java, which means less room for error;
- You can write new modules in Kotlin and be sure they will work alongside the existing Java code; Kotlin is compatible with all Java libraries and frameworks, the JVM, and can integrate with the Gradle or Maven build systems;
- Devs can benefit from a rapidly growing collection of open source projects on GitHub, many books, learning resources, and online courses;
- Adopting Kotlin doesn't cost anything (except for learning and training).
Cons of Kotlin
- Rather steep learning curve when switching entire teams to Kotlin due to the language's concise syntax (both a blessing and a challenge);
- Relatively smaller developer community compared to Java, which means limited learning resources and difficulty in finding answers to questions; one look at Stack Overflow will give you a rough idea – there are only around 45,046 questions tagged with Kotlin against 1.7 million questions about Java (September 2020);
- There are more and more Kotlin developers available, however finding an experienced mentor for your team might require a bit more effort;
- Kotlin, being a highly declarative language, sometimes tends to generate great amounts of boilerplate in corresponding JVM bytecode;
Kotlin use cases
Here are a few amazing apps written in Kotlin:
- Pinterest - a mobile app for the popular creative idea sharing social app;
- Trello - a visual tool for organizing work with customizable to-do lists.
- CarLens - a car recognition app powered by machine learning made by the Netguru R&D team for detecting cars and showing information about them. Its code is available on GitHub;
What is Java
Java is the favourite of many developers when it comes to Android app development – mainly because Android itself used to be written in Java. Developed by Sun Microsystems (now the property of Oracle), Java is an object-oriented programming language that boasts the title of the second most active language on GitHub. And no wonder – it’s been around for over 20 years, and its popularity only seems to grow.
Pros of Java
- Easy to learn and understand;
- Flexible – you can run it in a browser window or a virtual machine. This comes in handy when you reuse code and update software;
- Android relies on Java – the Android SDK contains many standard Java libraries;
- Java has a large open-source ecosystem, partly as a result of Google's adoption of the Java Virtual Machine (JVM) for Android;
- Accelerated assembly within Gradle – we're all thankful for it when assembling large projects;
- Java apps are more compact and are easier to be optimized when better performance is required. Also, in comparison to Kotlin, Java apps tend to be lighter (even in full analogue) as Java is a more imperative language;
Cons of Java
- Java has limitations that cause problems with Android API design;
- As a verbose language, Java requires writing more code, which carries a higher risk of errors and bugs;
- It’s slower in comparison to many other languages and requires a lot of memory.
Java use cases
Here are some examples of prominent open source apps written in Java:
- Android-oss - the official kickstarter.com Android app, a social platform for funding creative projects;
- NewPipe - a lightweight video streaming app project for Android;
- Wordpress Engineering - the official WordPress App for Android. (Although new features are developed in Kotlin, the core codebase is still made up of Java code.)
Why use Kotlin for Android
You may wonder - what is the point of making the switch from Java to Kotlin?
And the main argument might be the fact that Kotlin is designed to address Java’s issues. It means that Kotlin provides many safety mechanisms available out-of-the-box while being more concise and expressive than Java at the same time.
Perhaps that's why Kotlin is among the top five languages most beloved by developers, which accounts for % of developers who are developing with the technology or language and have expressed interest in continuing (Stack Overflow 2019, 100.000 respondents).
Build your Android app with the best programming language
While Kotlin offers many advantages that Java doesn't, it still has some shortcomings. When letting your team experiment with Kotlin, remember that transitioning to a new language isn't always that exciting for developers who have already found the tools and strategies that work for them.
You'll need to give your team at least a month to get familiar with Kotlin, risking that some team members might not adapt in time for the launch of your Kotlin project. You also need to bear in mind that Java isn’t going anywhere and will remain essential for Android app development.
But if you're a beginner looking for a new challenge, it makes sense to try Kotlin, especially if you'd like to work on innovative projects for startups. If you're running a team of mobile developers, however, it's best to experiment with Kotlin one step at a time to check whether the new language brings you tangible benefits.
This article was first published on Feb 20, 2018