DEV Community

Cover image for Why use Kotlin for Android development? Kotlin benefits, features, versions
Diana Maltseva
Diana Maltseva

Posted on • Updated on

Why use Kotlin for Android development? Kotlin benefits, features, versions

In accordance with Stack Overflow Developer Survey 2018, Kotlin is the 2nd most loved programming language and the 4th most wanted in the world.

Recently, TechBeacon digital platform included it in the list of 5 emerging languages with a bright future. In 2017, at Google I/O annual conference, Kotlin was announced as an official language for Android development.

Uber, Trello, Basecamp 3, Shadowsocks, Evernote, Pinterest, and Coursera have already used Kotlin in their Android applications. Why is Kotlin becoming so popular? What great functions does it include?

Perhaps, you should think about learning this technology and/or moving your projects to it? Let's get deeper in the question, Kotlin advantages, features, and versions.

Kotlin is a statically-typed programming language, created by JetBrains company, located in San-Petersburg. Providing full compatibility with Java, it runs on the JVM (Java Virtual Machine), enables to write less code, has readable syntax, and can be compiled to JavaScript source code.

The main advantages of Kotlin

1. Kotlin allows writing less code

Less code is important but there is readability that also should be considered and desirably improved. With Kotlin, you receive them both. JetBrains did their best to make the language as concise as possible, and they managed to do it.

Less code, when done right, results in fewer bugs. When you let framework take care of certain mundane aspects of coding, you can focus on more important things. Kotlin is all about high readability, simplicity, and the facilitation of the app development process.

2. It solves developer challenges

Kotlin came from the industry, not academia. JetBrains needed a simpler tool than Java to work with their main product, called IntelliJ IDEA, totally written in it.

They investigated the alternatives, stayed unsatisfied, and decided to invent their own language. The goal was to get an effective tool that could be used together with Java and work everywhere where Java can.

So, Kotlin solves challenges faced by programmers. For instance, the type system helps you avoid null pointer exceptions. Research academic languages tend to not have null at all, but this is of no use to software engineers working with large codebases and APIs which do.

3. Adopting Kotlin is easy

If you want to facilitate the product maintenance or streamline custom Android app development, you can assign two or three engineers to move the project to Kotlin starting from a small part of the code base.

4. Kotlin is fully compatible with Java

Another advantage is that Kotlin programming language is fully compatible with Java. Kotlin developers have access to all Java frameworks and libraries while writing more clear and concise code.

So, Android engineers can use both languages when building a mobile product as well as migrate their applications from Java to Kotlin.

Even if you have a large Java-based project with millions of code lines, you can easily convert it to Kotlin one file at a time and you’ll see everything still successfully compiling. Here in BLAKIT, we write our code in Kotlin and use Java only for maintaining old projects.

5. It imposes no runtime overhead

The standard library is small and tight: it consists mostly of focused extensions to the Java standard library. Heavy use of compile-time inlining means functional constructs like pipelines of map/filter/reduce compile similarly to an imperative version of the same code.

6. Kotlin has a strong community

JetBrains are constantly improving the language. It's committed to the project, has a large and highly competent team working on it, has a stable business model and is even converting parts of their own flagship product to use it.

7. Kotlin suits for the multi-platform development

Android development isn’t the only thing you can use Kotlin for. The language provides JavaScript support and interoperability, enabling developers to move their frontends to Kotlin or create them in it from the very project beginning.

What's more, the founders added Gradle support so that you can write Gradle files in Kotlin. They are actively developing Kotlin/Native, which allows building iOS applications. This way, you can write even native apps in this language, too.

8. Kotlin development offers more safety

The Kotlin developers integrated into the semantics the principles that prevent a variety of common mistakes usually happening during the program execution. Another reason for Kotlin higher level safety (comparing to Java) lies in its benefits.

It enables the implementation of the same tasks with less time and effort. When the code is more simple and easy-to-understand, errors are more difficult to make and much easier to find, so the chances for them significantly decrease.

Also, check out the review of Kotlin useful features and the latest versions.

Top comments (11)

Collapse
 
pawarpayal005 profile image
Payal Pawar • Edited

