Kotlin vs Java: Which is the best choice?

Entrepreneurs planning an Android app face many choices. One of the most fundamental is Kotlin vs Java, and which is the best choice for Android app development.

If you are planning on creating your own app and are wondering which is best, read on.

Contents

Kotlin: An overview
How history helped Kotlin: Google’s challenges with Java
Kotlin matures with Google and JetBrains collaboration
The advantages of Kotlin
The growing popularity of Kotlin
Learning Kotlin
Kotlin vs Java: Which one to choose?

Kotlin: An overview

Java needs no introduction, however, Kotlin is a relatively new programming language. JetBrains, the company behind “IntelliJ IDEA”, the popular Java “Integrated Development Environment” (IDE) created it. They first announced it in 2011 as “Project Kotlin”. The first stable release came in February 2016.

A few quick points about the Kotlin language:

  • It’s a cross-platform programming language for general purpose usage.
  • Kotlin is a statically-typed language. Developers need to specify the types of variables since the variable types are known at the compile time. Read this Stack Overflow Q&A thread for more information about statically-typed programming languages.
  • The team that designed the language took inspiration from popular programming languages like Java, Python, C#, and Scala.
  • Kotlin features type inference, which helps to automatically detect the data type of an expression. Read about it in this Techopedia definition.
  • The team behind Kotlin wanted to create a language for object-oriented programming that compiles as quickly as Java. They made Kotlin fully inter-operable with Java.
  • Kotlin targets “Java Virtual Machine” (JVM), moreover, it uses “Java standard libraries” and “Java class libraries”.
  • Kotlin also compiles to JavaScript.

How history helped Kotlin: Google’s challenges with Java

Before we delve further into Kotlin vs Java Android development, let’s take a step back. Android has relied on Java since its inception. However, the long drawn-out legal battle between Google and Oracle over Googles’ use of Java “Application Programming Interfaces” (APIs) is bringing changes.

The problems started in 2010, and has been getting nastier ever since. Read “The case that never ends: Oracle wins latest round vs. Google” for more details. Growing increasingly wary about the lengthy legal battle, Google began looking for alternatives to Java.

Kotlin looks to be fast becoming that alternative. While Google hasn’t said that in so many words, the indications clearly indicate this. Read “Google is moving Android away from its Oracle java problems with Kotlin” for more information. An important step occurred when Google announced first-class support for the language on Android in their 2017 “Google I/O”, their annual developer conference.

Download Our Project Specification Template

 

Kotlin matures with Google and JetBrains collaboration

Kotlin continues to mature with newer releases, as follows:

  • The Kotlin v1.2 release in November 2017, allowed developers to share code between JVM and JavaScript platforms.
  • Kotlin v1.3 release in October 2018 facilitated asynchronous programming. Asynchronous programming helps in improving the performance and responsiveness of an app. Read more about it in “Your ultimate async / await tutorial in C#”.
  • Google and Kotlin further strengthened their collaboration by forming “Kotlin Foundation” in October 2018.
  • At the time of writing this article, the latest stable release of Kotlin is v1.3.21, which was released in February 2019.

Kotlin is open-source. It’s under “Apache License 2.0”, and you can find the details here.

The advantages of Kotlin

I have explained how circumstance has helped stack the card in Kotlin’s favor. However, it is important to remember that it is also a superb programming language. Kotlin offers the following advantages:

  • Write less code: Developers the world over desire to write as least code as possible and still accomplish their objectives. This urge can affect with app performance, which demands clearly written code. Kotlin allows for  both. It’s a concise and programmer friendly language.
  • Kotlin helps developers: Programmers developed the language with programmers in mind. One example is the type system, which enables coders to avoid null pointer exceptions. There are other examples, but you get the point! It’s a language that empowers developers.
  • Ease of adoption: It’s easy to move work-in-progress Android app code to Kotlin.
  • Supports functional programming: Kotlin supports functional programming, by enabling developers to complete many tasks quickly and easily. Read more about it in “Kotlin vs. Java: 9 benefits of Kotlin for your business”.
  • Full compatibility with Java: As I mentioned earlier, Kotlin programmers can use all Java libraries and frameworks. Android developers who were coding in Java find Kotlin easy to use.
  • No runtime overhead: The Kotlin library is small, and much of the heavy lifting is done during compilation.
  • A vibrant community: Developers love the language, and now Google is fully behind JetBrains and the Kotlin community!
  • Multi-platform compatibility: Not just for Android development, coders get JavaScript support too with Kotlin. Compatibility with Gradle further helps interoperability.
  • Safety: The language eliminates quite a few common coding errors, moreover, chances of coding errors reduce when one has to write less code.

Read “Why use Kotlin for Android development? Kotlin benefits, features, versions” to gain a deeper understanding of these benefits.

The growing popularity of Kotlin

Kotlin is becoming increasingly popular. Check out the following trends so you can appreciate its’ growing appeal:

  • From minimal adoption prior to the 2016 launch of the first stable release, market share grew to 4.28% by May 2017 after Google announced their support. Adoption grew to 7.54 % by September 2017 and is still rising. Read more about this statistics in “Kotlin gains ground in Android, but no current threat to Java, experts say”.
  • A 2018 survey that involved over 100,000 Stack Overflow users found that over 60% of respondents use Kotlin. Read “The state of Kotlin 2018” for more information.
  • The same survey also found that over half of the respondents already use Kotlin significantly, i.e., the majority of their code is in Kotlin.
  • Udemy, the online learning platform reported in 2018, that based on the demand on their site, Kotlin was the hottest development skill of that year. Read their report in “9 hot tech skills for 2018”.

Learning Kotlin

