Kotlin Or Java - What Should Be The Foundation Of Your Android Application?

Marc Coll
Marc Coll, Business Development at AppFutura
Published on Sep 06, 2018 in Android Developers Resources
Kotlin Or Java - What Should Be The Foundation Of Your Android Application?

The first thing that pops up in our minds when we think about Android is Java programming language. However, Java is not the only go-to option for Android Development. There are a plethora of programming languages that can be used to develop Android apps such as C#, C/C++, Scala, Lua, Clojure.

Off lately, a certain programming language has stolen the spotlight during this year’s Google I/O and has become the first official language of Android. They call it Kotlin.

Android Studio comes with a built-in Kotlin support. This means that creating an Android project that can translate Kotlin code seems like a piece of cake while you are coding with Kotlin. The language is easy to use and reduces the overall app development time by a great extent.

These news left us with a dilemma: Kotlin or Java? What's better? There are so many questions your brain must be struggling out with. For example - If we pick Kotlin, would it make developers life easy? What are the features that Java lacks? Which Java features are compromised, so on and so forth.

Read further to find out.

What is Kotlin?

Kotlin is a ‘pragmatic’ programming language which is a general purpose, open source that comes with object-oriented and functional programming features for JVM and Android.

It’s mainly concentrated on interoperability, clarity, safety and tooling support. Two new Kotlin versions for JavaScript that uses ECMAScript 5.1 and native code using LLVM are still a work in a progress.

Kotlin’s origins date back to 2010 developed by JetBrains, the firm responsible for most well known Java IDEs such as IntelliJ IDEA, ReSharper etc. Kotlin was built to improve their productivity but wanted to avoid rewriting all their code for it, thereby making Kotlin interoperable with Java.

Kotlin vs. Java - The dilemma

Kotlin Or Java - What Should Be The Foundation Of Your Android Application?

Speaking in terms of learning curve, Kotlin is very low and any experienced Java developer can get an idea of Kotlin within few hours. Kudos to its developers, Kotlin is very well done and thorough. Apart from Kotlin also have some parallels with C# too.

When it comes to Android development, the Android Studio extends excellent tooling support as it is a fork from IntelliJ.

Because Kotlin interpolates effortlessly with Java, you can use Kotlin and Java files in the same project and they will go along well together.

You can create Java frameworks and libraries in Kotlin and others also can use any Kotlin network developed by you because Kotlin generates Java Bytecode. Developers who are new to Kotlin can comfortably test their results by using the language for isolated parts alone.

When choosing Kotlin over Java, the feature set that it comes with is something to look for. It brings in new capabilities that Java doesn't offer in Android development. Some noteworthy features include:

  • Eliminates Null errors and promotes safety through nullable and non-nullable types.
  • Safe casting and Calling Mechanism
  • Extension functions
  • Supports Functioning programming using Higher-order functions/lambda expressions.
  • Data classes
  • Immutability
  • Coroutines and Type aliases ( Extended in Kotlin 1.1)

Is Switching from Java to Kotlin a safe bet?

Although Java is considered the most widely used programming languages in the world, Java might not be the best option for your Android development always.

The reason is that Java is a primitive language. Java 8 has been a remarkable achievement for the platform by introducing a lot of new features including the lambda functions. But it seems like Android can only support a subset of Java 8 features. So would we reap Java 8’s benefits to a full extent any time soon? Maybe not. In that case, you are pretty much stuck with Java 7 for your Android projects.

Endless try-catch blocks and NullPointerException are some main issues faced by developers while programming for Android with Java. It lacks extendability and support for functional programming features too. Moreover, Java is still a procedural language even after the introduction of functional programming elements (lambda expressions and functional interfaces). And its syntax is also very verbose compared to many modern programming languages.

To answer the above question Kotlin code is relatively safer and more concise than Java code, and both kinds of files can work together in Android apps. In other terms, Kotlin can be used for new apps and expand existing Java apps.

The only drawback is that Kotlin is not apt for newbies who are new to Android development. It might be difficult for them to comprehend as most of the documentation and examples are in Java. But the conversion of Java into Kotlin takes a simple case of copying and pasting the Java code into a Kotlin file.

So, Have Kotlin Got our Thumbs-up?

Java is old school and has been in use for Android development for 10 years. Although developers are well versed with the language, we can’t deny its programming limitations over the years. And that’s where Kotlin takes the center stage with its set of perks:

  • It has less coding compared to Java with reduced boilerplate coding thus making execution better.
  • The popular Interoperability feature allows Kotlin to co-exist with Java.
  • It can be learned very easily within few hours and its intuitive and lean syntax creates a gentle learning curve.
  • Kotlin is an open source so no expenditure.
  • It’s Safer than Java and avoids NullPointExceptions errors.

What’s the catch?

While Kotlin is much easier to work with, developing with this language has its own challenges although new releases are managing to address some of these issues.

The most annoying thing about an app built with Kotlin will have a larger APK file than one built solely in Java. This is due to the fact of Kotlin’s standard library stacked up on top of Java’s standard library. Gradle is much slower for Kotlin than Java in terms of build time.

Kotlin for Android development - Yay or Nay?

A few years ago, Kotlin wasn’t as mature and popular as it is today. The language seems more comfortable as it is getting more upgrades. After the completion of the first commercial project, taking the leap for Kotlin was a “Yay” moment after all.

The language turns out to be as hyped “concise, clear and correct”.

Kotlin comes with Android Studio support that means IDE knows how to handle this new emerging language smoothly. With its ease of learning, glitch free security and fewer long-term crashes, the Kotlin is hoped to be deployed with new features. It seems to be written in the cards that this modern programming language - Kotlin will soon steal the spotlight by replacing the old school programming on a larger scale.

At the same time, Java is not going out of the market any sooner too. Java and Kotlin are completely interoperable and supports all Java libraries and frameworks. Android team has promised to keep extending the support for Java developers, just as they always do in their releases. Therefore, this royal language is not going to lose its reputation and charm.

There are a few points where Java wins, and same is true for Kotlin. Java still compiles faster while code size is considerably less in the case of Kotlin. Java has a large community whereas Kotlin’s community support is yet building up.

For now, we can just say that Kotlin has a brighter future and Java will remain the ultimate foundation language, which every newbie should learn before entering into Android development.

About the author
Marc CollBusiness Development at AppFutura

Marc has been involved with AppFutura since 2012. During this time, he has been in charge of different areas, from Content Management to his current position as Business Development Manager. After all these years, Marc has been in touch with the vast...

Read more...
You might also like