Android applications with Kotlin

Did you know you can write applications for Android using Kotlin instead of Java? Here’s how, in one minute!

Converting to Kotlin

IntelliJ offers a series of features targeted at Android development, among these is the ability to quickly create Android Components:

NewMenu

For instance, selecting to create a new Activity will generate the corresponding XML layout, source file and update and the application manifest. Quite useful. The problem is though that the source generated is in Java, which isn’t an issue of course unless you’re working with Kotlin. However, you can easily work around this. Simply use IntelliJ’s helper to create the necessary components, then select the generated Java file in the Project window and from the Code menu click on Convert Java File to Kotlin File (there’s a different shortcut depending on your keyboard layout).

CodeMenu

All this functionality is available in both IntelliJ Ultimate as well as the free OSS IntelliJ Community Edition, the same one Android Studio is built on.

12 thoughts on “Android applications with Kotlin

    1. Hadi Hariri Post author

      Will follow-up with more posts but the reason is that it is more concise, you write less code, you maintain less code, and keep your code nicer. It is safe, it avoid some of the pitfalls of null. It removes the need to explicit casting. It provides support for closures (and even nicer than with Java 8).

      Reply
      1. Hadi Hariri Post author

        Translates to bytcode, some would say even better than what Scala produces. If you try it with IntelliJ you can even see the bytecode it produces.

      2. Ruiz Aw

        This is good to have native perfomance. Do you think it’s good idea to start android programming with Kotlin without knowing Java? or i will have always ot overlook at Java docs?

    2. Dody Gunawinata

      @kral, I wrote an open source news app based on Kotlin that is available at Github http://goo.gl/FdEPw. You can examine yourself the benefits of using Kotlin in a real world app. It’s awesome. You can mix and match Java and Kotlin code so you don’t need to reinvent anything. Just use any Java library that you need and develop the rest of the app in Kotlin.

      The free app itself is downloadable at Google Play (http://goo.gl/kShgp)

      Reply
  1. Hadi Hariri Post author

    @Ruiz,

    I don’t know Java and I’m programming in Kotlin :). I don’t think you need to understand or know Java to work with Kotlin. You do need to work with the JVM/API’s but you can learn that as you go along, so yes. No reason to start with Java.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s