Você deve usar Kotlin ou Java para desenvolvimento Android?

Should you use Kotlin or Java for Android development?

Choose between Kotlin or Java for Android programming. Our expert guide helps you decide and learn faster.

Desenvolvimento Android com Java ou Kotlin

In 2019, Google announced that Android was becoming the first Kotlin operating system. Such a statement had a dual purpose. On the one hand, boosting the adoption of Kotlin among Android developers as the first step towards a more ambitious project: a common language for all platforms. On the other hand, it was Google's way of telling Java developers that they should start learning Kotlin.

More than a year after that announcement, Kotlin adoption is increasing, and the language is showing up in developer surveys as one of the most popular languages ​​out there. Does this mean this is the end of Java as an alternative for Android development? Not exactly. One of the most popular languages ​​in history still has some things to offer Android developers, who can still rely on it for their applications.

So which one should you choose? Should you follow Google's advice and choose Kotlin? Or should you choose a tried-and-true language like Java? Let's compare the two to see which is better.

Java Kotlin
Year of Creation 1995 2011
The creator James Gosling (Wikipedia) JetBrains (Wikipedia)
Documentation Java documentation Kotlin Documentation
Language type Compiled Language Compiled Language
Typing Statically typed Statically typed
TIOBE Classification 4 26
Popularity Very popular and widely used language, with a vast ecosystem and strong community support. Popular and growing language with strong community support.
Forms Web development, Android apps, enterprise apps Android app development, server side apps, web development
Performance High performance and widely used in enterprise applications High performance and interoperability with the existing Java code base.
Stability Stable and well established Stable and actively developed and improved.
Learning curve Moderate – Learning Java requires understanding its object-oriented concepts, especially for beginners. Moderate – Kotlin's modern syntax and interoperability with Java can make the learning process easier.
Community support Large, active community with extensive documentation and online learning resources. Large and active community with extensive documentation and strong support from JetBrains.
Development time Java development time can be longer due to its verbosity and strict syntax. Kotlin's concise syntax and language features can lead to faster development times.
Main advantages
  • Platform independence with “Write Once, Run Anywhere” (WORA)
  • Rich ecosystem and libraries
  • Strong community support.
  • Interoperability with Java
  • Concise and expressive syntax
  • Enhanced security features with null safety and type inference.
Main disadvantages
  • Verbosity and boilerplate code
  • Memory consumption may be higher compared to some other languages
  • Steeper learning curve for beginners.
  • Kotlin's rapid evolution could lead to some important changes
  • Smaller ecosystem compared to Java.
Companies that use this technology Amazon, Netflix, Twitter Pinterest, Evernote, Coursera
Cross-platform support Java offers cross-platform support, allowing developers to run code on different operating systems without modification. Kotlin offers cross-platform support and can be seamlessly integrated into the existing Java codebase, making it a popular choice for Android app development.

Kotlin – the cute new kid on the block

When Google released Kotlin in 2017, their intentions were clear: they wanted to provide developers with a more practical and efficient programming language for Android development services. While Java was the right choice for app development, Google felt it needed some more modern features and better performance – hence the creation of Kotlin.

Google's push for Kotlin has certainly affected the mobile development community. Since Kotlin was first announced, Google has been working with it across all of its Android apps. Big companies like Twitter, Netflix, Airbnb, and Pinterest have switched to Kotlin. And many other developers are thinking about it, enchanted by the possibilities brought by the newest kid on the block.

What are these possibilities? Kotlin brings solutions to common problems and improvements to the Java programming experience as a whole. Some of them include:

  • Interoperability. Kotlin was born from a clear goal: to become a dominant language that would eventually spread across all platforms. This focus led its creators to provide Kotlin with high interoperability that allows it to use a large number of libraries and write modules that will work perfectly with Java code.
  • Economics of Code. Java isn't exactly known for being concise, something Kotlin fully addresses by offering a concise and readable syntax. It allows you to develop your Android projects faster while reducing the likelihood of errors, especially in applications with a wide scope, greater number of features, or high complexity.
  • Modern programming capabilities. Because Kotlin is so new, it is built on more modern approaches to programming. This means you can use new programming concepts for your development, including extension functions, high-order functions, delegates, and other options for building APIs.
  • No raw types: There was a time when everyone used raw types, but as generics started to appear, they were maintained to ensure backwards compatibility. However, developers know that raw types can cause problems during execution. To nip this problem in the bud, Kotlin doesn't allow raw types, which leads to more type-safe code.
  • No exceptions checked. Certain Java developers may point out that checked exceptions are useful for performing error handling. However, these exceptions often cause empty catch blocks, which causes developers to waste time identifying the exception that caused it. Kotlin deals with this problem by removing checked exceptions completely.
  • Non-nullable variables. One of the most well-known issues during Android development is NullPointerException. Kotlin handles this by building null safety that prevents variables from taking on a null value. Of course, there is a workaround for cases where a variable needs to have a null value, but on a general level the language does not allow this.

