Java vs Kotlin for Android-developing: “pros” and “cons”

SHARE

When Google announced Kotlin as the language of choice for Android development in May 2019, the language choice debate flared up again. On the one hand, everything is simple: you need to write in the language that is personally convenient to you. But there are also a number of factors that can tip the scales in favor of Java or Kotlin. We have compiled our own list of pros and cons of each language based on facts and opinions of experienced developers. The conclusions can be seen at the end of the article.

 

Clause 1

Age of the language

Java

Large community, many libraries, solutions and ready-made modules. Roughly speaking, if a developer encounters a problem, he can quickly get an answer to his question.

Kotlin

But in the case of Kotlin, the opposite is true. The youthfulness of the language and associated libraries such as Kotlinx.Serialization or Exposed makes it worth spending a lot of time looking for solutions. In addition, the documentation of the language often comes down to explanations in the spirit of “it’s done like in Java, only you need to change it a little bit.”

 

Clause 2

Amount of code

Java

Yes, Java syntax suggests that the code will be more bulky than in Kotlin, and therefore writing will take more time. Although these languages are superficially very similar, but at the same time they are very different from each other. Here is an example of how text is assigned to a field without libraries:

Java

final TextView helloTextView = (TextView) findViewById(R.id.text_view_id);
helloTextView.setText("Some text");

Kotlin

helloTextView.text = "Some text"

Mark, Android Developer

Kotlin

Kotlin allows you to write the same thing as Java using fewer lines (Extensions, Null Safety, Data Classes). Separately, it is worth noting the work with the UI: thanks to Android Extensions, you no longer need to deal with the boilerplate with findViewById.

 

Clause 3

What to choose at the start of Android-development

Java

Today, Kotlin is the best choice for Android development. But if you are a beginner programmer, then at the start it is better to choose Java: this language is older, and you can easily find information on how to solve a particular problem. Do not forget that Kotlin is a wrapper over Java, and during the compilation process it is converted into Java bytecode.
However, it’s hard to imagine Android without Kotlin these days, but the Kotlin documentation assumes that you know Java, so if you’re just starting out as an Android developer, it’s best to start with Java and then move on to Kotlin.
Jacob, software engineer

Kotlin

You can start learning Kotlin without Java knowledge. But Kotlin still uses the JVM and is not a full-fledged alternative, although it occupies a certain niche in Android development. If you still intend to choose Kotlin, it is better to start learning with an eye on Java or even learn both languages at the same time.

 

Clause 4

Development environment

Java

Android app development has long been closely associated with Android Studio. This environment was originally designed to work with Java, and therefore the code can be written literally one letter at a time – the IDE will independently pull up everything you need.

Kotlin

Since Android Studio is based on Intellij Idea, and Intellij Idea and Kotlin are created and developed by JetBrains, as a result, developers get an up-to-date development environment that is closely related to the programming language, which greatly simplifies application development.
Jacob, software engineer

 

Clause 5

What is the purpose of the language choice?

Java

Most existing Android applications are written in Java, and you should not hope that they will be rewritten in Kotlin. And since the Android UI is developed in Java, this language has an SDK and many ready-made libraries, so a number of companies still prefer Java.

Kotlin

If the application has a long lifespan (for example, a mobile bank), and the question of cross-platform development is not even an issue, then we consider Kotlin to be the best option. It is fully compatible with Java, that is, both languages can be used within the same project. Compared to older versions of Java (7 and older), Kotlin has a bunch of new features that make writing code easier. At the same time, Kotlin does not depend on the Android version in the same way as Java
Ron, lead developer

Prospects

Java

Modern companies are increasingly developing mobile applications on Kotlin. But you can also come across a specific library that only works with Java, and if you do not know this language, you will have a hard time.
Besides, Kotlin is a young language, and no one knows what will happen next, while Java is characterized by cross-platform: not only mobile development rests on it, but also the backend with the desktop.
Mark, Android Developer

Kotlin

Now Kotlin is developing quite predictably and is focused specifically on Android development. It is increasingly chosen by young companies that are starting to create mobile applications, and now there is a shortage of Kotlin developers, and therefore the language is in high demand. It is unlikely that it will replace Java in the foreseeable future, but it may well coexist, gradually gaining popularity.

Other experts’ opinions

Christine, Android-developer

There are many mobile development languages, but Java and Kotlin are the most common. To develop Android apps, many advise you to start by learning Java. This is a win-win situation because if you master Java, the subsequent transition to Kotlin will not be difficult. I believe that you need to know both languages – it is impossible to know Kotlin without knowing Java.

Kotlin is a statically typified programming language that has appeared relatively recently and has already become quite popular among developers. It is as compatible with Java as possible, which means that if you wish, you can write a project using the advantages of two languages.

Now, when developing applications, our team uses Kotlin, but so far, we cannot completely abandon Java because of the need to support old projects. Using Kotlin is much easier and more convenient: the code looks more concise and clearer, the language has features that Java does not have – null safety, data classes, extension functions, and others. It is important to note that Kotlin is tailored for functional programming and provides the ability to use higher-order functions, lambda expressions, and operator overloading that reduces development time.

Obviously, some things are better implemented in Kotlin, while others are better in Java. Everyone chooses what they will write code on, but once you try Kotlin and understand its features, you are unlikely to want to return to Java.

 

Roger, Senior Android Developer

Since Kotlin has become officially supported for Android app development, there are more and more apps and libraries that use this language. I will not once again mention the advantages of Kotlin – it has a lot of them, and a lot of materials have been written about it, including official documentation.

Kotlin or Java? Typically, the community chooses the appropriate option based not only on the pros and cons but also on the spirit of the proposed solution. I suppose that is why Kotlin has managed to win the preference of many developers around the world so quickly and is chosen more often than Java. Many new projects start with Kotlin. In rare cases they start in Java because it’s been a very cool language so far. Albeit with some shortcomings, but applications can be written on it with the same success. Kotlin has absorbed more convenient features, removed some Java shortcomings and came up with a more concise syntax. But at the same time, in my personal opinion, one cannot say “don’t write in Java anymore”.

Choice is rather a matter of taste, but now Kotlin is increasingly being chosen to start a project.

 

Bernard, Software Engineer

What to choose for an Android developer – Java or Kotlin – is a young question, but it has already become a hot topic. It worries both beginners and experienced professionals. It is important to understand here that there is no only right choice.

In my work, I made a choice in favor of Kotlin a long time ago, I was immediately bribed by its simplicity and ease of use: null-safety code, immutability, collections and the presence of delegates – all this can leave few people indifferent. In addition to syntactic sugar, Kotlin provides coroutines that greatly simplify asynchronous work.

The above benefits allow you to write less code and do it easier, and the full compatibility of Kotlin with Java allows you to make the transition gradual, without rewriting the project from scratch.

It is also worth considering the situation on the market. At Google I/O 2017, Kotlin was officially recognized as the main development language for Android. Java offers version 8 of the language with some new features (with 14 as the current latest version), and its future in Android remains unclear. In addition, now almost every job lists knowledge of Kotlin as a big advantage.
I think that in the future Kotlin may completely displace Java from the Android development market.

Conclusion

So, what is worth choosing – Java or Kotlin? Technically, the difference is significant but if you plan to do Android development, learn both languages. Most popular libraries support backward compatibility with Kotlin; Java code can be used in Kotlin and vice versa, but to solve a problem or simply understand all the nuances of the documentation, you should know Java. Having mastered both programming languages, you will become a sought-after specialist and secure a good future for yourself in Android application development.