Kotlin vs Java for Android Development: Is It Time to Abandon Java?
Table of Contents

Kotlin vs Java for Android Development: Is It Time to Abandon Java?

Karlo Karagic
Senior Android Developer
Aleksander Jess
Content Marketer & Technical Expert

This text is contributed by Karlo Karagic, Senior Android Developer at ITMAGINATION.

If you are asking this question in 2022, we think you already know the answer, and are only seeking confirmation. Nevertheless, unchallenged truths become dead dogmas: this blog post is intended to be a short reference point for all who ask this question. We will try to explain which language you should pick in which scenario.

Is It Time to Ditch Java? Short Answer?

Yes.

Long Answer

Almost always, the answer is going to be yes. In our opinion, Java is a great learning language due to its verbosity, which gives it a clear and easy-to-understand syntax. Verbosity, often treated as an anti-feature, is a plus here. Oracle’s language has a lot of useful features that make it simple to learn it and understand. Because of this, it's a great language for fresh grads and junior developers to start their programming careers with. We’ll cover details of this aspect in the following sections.

An Even Longer Answer

In this section, you can find several real-life scenarios that could reasonably happen in your app development lifecycle, to better consider all circumstances you may meet.

Creating a New App

We think that when creating a new mobile app, this is an easy decision. You should go with Kotlin. The app will probably be used for years, and we don't think that Google will drop support for Kotlin any time soon, nor are there any reasons for the move.  

When it comes to Java, it stopped being recommended by Google for years now. You may safely consider new apps being written in Java as having a ton of “technical debt” right from the start because it will have to be rewritten in Kotlin at some point.

Winner? Kotlin.

You Have Many Fresh Grads/Juniors on Your Team

Hopefully, you have someone to guide those young guys in their day-to-day challenges, and they are not writing production code by themselves. If that is the case, we would still go with Kotlin because you will have to, most likely, rewrite everything if you start with Java.

If you are planning to build strong programming fundamentals in the juniors on your team, a small internal project could be written in Java. Kotlin has a lot of syntax sugar which hides some complex implementations and concepts. Make it harder for your newbies to write an app at first, to train them better.

Apps in Kotlin are usually 40% shorter than Java apps, which is great if you have developers who can utilize this speed boost. For learning purposes, however, this means it's a bit harder to read and understand the code. Additionally, Kotlin tends to make some stuff too easy, so fresh developers could start out with a few missing “chapters” in their development. One great example is concurrency in Java. Kotlin hides away the intricacies all too well.

To sum up this paragraph: if you are working only on production code, write it in Kotlin with close cooperation with more senior developers. If you have some small projects or assignments, or are building an internal app, ask them to write an MVP (Minimum Viable Product) in Java first. After that, they may switch to Kotlin.

Winner? Usually Kotlin, sometimes Java.

You Care About App Build Speed

If, for whatever reason, you prioritize build speed over all else (maybe due to really short release cycles) you may be tempted to write it in Java, as it is considered to have a shorter build time. There are some caveats here:

It is true. Java is faster for cold builds (building the app from scratch) by up to 15% depending on your device configuration. It is almost on par with Kotlin when it comes to incremental builds, however. As you are making incremental builds 95% of the time, cold build performance penalty doesn't matter that much. If you are interested in this topic, specifically, go here.

If you still think the speed of Java is worth it, let’s look at it from a different angle. Let's say you get a 15% performance boost when building the app (in all cases) which saves you 15% of your computing resources. This is not a small difference. What about your development time? Saving time for computers will be a trade-off: your people will lose time.  

To reiterate, Kotlin apps are, on average, 40% shorter which equals shorter development time and fewer places for bugs to hide. Let's say this gives a 15% performance boost. Saving this little on computing costs means nothing, when you may save much, much more money if you cut your development time.  

Computers are getting faster, and faster, so the gap in compilation time will diminish over time. Building the same 100k line app (100,000 lines of code) on an Intel Mac from 2020 and an M1 Mac from 2021 went down from 8 minutes to 2 minutes.  

Winner? Kotlin.

All Your Code Is in Java

Good news! Kotlin and Java are completely interoperable. This means that you can write one file in Kotlin and one file in Java, and they can work together pretty seamlessly. This means there is absolutely no reason for you not to try writing new features in Kotlin (or rewriting old ones). Crucially, you may use Java in Kotlin, however not the other way around.

As the time goes by, when you add more Kotlin code, you will probably want to move your entire codebase to Kotlin. There is an automatic tool which does that for you, though be careful it is not 100% safe, so exercise caution. Nevertheless, it can speed up the process a lot.

Let’s take a look at an example. We will calculate the Nth Fibonacci number, and use Java code from Kotlin. Here goes:

Winner? Kotlin.

All Your Teammates Know Java and Don’t Know Kotlin