Which is better programming language (Java or Kotlin) to use in Android Development and how to use it? Please guide me.

Collapse
 
dianamaltseva8 profile image
Diana Maltseva • Edited

Hi.) Kotlin is much simpler and allows writing more concise code. Provides features missed in Java, while it is fully compatible with it. Java is more popular as it exists for decades and it is really great. Many companies are using Java, so you might need it to work on some projects.

Here is a list of sources that will help you learn Kotlin:

Kotlin on Android:

  1. Get Started with Kotlin on Android: A short guide to start using Kotlin in Android Studio.
  2. Kotlin-Java Interop Guide: A set of rules for authoring public APIs interoperable in Java and Kotlin.
  3. Kotlin Style Guide: Google’s Android coding standards for source code in the Kotlin Programming Language.

Samples

  1. Sunflower: An end-to-end sample app that illustrates Android development best practices with Kotlin and Jetpack.
  2. Kotlin samples: A collection of Android code samples written in Kotlin.
  3. Converting your iOS App to Android Using Kotlin

Other

  1. Tutorials
  2. Kotlin on StackOverflow

Hope, I've helped you!)

Collapse
 
savnisharma1 profile image
savnisharma

If you are starting with Android, definitely go with Java as you will be able to find much more information about Android development in Java which will be extremely important in the starting phase.

Later, you can switch to Kotlin or stay with Java as per your preference.

Kotlin is just another language for JVM (Java Virtual Machine) and knowing Java will help you to grasp Kotlin faster as a lot of information is available in form of comparation between Kotlin and Java.

As you will become skilled in both languages, you can find solution in Kotlin or Java and you will be easily able to transform it to the language you are actually using.

And do not worry about Google replacing Java. Kotlin is just a language and needs Java VM to work and the heart of Android is defacto Java VM, so Kotlin is not a new language for Android - it’s just an another option how to write code that will be then compiled to Java byte code, so both Java and Kotlin will co-exists together. For Kotlin, this kind of co-existence is extremely important because Java’s ecosystem is mature, stable and provides way more libraries than is available for any other language. And this gives Kotlin a huge advantage over new programming languages written from scratch.

Spring Framework Online Course

Collapse
 
kabirules profile image
kabirules

I've translated this article to Spanish in case anyone is interested
developinginspanish.com/2019/08/24...

Collapse
 
dianamaltseva8 profile image
Diana Maltseva

Hey! I want to share the link to this article on my Twitter (twitter.com/DianaMaltseva8) and include your name or better - a link to your account on Twitter, too. Could you please provide me with this info?)

Collapse
 
kabirules profile image
kabirules

Sure! My twitter is twitter.com/kabi_rules
Thanks a lot for sharing!

Collapse
 
dianamaltseva8 profile image
Diana Maltseva

Great, well done!

Collapse
 
martin profile image
Martin Beentjes

How is the support with Streams today?

Collapse
 
tedhagos profile image
Ted Hagos

There's an article about Kotlin in here;

There's a portion in it where Streams are discussed; short answer is
  • Kotlin has Streams
  • All collection classes in Kotlin already supports the one-time_iterator behavior of java.util.stream.Stream instance
  • Kotlin doesn't need the initial conversion (collection to stream) and the final conversion (stream back to a collection)
  • BUT remember that Java streams are lazily evaluated while Kotlin streams are eagerly evaluated unless you convert to a Sequence
Collapse
 
dianamaltseva8 profile image
Diana Maltseva

If I've understood you right (you mean the ability to work with streams from Java 8 and Kotlin), kotlin-stdlib provides several extension-functions for transferring Java-Stream into Kotlin-Sequence or Kotlin-List kotlinlang.org/api/latest/jvm/stdl....

If you want to know what alternative Kotlin provides Java-Streams with, collections in Kotlin "out of the box" offer operations, available in Java only when transferring collections into Stream.

To compare:

  • Java someList .stream() .map() // some operations .collect(Collectors.toList());
  • Kotlin someList .map()
Collapse
 
noahbenz2 profile image
Noah Benz

I believe most of the developers still use Java since its the old way. But Kotlin could be a better switch. Take Java Certification Course.