Kotlin vs Java: For Android Apps and Beyond in 2021

Updated: Sep 06, 2020
10 min read

Kotlin is designed to improve developer productivity and overcome the shortcomings of existing languages like Java and C++. So, by design, Kotlin has advantages over Java in many areas. This makes Kotlin vs Java debate obvious, let us get into details.

Developers migrating from Java to Kotlin claim they need to write 30% less code to achieve the same objective in Kotlin as compared to Java.

While 30% productivity gain is huge, Java too has made many improvements with Java 8 onwards. The productivity gap should reduce if you rewrite java code with the latest Java features. 

Nonetheless, I love Kotlin too and there is a lot more than just the productivity gain. 

Kotlin vs Java

So, the big question is whether you should switch from Java to Kotlin? and for the newcomers, whether you should start off with modern Kotlin or rely on age-old Java? 

At 2019 I/O, Google announced Kotlin as the language of choice for Android development and declared that any further progress in the Android ecosystem would be Kotlin first.

Also check out: Best Kotlin Tutorials and Courses

While Android apps development is not the only thing you do with Kotlin and Java, this announcement from Google ignited this Kotlin vs Java debate. 

Also, it is important to know that Google has already built 60+ apps using Kotlin including Google Play, Maps, and Home. Apart from Google, many enterprises including Uber, Evernote, Pinterest, and Atlassian have started using Kotlin in their apps. Some of them have completely upgraded the code base to Kotlin.

More than 50% of the recent apps released on the Play store are built with Kotlin, Java’s share has reduced drastically in this space.  

Kotlin’s claim to fame seems to be the concise code, lambda expressions, Null pointer exception safety, interoperability with java, and a lot more. 

Is Kotlin Replacing Java in 2021?

Well, the short answer to this is quite evident, Kotlin is fast replacing java for Android apps development. Having said that, Java is a very old language and commands a huge ecosystem. 

Java is used in many other areas apart from Android, including data science, web development, server-side programming, networking, embedded systems, and much more. So, Java is not going anywhere anytime soon. 

In fact, popular indexes and surveys still rank Java among the top 3-4 languages in terms of overall developer base and popularity, though the trend seems downwards.. 

Java also has a huge codebase and set of libraries for Android and since Kotlin is interoperable with Java. So, the Java ecosystem for Android too is here to stay for a while.  

Kotlin or Java: Which one is for you?

Let us start off with a brief introduction of the two languages before getting into an objective and parametric comparison. We will start off with Kotlin – 

What is Kotlin

Kotlin was an initiative of JetBrains for their internal development but they open-sourced Kotlin shortly thereafter. The first stable version of Kotlin came into existence back in 2016, and within a matter of months, Google announced its support for Kotlin.

Kotlin is a statically typed general-purpose programming language and runs on Java Virtual Machine (JVM). Koltin offers both object-oriented and functional programming paradigms.

Apart from Android/JVM based development, you can also compile Kotlin to javascript and use it for front end development.

Kotlin also supports server-side development by utilizing existing frameworks and libraries of java, like spring and Vaadin. You can set up a Node server too to ditch the JVM altogether.

The team behind Kotlin is also working on additional features to make it suitable for Native mobile development, data science, machine learning, and AI. 

What is Java

Java is an old programming language and has ruled the world of programming for more than a decade. Sun Microsystems developed Java back in 1990, now owned and maintained by Oracle. Writing code once to run on all platforms was the philosophy that made java so very popular. 

Not only Android development, but Java is also used for web development, enterprise software development, networking, embedded systems, data science, and much more. To say the least, it still tops the job charts. 

Java is also a statically typed, class-based, object-oriented programming language and brings in an imperative style of coding. Java 8 introduced many features to support the functional programming paradigm as well as features to write concise code. 

So, while Java is facing tough competition from modern languages, it is still in the game with continuous improvements. 

Java runs on Java Virtual Machine (JVM) and JVM makes Java programming platform agnostic. It is interesting to note that, as of today, it is not only Java that runs on JVM, but hundreds of other languages run on JVM.

Some of the most notable modern languages utilizing JVM include Scala, Kotlin Itself, Groovy, Clojure, Ceylon, XTend, Fantom, and X10. The list is very long, we will not go there for now!

You might like: Online Java Compiler

Kotlin vs Java: Why Kotlin for Android and Beyond?

Let us look at some of the key features Kotlin brings on the table that Java doesn’t have and vice versa – 


Non-blocking asynchronous code execution and concurrency take care of long-running and CPU intensive tasks and provide a seamless user experience. Kotlin adapted coroutines to achieve this, which is missing in Java.

In java, developers typically utilize background threads to achieve this but Coroutines in Kotlin make it much easier.

Coroutines pass the execution to the libraries while the rest of the code continues, this enables you to write concurrent and asynchronous code as required, with ease. 

Null safety

Null pointer exception, why is it so huge. Ask any Android developer working on a large application in Java and you will get to know. Null references go unhandled and end up in NullPointerException in Java, and hence frustration for developers. 

