Introduction to Kotlin for Android

Kotlin
Kotlin

What is Kotlin?

Kotlin is a programming language that purports to be 100% interoperable with Java. Created by JetBrains — the company that created IntelliJ IDEA, WebStorm, and others. JetBrains released the first version in 2011, reportedly after one year of development. The 1.0 release of the language happened on February 15, 2016.

Kotlin is an Open Source language, developed on Github (https://github.com/JetBrains/kotlin) under the Apache 2.0 Open-source license. As of this post, there are 139 contributors to the project.

Why develop with Kotlin?

  • Safe — for example, null references are controlled by the type system
  • Concise — reduces a lot of boilerplate code
  • Versatile — build Android apps, front-end code, and server-side applications
  • Interoperable — with frameworks and libraries of the JVM
  • Easy to read and learn — less verbose than Java
  • Great tooling — Java-to-Kotlin converter, command-line compiler

Kotlin advantages and features

  • Lambda expressions
  • Extension functions
  • Null-safety
  • Smart casts
  • String templates
  • Properties
  • Primary constructors
  • First-class delegation
  • Type inference for variable and property types
  • Singletons
  • Declaration-site variance and Type projections
  • Range expressions
  • Operator overloading
  • Companion objects
  • Data classes
  • Separate interfaces for read-only and mutable collections

Projects that use Kotlin

https://github.com/Kotlin/anko
https://github.com/antoniolg/Bandhook-Kotlin

Why is Kotlin good for Android development?

Oftentimes in Android you’ll get crashes due to NullPointerException. As null references are controlled by the type system in Kotlin, you are much less likely to come across them.

Less crashes == happier customers == better app ratings.

Jake Wharton has a post that describes some advantages Kotlin brings to the table for Android.

Conclusion

Kotlin is a great new language replacement for Java.  It’s very popular in the Android development community, and can be used for back-end server-side development, as well as front-end development.

Try it out for yourself with the online demo IDE: http://try.kotlinlang.org/

Leave a Reply

Your email address will not be published. Required fields are marked *