Kotlin: A New Language For Android Development

by Tinoy Peter

on December 5, 2017

One of the biggest news from Google for Android developers for this year is Kotlin has been selected as the official programming language for Android development. Yes, Google just announced they will officially support Kotlin on Android as a “first-class” language, at the event of Google I/O 2017. We believe this is a great step for Kotlin, and great news for Android developers as well as the rest of Android community. Let’s see what Kotlin language is all about and what do they offer for developers.

What is Kotlin?

Kotlin is a statically typed programming language for the JVM, Android and the browser which is now officially supported by Google For Android.

Kotlin is a new programming language built by JetBrains (formerly IntelliJ), the company which also develops the JetBrains IDE that Android Studio, Google’s official developer tool is based on. Like Java, which is the default language for Android development, Kotlin is a language that runs on the JVM (Java Virtual Machine), and it’s already possible to use Kotlin for Android development. Android doesn’t use the JVM exactly. But the Java roots are strong, and one of the advantage of Kotlin is its interoperability with Java, which have made it a popular choice among developers. Official Google support will be a huge boost for the budding language, and will presumably make working with Kotlin on Android a lot more natural.

Story Behind Java to Kotlin:

JetBrains software development company, had been looking for a modern language that could successfully replace Java in their products. They worked with Java enough to start seeing its limitations and disadvantages. And that’s when they decided to come up with their own solution. One of the main requirements for their new language was compatibility with Java, since a lot of JetBrain’s existing codebase was written in Java. Before developing their own language, they tried out other languages but quickly ran into limitations.

Some of the reasons behind the development of a new language for Android development is quite easy to understand apparently there are a few:

  • Java has been around for over two decades already (quite a term for a programming language), which is why there are loads of features that can not be implemented due to Java’s massiveness and obsolescence.
  • Code written on Java takes quite a while to compile.
  • Null-unsafety (and that infamous NullPointerException)
  • Lack of support for functional programming features.
  • Java’s syntax is pretty verbose, particularly when compared to many modern programming languages.

Kotlin Advantages:

  • Modern syntax and similarities to Swift:

Swift and Kotlin have a number of similarities. Though intuitive syntax is the killer feature when Kotlin is compared to Java. Kotlin has all the features of modern languages you would need! Kotlin has a safe Nullability system, Method references and Lambdas for clean connections between parts of your App, a built in Mutability/Immutability property system to improve the development life and productivity!

  • The interoperability

You don’t have to worry a single bit, if you have started a new project in Java. Kotlin and Java are fully interoperable, meaning you can have any amount of code written in Kotlin, and the rest in Java, and it will all just work together!

Even better, there is a tool in Android Studio 3.0 and above that allows you to instantly ‘translate’ Java into Kotlin, which works quite well most of the time, so that you can have a glimpse at what does a method in Java look like in Kotlin. This is a great feature for beginners, it’s a great guideline.

  • Kotlin requires less code to write:

At least 20% less. The amount of code written in Kotlin would be much lesser when compared to the one written in Java. The reason behind this is Java is a bit outdated and is very verbose. Kotlin’s architecture was created from scratch, causing the absence of layer to layer architecture. An example: Kotlin comes with the support of lambda expressions which is a Java 8 feature, with this we could rewrite the following code as,

Adding a click listener to a button. In Java 7 and earlier, this would typically require the following code:

view.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

toast(“Button clicked”)
}
});

In Kotlin lambda functions allow you to set a click listener using a single line of code:

  1. view.setOnClickListener({ view -> toast(Button clicked) })
  • Easy to Learn

Kotlin aims to be an enhancement to Java, rather than a complete rewrite, so many of the skills you’ve acquired throughout your Java career should still be applicable to your Kotlin projects.

Kotlin is also designed to have a gentle learning curve for Java developers. Java developers should find that most of the Kotlin syntax feels familiar, for example, the code that’s used to create a new class in Kotlin is very similar to Java:

  class MainActivity : AppCompatActivity() {

Kotlin is also designed to be intuitive and easy to read, so even if you do encounter some code that’s drastically different, you should still be able to get the gist of what this code is doing.  

  • The Community and Support

Java language is very closed and  it’s development is hardly influenced by the needs of Java developers. But Kotlin is just the opposite! Jetbrains team takes every idea and proposal from the community and keeps them in mind while developing the language.

The Kotlin is also open sourced on Github, so you can check it out anytime.

https://github.com/JetBrains/kotlin

All Kotlin standard library features are available to all Android API levels. This means that the Streams API can be used, not having to set the minimum SDK version to 24, so waiting for game-breaking features is no longer a necessity!

 

  • The Native

 

Kotlin Native is a milestone Jetbrains is working on reaching, with the idea of running Kotlin code in multiple platforms, without having to compile it down to JVM, making it much faster, and not requiring Java. The platforms to be are Web (both backend and frontend), iOS and Game development.

Which means one can learn a single language and share it among various platforms.

Kotlin downside:

Although Kotlin has lots to offer Android developers, there are some drawbacks you’ll need to keep in mind:

 

  • Extra Runtime Size

 

Your .apk file size increases by around 800KB when we use the Kotlin Standard Library. If your application is already on the large side then that extra 800KB may tip it over the edge and make users think twice before downloading your app.

 

  • Initial Code Readability

 

Kotlin’s concise syntax is one of the language’s greatest strengths, but initially you may find some difficulty to decipher, simply because there’s so much going on in such a small amount of code. Java may be more verbose, but the upside is that everything is clearly spelled out, which means unfamiliar Java code tends to be easier to decipher than unfamiliar Kotlin. Also, if used incorrectly, Kotlin’s operator overloading can result in code that’s difficult to read.

Wrapping up

Finally, Kotlin is an improvement on Java in many ways. Its future is only getting brighter and better. And after Google gave it first language status for Android development, Adoption and usage has already gone up and will only continue to go up. Kotlin’s creators at JetBrains is currently working on applying certain agile development principles including continuous delivery to Kotlin’s development to make sure the language keeps up with industry challenges. Along with Google’s official support Kotlin guarantees that we’ll hear more about it in the future.

Also Read:

What is NFC? How does it work?

 

  • Share this Article

GET IN TOUCH WITH iLEAF

  • We can initiate development process at the hour of your convenience
  • Discussion on the projects can be held for a stipulated duration
  • We will sign NDA and the talks will be secured
  • We’ll show you around our cherished designs
  • Briefing on technology
  • Guaranteed source code delivery
  • Option to re-start a closed venture

See how we can unwrap your app idea and proceed towards success