All these benefits might make you believe that Kotlin is better for Java, and that's it. However, it is best to describe the limitations and cons of Kotlin to provide a complete picture. Some of the disadvantages of the language include:

  • Steep learning curve. This may seem contradictory. How can a concise, highly readable language be difficult to learn? However, this brevity can be difficult to understand for developers accustomed to other languages. Learning Kotlin requires a change of idea about what a language can be.
  • Slow compilation speed. When compared to Java, Kotlin compilation is slower in most cases. You may find some projects where Kotlin outperforms Java, but this is more of an exception than a rule.
  • Standard code. Since Kotlin is a highly declarative language, it often tends to create boilerplate code in the corresponding JVM bytecode, leading to verbose code that doesn't need to be that way.
  • Small community. Finally, given how young it is, Kotlin has yet to develop a strong developer community. Kotlin's community is insignificant when compared to Java's, simply because the latter has been around for a long time and has a lot of features to offer its users.

The old reliable Java

On the other side is Java, a favorite of developers, especially in Android app development. This is for a simple reason: Android used to be written in Java, so building apps on it was a no-brainer. However, since the emergence of Kotlin, many developers are questioning how useful it can actually be to follow it when creating Android applications.

The answer, again, may seem simple: just ditch Java and adopt Kotlin. However, there are many reasons why Java has stood the test of time. Being one of the most popular programming languages ​​on the market, it is natural that some want to keep it without even considering an alternative. Here is a list of reasons why this might happen:

  • Easy to learn. Java is easy to learn, write and understand. There are many resources available online to help you with training, but the syntax also features ease of use and understanding that makes any Java project simple.
  • Portability. Thanks to the Java Virtual Machine, Java is platform independent, meaning it can run virtually anywhere. This means that everything you develop with it can be easily ported to other platforms.
  • Android's trust. Android may be choosing Kotlin as its language of choice, but that doesn't mean it has cut its ties with Java. The Android SDK still contains many standard Java libraries, making it easier for Java developers to work on Android.
  • More compact applications. Java applications tend to be more compact and much more optimizable. This is great when you want to create a new version of an application that desperately demands better performance. What's more, you can achieve this with lighter applications thanks to Java's imperative nature.
  • Great community. You will encounter problems when programming with any language. This is a fact. So it's great that Java development teams have a large community of experts to support them. If you use Java and run into a problem, chances are you can find help online to solve it.

As you can see, there are many benefits to working with Java on Android, even if Kotlin feels more personalized. Naturally, there are some disadvantages to Java, which you should consider before making a decision. These cons include:

  • Detailed. Java is a verbose language, which means you will have to write more code to leverage the same functionality that Kotlin would have with much less code. On the one hand, there is a greater risk of errors and bugs occurring. Then there is the possibility of bloating the application. Finally, there is also a longer development time to reach the final product.
  • Slow performance. Anyone who has used Java knows that it is unfortunately slow, especially if you compare it to more modern languages ​​– like Kotlin. That's not all, as Java requires a lot of memory to function properly, which can be a deal breaker for some.
  • Lack of modern functions. Just as Kotlin is able to use newer concepts and approaches for application development, the opposite is true for Java. Although we are seeing more and more updates, Java still feels like an old language in certain ways, which can be challenging for new developers with a different approach to development.

Which one should you choose?

All of the above may seem like you will be forced to switch to Kotlin development services sooner or later. But where we are today, it's not necessary. Java can do a great job in Android development and can be a perfect choice, especially in the hands of experienced developers. When the time comes to make this language change, Java development companies will not have as much difficulty, as Kotlin is intertwined with Java in a sense.

Time will tell if Kotlin becomes the dominant force it appears to be. Meanwhile, it's already defining new standards and methodologies for Android development, which, for better or worse, will require developers to learn to keep up.

If you liked this, be sure to check out one of our other Java articles:

  • 6 Best Java GUI Frameworks
  • 8 Best Java IDEs and Text Editors
  • The Pros and Cons of Java Development
  • Top 10 most popular Java frameworks
  • What is Java used for? 8 things you can create

Source: BairesDev

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.