Even if this is your case, it is worth to move to Kotlin. You will probably take a short-term kick to performance (maybe a bug here and there) but mid-to-long-term you will see improvements to speed and stability. Also, don’t forget, that Kotlin is one of the most loved programming languages in the world, and it is a joy to work with.  

As we mentioned already, Java and Kotlin are interoperable and as such, transition for developers can also be gradual. Your team can write just the new features on Kotlin and pick up the new language on the way. It just takes getting used to the few new features and some syntactic sugar. Luckily, Kotlin documentation is superb, and it should help a lot.

Winner? Kotlin.

You Want to Be Future-Proof

We already mentioned this, but to recap, Google did not drop support for Java (yet?), and they are recommending Kotlin for a few years now. Not many people/companies are investing in the Java ecosystem for Android, as the focus has shifted to Kotlin. Keep in mind that Java is currently at version 17 while the Android ecosystem is stuck with Java 11. This will not change any time soon, either. You can find more details here.

New libraries for Android development are released for Kotlin. A good example of this is Jetpack Compose - a modern toolkit for building native UIs which is, most likely, the future for Android development (the UI layer at least). This toolkit does NOT work with Java and as far as the Compose team said, they don’t have plans to change that at this moment, if at all. This could be one of the biggest reasons not to use Java for projects that will go on for some years in the future, as you are locking yourself out of this great tool.

Winner? Kotlin.

Maybe You’ll Want to Support iOS in the Future

Currently, the best way to develop cross-platform mobile apps is to use React Native or Flutter but if you want to stick to JVM languages keep reading.

As things stand currently there is no reasonable way to write an iOS app in Java and nothing is on the horizon.

Kotlin on the other hand does have an ace up its sleeve. Kotlin Multiplatform Mobile or KMM for short. In short, it allows you to share code between Android and iOS apps written in Kotlin. The best part it is it allows you to make as much of the functionality shared as you want, as it also allows you to write native code as well. The solution might not be the most practical at the moment, though we expect the situation to improve.

Winner? Kotlin.

You Want to Hire a Lot of New Android Developers

Considering that Kotlin is the suggested language to use for Android development, we think this is the one to use here as well. There are a few things to think about here:

  • Any newer developers will probably focus on Kotlin for Android, as it is the suggested language for native development.
  • Any older experts who don’t know Kotlin and haven’t even heard of it obviously don’t keep in touch with modern Android development and should probably be avoided (we are generalizing here, use common sense).
  • It's a fun experience to move from Java to Kotlin, while it's not so enjoyable the other way around. In other words, you can lure Java specialists to the Kotlin world, but it will be very hard to do the same the other way around.

Winner? Java. Just kidding. Kotlin!

Conclusion

The conclusion is obvious. You should really focus on Kotlin in 2022. It's a really nice programming language with tons of features. It is loved by developers, it improves the speed of app development and lowers the number of bugs.

Kotlin also has more prospects with constant improvements to libraries, fast progress of the Kotlin language and support for Jetpack Compose (the next big thing in Android). On the other hand, Java for Android is stuck in 2018 with Java 11.

If you are very engrossed in the Java world, Kotlin made it ridiculously easy to switch. You may learn as you go, develop only new features in Kotlin, or even parts of features. The documentation is excellent and there are many Kotlin developers on, e.g., Stack Overflow, willing to help out.

If you're looking for expert Kotlin developers to help you out with your development, make sureto reach out!

Liked the article? subscribe to updates!
360° IT Check is a weekly publication where we bring you the latest and greatest in the world of tech. We cover topics like emerging technologies & frameworks, news about innovative startups, and other topics which affect the world of tech directly or indirectly.

Like what you’re reading? Make sure to subscribe to our weekly newsletter!
Categories:
Share

Join 17,850 tech enthusiasts for your weekly dose of tech news

By filling in the above fields and clicking “Subscribe”, you agree to the processing by ITMAGINATION of your personal data contained in the above form for the purposes of sending you messages in the form of newsletter subscription, in accordance with our Privacy Policy.
Thank you! Your submission has been received!
We will send you at most one email per week with our latest tech news and insights.

In the meantime, feel free to explore this page or our Resources page for eBooks, technical guides, GitHub Demos, and more!
Oops! Something went wrong while submitting the form.

Related articles

Our Partners & Certifications
Microsoft Gold Partner Certification 2021 for ITMAGINATION
AWS Partner Network ITMAGINATION
ISO 9001 ITMAGINATIONISO-IEC 27001:2013 ITMAGINATION
Great Place To Work
ITMAGINATION Winner Great Place To Work Best Workplaces Poland 2021
© 2022 ITMAGINATION. All Rights Reserved. Privacy Policy
// Opening all links in new tab // Syntax Highlighting Code