ANDROID & KOTLIN - GETTING STARTED

Chema Rubio
3 min readSep 4, 2016

--

WHAT IS KOTLIN ? 〈(゜。゜)

Kotlin is an open source language developed and maintained by JetBrains, the company behind IntelliJ IDEA, in which Android Studio IDE is based. In my opinion one of the best development IDEs.

This language is designed to interoperate with Java and is reliant on Java code from the existing Java Class Library.

Perhaps another JVM alternative, but designed to be light by excluding all the domain-specific heft and only keeping the core features missing from Java.

WHY USING KOTLIN ? ¯\_(ツ)_/¯

Kotlin is an easy to use alternative to Java, it is highly interoperable, you can mix Kotlin and Java code in the same project.

This feature can make Kotlin interesting to any Java developer who expects more expressiveness and less verbosity (avoid boilerplate).

So, what does Kotlin offers as a programming language ?

  • Easy learning: Kotlin is very well documented and it has a quiet fast learning curve.
  • High interoperability: It works with any other Java libraries, with very simple interoperability. You can mix Kotlin and Java code in the same project and it works perfectly.
  • Android Studio and Gradle integration: There are some plugins that make this happen.
  • Kotlin library is quite small compared to others.

WHY NOT USING KOTLIN ? (╯°□°)╯︵ ┻━┻

To be honest, I couldn´t find any weight reason not to try Kotlin, even if just for fun it worths a try. Spending a couple of hours programming in Kotlin made me realize that it brings more strengths than pitfalls in its current version and programmers could really take advantage from its features.

Here some examples of companies already using Kotlin in their developments.

USING KOTLIN WITH ANDROID STUDIO

https://raw.githubusercontent.com/ServiceStack/Assets/master/img/wikis/android-studio-splash-kotlin.png

Here, it will be explained how to configure Kotlin in Android Studio using JetBrains´ Kotlin Plugin and also a small HelloWorld application will be set in order to explain how does this plugin work and what can it do for developers.

First of all, create a new Android Studio project, once the project is created, it is time to install the Kotlin plugin for Android Studio.

After installing the plugin, some new actions related to Kotlin are available in the IDE.

In order to configure our project so it becomes compatible with Kotlin, it is necessary to convert Java files into Kotlin files (.java -> .kt) and configure the project before we can run it, let´s see how this is done with just executing two actions.

CONVERT JAVA FILES INTO KOTLIN FILES

Now, MainActivity.java is written in Kotlin:

CONFIGURE KOTLIN IN PROJECT

Kotlin is configured modifying Gradle file the following way:

RUN THE APPLICATION

CONCLUSION

In this first article about Kotlin it is seen how easy is getting started with this language in Android development, if after reading this article you are willing to give Kotlin a try, keep reading next articles about testing applications and a deeper Kotlin practice.

--

--