Over a million developers have joined DZone.

Why You Should Consider Kotlin For Android Development

DZone's Guide to

Why You Should Consider Kotlin For Android Development

Despite its good qualities, Java isn't the only choice for Android development. If Java errors are getting you down, read on to learn about developing with Kotlin.

· Mobile Zone ·
Free Resource

Java is the primary and official language for Android development, but that doesn’t mean it is the best or the only choice. To give Java credit, it is a robust language that has been around for a while, but it comes with a specific set of challenges that can be a deterrent for developers.

A new breed of modern JVM languages is slowly gaining traction within the Android community, and Kotlin is leading the pack of these modern and safe JVM languages as an alternative to Java. Kotlin is a statically typed programming language that runs on the Java Virtual Machine. It can also be compiled to JavaScript source code. The main development team behind Kotlin is a team of JetBrains programmers from St. Petersburg, Russia (hence the name Kotlin - from Kotlin Island near St. Petersburg). Here are some reasons why it is fast becoming the favorite of many Android app development companies.

Image title

The Trouble With Java 

Java is one of the oldest programming languages. It has been around for twenty-two years and has many features that can’t be implemented due to its massiveness and obsolescence. Being old has many advantages, but also disadvantages from a programming standpoint. For example, it doesn’t have support for lambdas, method references, streams, or try-with-resources.

Java is also error-prone and one of the biggest complaints being how it handles “null," often causing an error leading to the dreaded NullPointerException (NPE), popularly known as The Billion Dollar Mistake. Java’s “Nullability" is more exacerbated with Android.

Java is also extremely verbose and ceremonious. Programmers need to write reams of code to get a simple task done. There's a great deal of “ceremony” in Java APIs, and Android aggravates this by forcing developers to go through many steps, in a specific order, to get things done. Java also has some well-documented language and design flaws that make it cumbersome to use.

Vis-à-Vis Kotlin

    1. Concise and idiomatic: Kotlin requires way less code to write. At one estimate, it is almost 20% less than Java. It drastically reduces the amount of boilerplate code that programmers need to write. The fewer the code, the better its execution.

    2. 100% interoperability with Java: One reason for its popularity is the interoperability with Java. You can also have Java and Kotlin code co-exist well in the same project and compile perfectly. Once your project combining Java and Kotlin is compiled, it would be difficult to tell which parts of the project are created in Java or Kotlin. And because Kotlin and Java can co-exist so well, you can start using Kotlin without having to convert an entire project or starting afresh. Due to the interchangeability, you can also benefit from the vast number of Java libraries and frameworks in your Kotlin projects.

    3. Easy learning curve: Kotlin is approachable and can be acquired in a few hours by simply reading the language reference. It has a lean and intuitive syntax. Kotlin is also designed to have a gentle learning path for Java developers. Java programmers will find that most of the Kotlin syntax feels familiar.

    4. No cost adoption: Kotlin is, of course, open source. You can use a high quality, one-click Java-to-Kotlin converter tool converting existing Java projects one file at a time and convert complex projects with millions of lines of code.

    5. Less buggy, safer option: Kotlin makes it possible to avoid entire classes of errors such as NullPointExceptions. It protects you from mistakenly operating on nullable types, including those from Java. If you check a type is right, the compiler will auto-cast it for you.

Last but not least, Kotlin has top-rated Android Studio Support since it is developed by JetBrains– the company behind IntelliJ– the IDE for Android Studio. Once you install the Kotlin plugin, Android Studio makes the configuration in your project a matter of opening a few menus. While no programming language is perfect, Kotlin too has a few chinks in its armor like extra runtime size, initial readability of code, smaller community, and less support.

Overall, Kotlin is one of the safest bets as an alternative to Java for custom Android app development. Have you used Kotlin? What has your experience been? We welcome your opinion in the comments below.

android ,java ,kotlin ,mobile ,mobile development ,app development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}