DEV Community

Discussion on: Kotlin for Android Development: Heavyweight Language or Hopeless Hype?

Collapse
 
niharmore33 profile image
nihar

When you think about Android development, chances are one programming language immediately springs to mind: Java.
Learn Kotlin and java here: hackr.io/

While it’s true that the majority of Android apps are written in Java, when it comes to Android development, Java isn’t your only option.

You can write Android apps in any language that can compile and run on the Java Virtual Machine (JVM), and your end users will be none the wiser. And one JVM-compatible programming language that’s really caught the attention of the Android community is Kotlin, a statically typed programming language from JetBrains.

If you’ve heard good things about Kotlin and are interested in trying it for yourself, then you're in the right place. In this three-part series, I’m going to share everything you need to know in order to start using Kotlin for Android development.

In this first installment, I'll look at why you, as an Android developer, might want to consider making the switch from Java in the first place, and then I'll examine the pros and cons of selecting Kotlin as your Java replacement. By the end of this article, you'll have a solid grasp of exactly what Kotlin has to offer and will know whether it's right for you.

In part two, we'll be looking at how to set up your Android Studio installation to support Kotlin and create a simple Android app that's written entirely in Kotlin. With these foundations in place, in the third installment we'll look at how to supercharge your Android development, using some more advanced features of the Kotlin language.

Why Should I Make the Switch From Java?
While Java is one of the world's most widely used programming languages and is pretty much the official language of Android development, there are many reasons why Java might not always be the best option for your Android projects.

The biggest issue is that Java isn’t a modern language, and although Java 8 was a huge step forward for the platform, introducing lots of features that developers had been waiting for (including lambda functions), at the time of writing Android only supports a subset of Java 8 features. It seems unlikely that Android developers will be reaping the full benefits of Java 8 anytime soon, so for the foreseeable future if you want to use Java in your Android projects, then you’re pretty much stuck with Java 7.

Java as a whole also has some pretty well-documented language issues, including endless try-catch blocks, a lack of extendability, null-unsafety (and that infamous NullPointerException), not to mention a lack of support for functional programming features. Although Java is starting to add some functional programming elements, such as lambda expressions and functional interfaces, at its core Java is still a procedural language. Java’s syntax is also pretty verbose, particularly when compared to many modern programming languages.

Advantages of Kotlin
So you may want to consider switching to one of the many modern programming languages that are designed to run on the JVM. While there’s no shortage of languages that compile to Java bytecode, there are a few factors that make Kotlin stand out from the crowd:

Interchangeability With Java

One of Kotlin’s greatest strengths as a potential alternative to Java is the sheer level of interoperability between Java and Kotlin—you can even have Java and Kotlin code existing side by side in the same project, and everything will still compile perfectly. Below, you can see an example of a project that consists of a Java Activity and a Kotlin Activity.