Kotlin vs. Java – Why Kotlin on Android is Here to Stay

Kotlin Logo

Android is a popular mobile platform, but it lacks some of the basic language features in Java that iOS has with Swift. Even on the Android framework, Java is a verbose language.

Other contenders like Clojure and Scala have come before to make the JVM more friendly, but they have fallen short of widespread usage. Now there’s Kotlin, which is here to make mobile development easier on Android, and to end the mutation and Null Pointer Exceptions of the past.

Kotlin received a big endorsement in May 2017, when Google announced official support for the language on Android. If you’re thinking about trying it as an alternative to Java in Android, here are a few things to consider:

Java 8 Still Isn’t Available on Android

This fact is clear from the moment one jumps into Android Studio, but it’s worth mentioning either way. While JVM versions have been upgraded in recent versions of Android, older Android devices will always be left out.

Google has remedied this in part by releasing Java 8 language features in Android Studio 3, but the move doesn’t go far enough for developers who want more advanced features like Functional Interfaces or Java Streams.

Kotlin Is a Bridge to Functional Programming

The promise of a language like Clojure was to bring a “general-purpose language…where Java is suitable.” In practice, the issue with this claim is the built-in knowledge of C-like languages around Java codebases.

Kotlin reads much more like Java than Clojure ever could, and to iOS developers, it reads much more closely to Swift. These surface-level similarities help over time to establish a cornerstone for exploration, and they can lead to a more idiomatic codebase.

Beyond syntax, Kotlin provides language features that aren’t available to legacy devices in Android. Sequences take the place of Streams, and functions in Kotlin can be used like the Function interfaces in Java. Furthermore, language features such as lambdas and null safety are available out of the box.

The main pull in Kotlin is toward code that handles null cases more explicitly and handles mutability in a reasonable way, all while maintaining full Java interoperability.

Kotlin Reduces Verbosity

Most Java developers will know that a simple “hello world” program involves an entire class to run. In a small example, Kotlin reduces the amount of code:

println("Hello world.")

No class. No main method.

From string interpolation to class extensions, Kotlin reads like a more modern language than Java. Even more C-like languages like C# have adopted implicit getters and setters, which are present in Kotlin.

My favorite Android features are the Kotlin Android Extensions, which remove the need of verbose, vanilla Java or third-party view dependency injection tools like Butter Knife.

The Cost

Chances are that if you’re programming in Android, you’re using Android Studio or IntelliJ. The downside of using Kotlin is that some configuration is required. Luckily, for the current Android Studio version, Kotlin support is free in the form of an IDE plugin.

Kotlin will be supported by default in Android Studio 3 once it is officially released. For more information, check out a Google I/O 2017 talk from Christina Lee and Jake Wharton, two well-known Android developers who discussed the features and realities of Kotlin in production.