Last year, Google acknowledged Kotlin by making it the second official language of Android app development. Since then, Kotlin has also been steadily building partnerships with Google Cloud Platform, the Spring Framework, and Gradle. The Kotlin mobile app development community is growing and Android developers finally have the pragmatic, modern, and intuitive language they’ve been waiting for.

What is Kotlin?

Kotlin is a statically typed programming language for Java Virtual Machine (JVM) and JavaScript. Described as a general purpose language, Kotlin introduces functional features to support interoperability and intelligibility. The Kotlin project was born out of the aspiration for heightened productivity. The goal was to improve the coding experience in a way that was practical and effectual.

Kotlin is both an object-oriented and functional programming language. It’s compatible with OO and FP styles allowing developers to incorporate elements from each form. Kotlin offers support for higher-order functions, function types and lambdas, making it a great choice for functional programming.

A central focus for Kotlin is to enable mixed-language projects. Kotlin is entirely compatible with Java and Objective C, which makes learning the new language painless. Kotlin introduces improved syntax, as well as concise expressions and abstractions. Using Kotlin with Java eliminates the need for excessive boilerplate code, which is a huge win for any developer.

The Growth Of Kotlin

Kotlin saw an explosive of growth for Android development after Google I/O 2017 . Since then, JetBrains hosted the very first KotlinConf and announced the beta release of Kotlin/Native.

In 2018, Airbnb began transitioning away from React Native in favor of Kotlin. In fact, they’ve written 80 percent of their new code in Kotlin. So while the adoption of cross-platform Kotlin development hasn’t been explosive, major industry players are taking note of the many benefits Kotlin has to offer.

Is this the end of Java?

There are mixed opinions from developers.

Java is a reputable programming language with vast open source tools and libraries to help developers. With that said, no language is without fault and even Java is subject to complications that can make a developers job tedious. If anything, Kotlin will introduce solutions to common programming headaches and improve the Java ecosystem as a whole.

In the last year, Kotlin has become a more stable and congruous development option for Android Studio. Some developers seem to believe that Kotlin will oust Java for Android development in the coming years. Other experts see Kotlin and Java existing in parallel without one outweighing the other.

For most, Kotlin’s strengths outweigh the language’s setbacks. There are definite limitations within Java that impede Android API design. Kotlin is inherently lightweight, clean and far less verbose, especially in terms of writing callbacks, data classes, and getters/setters. In other words, Kotlin was specifically designed to improve existing Java models by offering solutions to API design deficiencies.

Kotlin addresses a number of Java-induced weaknesses:

Brevity

A lot of developers praise Kotlin for being concise. This is a quality Java is not known for; however, readability should always take priority over concision. Yes, the succinct nature of Kotlin uncomplicates a developer’s job and leaves less room for error, but Kotlin doesn’t practice concision for concision’s sake. Boilerplate code is a problem to read through and leads to more bugs and wasted time to try to identify them.

Android App Development

Above is a simple calculator function written in Java. For comparison, here is the same calculator written in Kotlin:

Kotlin Android App Development

It may not seem like much, but the Kotlin version of this calculator is written in half the lines of code it took to program the function in Java. Brevity is a crucial factor for productivity. Writing large projects becomes easier when a developer is given more power for every line of code. A key observation here is Kotlin does not overlook comprehension for the sake of brevity. The syntax is concise readable and still substantial.

Interoperability

Interoperability is Kotlin’s core purpose. From the beginning, the project’s intention has been to use existing knowledge and expertise to make every library out there available to Kotlin programmers. Developers can simply write modules in Kotlin that work flawlessly within existing Java code. By emitting the Bytecode, a Kotlin compiler allows the two languages to work in unison in the same project.

Inbuilt Null Safety

Kotlin’s type system has inbuilt null safety. The infamous NullPointerException is largely responsible for Android and Java development mistakes. Android relies on null to represent the absence of value, but null can easily destroy an app. Kotlin solves this problem by incorporating inherent null safety. This addition saves developers from writing extra code to work around the issue.

No Raw Types

Before generics came into play, raw types were used quite frequently. Raw types allow for backward compatibility, but raw types can throw a CastClassException and the error will occur during execution and not the compiling stage. Kotlin does not allow raw types, and as a result, produced a more type-safe code.

No Checked Exceptions

The checked exception feature in Java can be problematic. Checked exceptions are when the compiler forces the caller of a function to catch or (re-throw) an exception. The fact is, checked exceptions are often unnecessary and cause empty catch blocks. Non-existent checked exceptions are an annoyance for developers because they’re forced to weed through the code to identify a possible exception that never actually occurred. As a solution, Kotlin removed them entirely, which again minimizes verbosity and improves type-safety.

Is it Necessary for Developers to Learn Kotlin?

No, but sorta.

While it is not entirely necessary for developers to make the switch to Kotlin, they’re going to encounter the language eventually. If you’re already familiar with Java, learning Kotlin will be simple. The language is poised to impact app development on a certain scale, so it doesn’t hurt to learn the basics, and growing with modern techniques and development styles will aid the growth of any developer’s skill set.