Kotlin: A Java Alternative

Apr 3, 2019 9:05:00 AM

KotlinAt one time in the history of computing, there was only a handful of high-level languages: COBOL, Ada, BASIC, FORTRAN, Pascal, C, and a few others.

How the times have changed! These days, there are literally hundreds of high-level languages, with more popping up all the time; we’ve reported on several of them here in the AndPlus blog.

Many of the newer entrants are special-purpose languages with a narrow focus and a limited community of users. A few well-established examples, such as Java, Python, and C#, are general-purpose languages that enjoy wide adoption. And some are upstarts whose backers are trying to get them into the mainstream.

One of these, called Kotlin, has a strong backer indeed: Google.

Origins of Kotlin

Kotlin (named for an island in the Baltic Sea near St. Petersburg, Russia) first emerged in 2011 as a project of JetBrains, a company better known for developing integrated development environment (IDE) software for developers. (JetBrains has since open-sourced the language, and it is now managed and maintained by the Kotlin Foundation.)

The primary motivation behind Kotlin was to create an alternative to Java that would make Android app development easier.

Although it is possible to develop Android apps using other languages, Java has been the language of choice for most Android developers since the beginning. In fact, the Android operating system itself was written in Java.

Java, however, suffers from some shortcomings that drive developers crazy:

  • Although Java allows variables to be “null” (that is, to have no assigned value), referencing such variables can cause “null pointer exception” errors at runtime.
  • Java code tends to be highly verbose, with many lines of code required to perform simple tasks.
  • Java is typically slower than other languages, requires more memory, and, in many cases, compiles more slowly.

Java’s status as the go-to Android development language, coupled with these shortcomings, may be one of the reasons why a recent survey of developers found that Java is simultaneously one of the most-liked and most-hated languages.

Kotlin’s Advantages

Kotlin was designed to overcome Java’s issues while being interoperable with it. As such, Kotlin has a number of advantages:

  • Type inference, which means that the compiler can determine whether data of one type needs to be converted to a different type to prevent errors. The result for developers is fewer lines of code.
  • Kotlin solves Java’s null pointer exception issues by making null part of its data type system. The compiler is smart enough to recognize when a null pointer issue might result and throws an error at compile time. This is an advantage for Android development, which often uses null to indicate the absence of a value.
  • A lack of checked exceptions, which are a way of enabling an application to recognize and deal with error conditions. The result is fewer lines of code because developers need not explicitly code for all possible error conditions.
  • Data classes, which simplify coding of classes whose sole purpose is to hold data without having much functionality. Kotlin generates much of the “boilerplate” code (get and set methods, among others) that Java programmers have to code explicitly.
  • Kotlin supports coroutines, which can enable applications to continue responding to user interaction while certain long-running processes, such as network input/output, are occurring in the background. With Java applications, this type of process causes the entire application to stop responding unless exotic and error-prone multi-threading techniques are used.
  • Kotlin can compile to JavaScript, as well as Android and the Java Virtual Machine, thereby offering a level of cross-platform development.

Shortcomings of Kotlin

To the extent that Kotlin has weaknesses, they are mostly confined to project management issues, rather than problems with the language itself.

Although Kotlin can interoperate with Java, it’s not a Java clone. It’s a different language with different syntax conventions. Developers who are well versed in Java face a steep learning curve. It’s not something you want your Java developers learning while working on a high-profile project. It might be better to have them take some time to learn it when they aren’t working on any projects at all, or perhaps when doing a minor update to an existing, low-impact application.

The Present and Future of Kotlin

Kotlin received a major boost when Google added full support for it, alongside Java, in version 3.0 of its Android Studio development toolkit.

Google, of course, has a vested interest in supporting Kotlin. Why?

Java is owned and supported by Oracle, which means Google has limited influence over its further development. Presumably, Google is in favor of a language that it can exert a bit more influence over, without being fully responsible for its ongoing development and maintenance.

Kotlin would appear to be a perfect fit. Because Kotlin is optimized for Android development, to begin with, and open-source as well, Google can help shape its future and perhaps make it the successor go-to language for Android developers.

Kotlin also has the advantage of being 100% compatible with Java. Java programs can call Kotlin code and vice versa, and everything can compile together without any conflicts, dependency issues, or compatibility problems. Thus, there’s no need to rewrite entire applications; new Kotlin-based functionality can be added to existing Java apps over time without problems.

In this way, Kotlin could potentially take over the Android development world gradually.

Whether things actually turn out that way is an open question. Despite its many advantages, particularly for Android development, the number of developers who have any experience with it is quite small, especially in comparison to the overwhelmingly deep talent pool of Java developers. A mobile app development team that is looking to become a Kotlin-only shop will find it difficult to locate experienced resources.

For developers, there’s a risk, too: Do you spend time learning a language that may not actually become popular, or do you stick with Java, which has a pretty much guaranteed demand? Learning Kotlin could get you on the ground floor of what turns out to be a huge movement, or it could be a complete waste of time. You could learn both Kotlin and Java, of course, but especially for freelance developers, time spent learning a new language is time that can’t be billed to a client.

That said, there are some signs that Kotlin may be gaining some traction. The most recent version of the popular Basecamp collaboration tool was written in Kotlin, and Pinterest, Corda, Evernote, and Uber have introduced Kotlin into their app ecosystems.

Here at AndPlus, we are watching Kotlin with keen interest. Any language or tool that can streamline the Android app development process—especially one that has the backing of Google—is something we believe is worth learning about. We’re all about serving our clients with maximum efficiency, so we find Kotlin’s promise of shortened development cycles with fewer bugs highly attractive. Yes, it’s yet another high-level programming language, but it’s one that at this point looks like a winner.

Learn More!

Brian Geary

Written by Brian Geary

Brian is a true believer in the Agile process. He often assists the development process by performing the product owner role. In addition to his technical background, he is an experienced account manager with a background in design and marketing.

Lists by Topic

see all

Get in touch

LET’S BUILD SOMETHING AWESOME. TOGETHER.

Clients

 
Arthromeda
Bloomberg
crossref
Honeywell Logo
Medica
NexRev
Onset
Predicata