Kotlin is relatively new, however, developers can access a growing collection of learning resources. Check out the following examples:

 

Kotlin vs Java: Which one to choose?

Now that you know about Kotlin, the question is, should you choose Java or Kotlin? Consider the following factors:

Factor #1: The larger objective

If Android development is the main objective, then Kotlin is the right choice given the productivity advantages and the massive support from Google.

Read How We Helped a Marketing Company to Build a Back-Office Custom Ads Dashboard

However, if the objective is the creation of larger, more complex products,  then working with Java is the better choice. The use of Kotlin for backend projects is a recent phenomenon. For e.g., Spring 5.0 started supporting Kotlin only in 2017, so it still lacks the advantage that Java has in terms of maturity.

Overall, Java still remains the most popular programming language due to the various advantages it offers. The latest TIOBE index confirms this. Read “TIOBE index for February 2019” for more details.

Factor #2: Can you afford a learning curve?

I made reference to the concise syntax of Kotlin in an earlier part of this article. Let’s take a deeper look:

  • Developers can write less code, however, post launch maintenance teams can still easily understand the code. This advantage comes from the concise nature of the language. Read more about it in “The character of Kotlin: Conciseness”.
  • A concise syntax helps with various coding aspects, e.g.:
    • Class creation;
    • Data modifier;
  • Developers have a steep learning curve when first trying to get used to this concise syntax. As an entrepreneur or a project manager, you need to determine whether you can accommodate this learning curve.
  • Now, for the good news. Except for the concise syntax, Java developers face no further learning curve when working with Kotlin. They can use most of the Java coding skills that they learned previously. Read about this in “Java vs. Kotlin: should you be using Kotlin for Android development?”.

Factor #3: Development manpower cost

If you opt for Kotlin, then prepare to incur higher development manpower costs. This is due to the following reasons:

  • Kotlin was one of the hottest skills at the end of 2018, as you can see in “The top tech skills of 2018: Kotlin & Kubernetes made their mark“. The average salary of Kotlin developers is $ 115k per annum, while the best can earn up to $ 156k per annum, as this ZipRecruiter report
  • Kotlin job postings increased dramatically during 2018, as this Dice Insights report The prized place Kotlin has in the Android development space has caused this increase. Android development will only increase, further pushing up the demand for Kotlin developers. Consequently, you should prepare for a longer hiring lead time, which again translates to increased costs.

Factor #4: Limitations of using Java in Android

Android doesn’t support the full range of Java capabilities. Android Studio supports Java 7 fully, however, it only supports a subset of Java 8 features. Read about it in “Use Java 8 language features”.

If your love for Java is holding you back when Kotlin is the better choice then you might as well bite the bullet. Allocate a higher up-front budget, and just take the plunge with Kotlin. The longer-term benefits, including higher productivity, really are worth it. If you plan to develop multiple apps in the future, you are also investing in improving future development success.

Factor #5: Productivity gain with Kotlin

If productivity gain matters to your project, Kotlin is the way to go. Kotlin productivity levers are as follows:

  • Library: Kotlin has a far more comprehensive standard library than Java. There is an excellent collection of APIs. The language has many extension functions that developers often require.
  • Programmers can add their custom functions, and they can extend an existing class with this new functionality. Read more about it in “Comparison to Java Programming Language”.
  • Features: Kotlin has many more features than Java, for e.g., null-safety, easier generics, string templates, companion objects, data classes, primary constructors, etc. Read more about these features in “Kotlin language documentation”.
  • Kotlin is an intuitive language.
  • Support for functional programming: I discussed this earlier, however, let’s elaborate further. Kotlin supports “Lambdas”, i.e., anonymous functions and the language includes them in the standard library. Read “Kotlin by examples: methods and lambdas” to know more about how Kotlin treats Lambdas.
  • Developers write less code, thanks to the concise syntax. Programmers can avoid writing “boiler-plate” code since Kotlin generates it.
  • A smaller code makes it easier to maintain.

Read more about the productivity benefits of Kotlin in “How Kotlin makes me a more productive software developer”.

Factor #6: Kotlin handles “Null” better

Kotlin handles “Null” well, which is a great advantage over Java. This difference manifests itself as follows:

  • With Java, you can assign “Null” to any variable. The challenge comes when using object references with null values, and you get a “NullPointerException”. This is a common challenge and impacts the productivity of the team.
  • In Kotlin, no “type” can hold null by default. Developers need to explicitly define a “nullable” variable if they want to hold null in it. This rules out “NullPointerException”, which is a significant advantage.

Read more about it in “Kotlin vs Java: key differences between Android’s officially-supported languages”.

Factor #7: Handling long-running network I/O or CPU-intensive tasks

Kotlin has advantages over Java with respect to handling long-running network I/O or CPU-intensive operations. The two languages differ as follows:

  • In the case of Java, a thread involving a long-running I/O or a CPU-intensive task is blocked. Java allows multi-threading in the background, however, it’s complex.
  • When programming in Kotlin, developers can run multiple threads. Kotlin supports coroutines. These suspend execution at a certain point without blocking the thread.

Read “Differences between Java vs Kotlin” for more insights.

Grappling with the Kotlin vs Java choice for your strategic app?

Kotlin and Java both have their strong points. So to choose the right one you will need to consider the long-term strategic aspects of both platforms, including the fact that Google are slowly moving away from Java.

Making the right choice for your app development can be tricky. If you lack the complete range of skills and team, then I recommend you take professional advice. Read “How to find the best software development company?” before you engage a development partner. Good Luck!

Download Our Project Specification Template

Aran Davies

Blockchain Expert | Developer | Writer | Photographer
Aran Davies

Latest posts by Aran Davies (see all)