How Kotlin won the language war in Android app development
As larger and more visible companies adopt Kotlin, it will become more attractive for other businesses to consider using it. We want to continue to provide a top-class language with good tooling
“Kotlin has become quite popular, especially since it’s been made the language of choice for Android development,” says Hadi Hariri, Kotlin developer advocate at JetBrains. JetBrains is Kotlin’s parent and it is trying to fit Kotlin into the existing multiverse of technologies – data science, web frontend, server-side, native, multiplatform and Android. Hariri describes Kotlin as a “multipurpose industrial language.” But it is Kotlin for Android development that is most popular globally, and especially in India. “In a country like India, where all applications are built mobile-first, with a 90% market share of Android, it’s a no brainer that everybody is writing applications for Android,” says Maneesh Sharma, country manager of software development platform GitHub.
With everybody starting to participate in the code economy, having simple languages really help. That’s why languages like Kotlin, Python and others are simplifying the syntax, making it easy to write code.
Kotlin was originally conceived as a project to cover the ground that Java could not. Its design ensures ease of use – syntaxes are simpler when compared to Java, yet core functionalities remain intact. Some estimates find it reduces the number of lines of code by 40% compared to Java because you can express more concisely what you want the machine to do. One big advantage is it takes care of what are called null pointer exceptions, which can potentially crash applications and which is an issue in Java programming.
Null pointer exceptions happen during the runtime of the code when variables are assigned no (null) value. “Kotlin is designed in such a way that you can’t write a lot of code that can generate null pointer exceptions,” says Arnav Gupta, cofounder of programming training platform Coding Blocks. The 100% interoperability with Java code is what gave Kotlin the initial momentum. “Existing Java code can be called from Kotlin in a natural way, and Kotlin code can be used from Java rather smoothly as well,” says kotlinlang.org.
When you use Kotlin without Java, it’s faster. But getting there will take time. JetBrains and the entire Kotlin ecosystem are pushing towards building more Kotlin libraries, rather than having to use Java libraries
The interoperability, added with code features that Java developers always longed for, made some coders dub Kotlin as ‘better Java’, says Gupta.
For those using Java for Android, the interoperability meant a smoother migration. The entire Kotlin ecosystem, Gupta says, has grown using Java as a crutch.
Most of the Kotlin developers are Android developers as well. “They never have to worry in particular about a Java line of code. Their solutions mixed with Java will work in Android,” adds Gupta.
But this version of Kotlin works with Android Runtime (ART), a virtual environment that allows the same code to run on varied platforms. That works beautifully in an Android world where smartphones come in numerous platforms.
One of the main advantages of using Kotlin is the ability to use it along with Java while writing code for an Android app. Developers can write some parts of the code in Java, other parts in Kotlin
But iOS and embedded devices require a different approach. That’s where Kotlin/Native comes in. It uses what is called LLVM (low level virtual machine, which is a set of compiler and toolchain technologies) to compile Kotlin code directly into machine readable code. LLVM compilation makes Kotlin/Native faster, but the code cannot have any Java dependencies. “If you want your code to be native for any hardware system, like an IoT device or an Android TV, you will use LLVM.
So far, I haven’t seen many developers in India do that,” says SiddheshPatil, mobile developer at Paytm Insider and organiser of the user group Kotlin Mumbai. Gupta agrees. “There is a lot of learning gap when we talk about Kotlin/Native,” he says.
Kotlin also saves a lot of development time because it allows for substantial code reuse through Kotlin Multiplatform Mobile (KMM). Code written in common Kotlin (be it business logic, infrastructure code, and other functionalities like core libraries, and basic tools) works everywhere.
If developers are making something new, they now do it in Kotlin. If there is legacy code that is in Java, that is being made interoperable with Kotlin. All developers understand that Kotlin is the way to go
Close to 10% of requirements from companies have been in mobile development, which has been for iOS or Kotlin for Android. We don’t see any demand for Java for mobile app development
Kotlin is seeing significant action on the server-side too. Hariri says among attendees at the KotlinConf events in recent times, around 40% are server-side developers.
“In the case of the JVM (Java Virtual Machine), you can use a wide variety of server-side technologies and frameworks such as Spring, Micronaut, Quarkus, and even Kotlin-specific frameworks such as Ktor, which is a great solution for building connected systems and microservices,” Hariri says.
Only time will tell if Kotlin becomes this overarching language that’s used everywhere, much like Java. Or it remains primarily in mobile app development.