Kotlin on the other hand offers Null safety by default. Data types in Kotlin can not hold null values by default and code fails at compile time itself making NullPointerException impossible in Kotlin. Well, you can make an effort to get one though. 

Example –

var cantNullMe: String = "abc" // Kotlin default
cantNullMe = null // compilation error

Smart Casts

Typecasting is irritating and developers hate that, one of the hot topics of discussion in the Kotlin vs Java debate. Kotlin offers Smart Casts that let you skip the casting. All you need to do is check an object to be of a specific type using the “is” operator and move forward. No need to explicitly cast to that object type. 

Example –

fun autoCast(x: dumb) {
    if (dumb is String) {
        print(dumb.length) // dumb auto casts to String

Data Classes

Kotlin makes it easier to create classes that are meant to hold just data, you need to append prefix “data” to the class declaration and the basic functions for all data elements would be available out of the box, unlike java where you need boilerplate code.

Example –

data class Shape(val name: String, val sides: Int)

Developer Productivity

It is not an opinion of a few developers but a well-known fact that Kotlin requires lesser code to develop the same functionality, given its concise syntax including one-liner functions.

Kotlin also brings features to support functional programming including higher-order functions. Using Kotlin functional programming, you can make the code readable and highly reusable. 

Also, since Kotlin is fully interoperable with Java, all the existing libraries and frameworks of Java can be used as-is in Kotlin without the worry to write basics from scratch. 

Extension Functions

Many modern languages like C# offer extension functions, and so does Kotlin. Using extension functions, you do not need to inherit the class to add more functions to it. 

This is specifically useful when you want to add more functions or capability to the third party provided classes/packages. You can simply define new functions using extension functions syntax and those will act as if belonging to the original class. 

Compile Time

Compile time of Kotlin has been reported by developers to be higher than Java, which is kind of a set back for projects with a large codebase. 

Though I do believe that compile-time will improve as more and more Kotlin libraries and frameworks pop up, for now, Kotlin uses many Java libraries, so the code base is mixed and results in higher build times. 

As per the official notes, Google and JetBrains together are committed to reducing the compile time of Kotlin.

Lambda Expressions

When we talk about Kotlin vs Java, it is difficult to leave Lambda functions at bay. Kotlin offers support for Lambda expressions. This gives a lot more flexibility to developers, developers can treat Lambda functions as arguments to other methods, use returned values as is, and for that matter, treat the function as any other object or data value.

This is more driven from the functional programming paradigm and helps keep code concise, readable, maintainable, and well, scalable too. 

Inline Functions

WIth higher order functions, you can pass functions as arguments and get return value as a function. Given that every function here is treated as an object, this becomes overhead for memory allocation and virtual calls. 

The solution to avoid overheads is inlining the functions, which avoids object creation but instead adds the code of the referred function inline the calling function. You just need to use the keyword inline to do so.  

Checked Exceptions

Java has checked exceptions while Kotlin doesn’t have it. This is something where the developer community is in favor of java. My take is, developers are used to working with checked exceptions and find it difficult to adapt to Kotlin for the time being. 

I personally do not like too many try-catch blocks, there has to be a better way of catching exceptions. 

I am still experimenting with Kotlin to figure out how the dropping of the checked exceptions is playing out, so, we wait and see before concluding this in favor of Kotlin or Java. .

Ease of Delegation by Design

Delegation as its name suggests is about passing operations or processes from one object to another.

Kotlin has first-class support for delegation to achieve this as compared to inheritance in Java, this kills the need for any boilerplate code and helps build a scalable codebase. 

Static Keyword

Developers use static members heavily in Java, but Kotlin does not provide support for statics. While Kotlin does not support static, it has alternatives to achieve the same.

Static keyword in front of a field or class ensures that a separate instance of that type can not be created.

For example, you can create a function outside of the class, at the package level directly, and this function will have only one instance always. 

An even better way to do this in Kotlin is to use companion objects.

In Java
class Foo { public static int a() { return 1; } }
In Kotlin
class Foo { companion object { fun a() : Int = 1 } }

Final Thoughts: Kotlin vs Java?

From a language capability perspective, Kotlin has clear advantages. And, specifically since it is interoperable with Java and can utilize everything that Java has. So, it has the upper hand by design. 

In the Android development space, Kotlin has already taken the front seat replacing java.

More apps are built using Kotlin than java as of writing. So, there doesn’t even seem to be a Kotlin vs Java debate anymore, go for Kotlin.

Java, on the other hand, has a huge ecosystem and skilled developers available. It may not be wise to touch your existing codebase and start porting it to Kotlin with full force. You might want to continue with Java skills on the existing code, and start small on your migration endeavor.

Comments ( 0 )

    Why Eduwyre

    Eduwyre helps you find the best courses, tutorials, books, and university certifications, reviewed by our experts and ranked by real verified students.

    Ⓒ 2020 eduwyre — All rights reserved