On 17 May 2017, Google announced first-class support for Kotlin, meaning Kotlin became an official programming language for Android application development.
Since then, JetBrains proved that Kotlin can also be successfully used for writing iOS apps – the official app of KotlinConf 2017 was built entirely in Kotlin and supported iOS and Android, as well as most browsers via its web app.
What is Kotlin and what are its origins?
Kotlin is an open-source statically-typed programming language generating code that can run on a Java virtual machine (JVM). It was developed by JetBrains, and its name comes from Kotlin Island near St. Petersburg, Russia.
While Kotlin’s syntax isn’t compatible with Java (the programming language historically used to develop apps for the Android platform), it can interoperate with Java code. In other words, code written in Kotlin works with Java just as well as it does natively. And in some cases, we can use JVM Platform Annotations in Kotlin to access Kotlin’s codebase from Java code.
Kotlin uses aggressive inference to determine the types of values and expressions if they’re not clearly stated. It makes the language even more distinctive from Java, which sometimes requires repetitious type specifications.
Despite being introduced back in 2011, it wasn’t until Google’s announcement officially supporting Kotlin as a first-class Android development language that it grabbed the interest of the global community.
That being said, leading tech companies like Atlassian, Uber, and Pinterest had already started using Kotlin for Android app development long before it was officially supported.
Prior to using Kotlin for your next Android app project, it’s a good idea to explore the advantages and disadvantages of Kotlin.
Kotlin addresses several Java issues
Kotlin is a powerful, modern, and efficient language with many useful features. It’s expressive and more concise than Java.
While Java earned its reputation as a robust and reliable programming language, it lacks many features and is slowly becoming obsolete, making Kotlin a worthy alternative to replace it.
When it comes to strictly technological advantages, Kotlin offers first-class support for functional programming, even though it’s mainly object-oriented. For instance, Arrow is a widely accepted “companion to Kotlin's Standard Library”, further extending functional programming opportunities.
Apart from that, JetBrains built protection against errors related to nulls straight into the type system, making the Kotlin programming language more fault-proof, and therefore easier and cheaper to maintain than Java.
The creator of null famously said that the null reference must have generated billions of dollars in losses caused by errors, vulnerabilities, and system crashes. Now, you can stop fearing null-related errors and save yourself some money, too.
Kotlin is also a big change when it comes to asynchronous programming. Thanks to coroutine, developers can work with asynchronous code more easily than ever. Used together with Flow (Kotlin’s reactive stream), coroutine can be an excellent replacement for RxJava. However, it’s worth noting that many job specs still cite RxJava as a required skill.
Apart from developing Android apps (and more recently iOS), Kotlin is also valuable for JVM development. Why? It facilitates desktop, web, and backend server application builds using established Java frameworks like Spring, Vaadin, Spark, Hadoop, etc.
Pros of using Kotlin for Android app development
Kotlin is well-regarded by mobile app developers; many now prefer it to Java, its elder counterpart. Below are Kotlin’s most prominent benefits.
Increases team efficiency
Being clear and compact, the Kotlin language increases team efficiency thanks to its intuitive and succinct syntax. Using Kotlin, it’s possible to get through more work because it takes less time and fewer lines to write and deploy working code.
Complies with existing Java code
Kotlin is positioned as a 100% Java-interoperable programming language. It’s consistent with Java code and all related tools and frameworks, making it possible to switch to Kotlin step by step. If your product can’t be written solely in Kotlin, it’s possible to comfortably use both programming languages at the same time.
Kotlin is supported by a vast majority of IDEs, including Android Studio and other SDK tools. This helps increase developers’ productivity because they can continue to work with the toolkit they’re used to.
Kotlin code is clearer and more compact than Java, helping developers ensure production code is stable and consistent. Bugs are detected at the compile stage, so Android developers can fix errors before runtime.
Accelerates UI development through Jetpack Compose
Jetpack Compose is a powerful toolkit that’s only available using Kotlin. It offers a declarative way to efficiently create UI for Android apps and other platforms, with less boilerplate code – the codebase is created in a single language without using XML. Moreover, managing and updating the UI is easier and more reliable. This is a Kotlin Multiplatform Mobile (KMM) way of developing UI (more on KMM below).
Cons of Kotlin for Android app development
Before you use Kotlin for your Android projects, consider the following disadvantages.
Kotlin still decompiles to Java, and its language features are based on what’s available in the current version of the JVM supported by Android. Since Android doesn't use the newest iteration of Java, Kotlin developers have to find workarounds for implementing some features.
Fluctuating compilation speed
In some cases, Kotlin is faster than Java – mostly when performing incremental builds. However, Java is the winner when it comes to clean builds.
Basic Java understanding is still a "nice to have"
Mobile and web app development development jobs increasingly require Kotlin, but for older projects with legacy codebase, knowledge of Java is beneficial, meaning developers should ideally have a basic understanding of it.
Business benefits of Android app development with the Kotlin programming language
After weighing up Kotlin’s pros and cons and drawing on our experience using the language, we recommend converting to Kotlin for a number of reasons.
Being more fault-proof, apps are easier and cheaper to maintain. Kotlin also facilitates faster development because it’s more concise. Estimates show it offers as much as a 40% reduction in lines of code compared to Java.
Fewer lines of code = less time spent on coding = less money spent on development. Oh, and there’s an automatic Kotlin-to-Java converter, helping you automatically convert Java code to Kotlin code.
Furthermore, the JetBrains team has launched Kotlin Multiplatform Mobile (KMM), giving developers the ability to build multi-platform applications with shared codebases – for example, Android and iOS apps.
Android app development: future insight
In the Android development world, Kotlin is now a must-have because new applications are preferably written in Kotlin. On the other hand, some of the bigger libraries are still written in Java, meaning this long-standing code is unlikely to become obsolete in the near future (or, perhaps, in the distant future).
Official support from a giant like Google is a big step towards making Kotlin as popular as Java (or even more so). But let's not forget that Java is not only used on Android – its ecosystem is huge and still broadly used in other departments. This means that switching to Kotlin often won't make sense from a business perspective.
It’s safe to say that Kotlin and Java will be used together for some time to come.
However, the sooner you switch to Kotlin for Android development, the sooner you can use Jetpack Compose and coroutines, reducing development time.
All of our new projects are written in Kotlin, and our developers are extremely happy with it. At the same time, we’re not planning on dropping Java right now, as we’re still working with it on several existing projects.
If you have any questions regarding Kotlin’s pros and cons or the best tech stack for Android app development, drop us a line – our team is on hand to partner with you and develop a solution that suits your individual needs.