Google I/O

Kotlin is now a first-class language on Android

Gabriela Motroc
Kotlin

© Shutterstock / Forest Foxy

The Android team has officially added support for Kotlin, making it a first-class language. For Android developers, this means they will finally have answers to problems such as runtime exceptions and source code verbosity. As of now, Android Studio 3.0 ships with Kotlin out of the box.

The Android team announced at Google I/O that they are adding support for Kotlin, thus making “Android development faster and more fun,” Mike Cleron, Director of the Android Platform wrote in a blog post announcing the good news.

The Kotlin plug-in is now bundled with Android Studio 3.0 and is available for immediate download.

The question on everyone’s lips: Why Kotlin?

Kotlin plays well with the Java programming language, Cleron explained. “The effortless interoperation between the two languages has been a large part of Kotlin’s appeal.” Furthermore, this programming language will be “very familiar to anyone who has used the Java programming language.”

package helloWorld

fun main(args: Array) {
   println("Hello World!")
}

Kotlin is highly expressive with minimal syntactic friction between your thoughts and what you have to type in order to express those thoughts. If when writing code you have asked yourself questions that began “why do I have to …?” you will be pleased to learn that in Kotlin the answer to many of those questions is “you don’t!”

The Android team thinks that Kotlin will make writing Android apps “easier and more enjoyable.Kotlin is also a great match for the existing Android ecosystem. It is 100% compatible with the Java programming language. You can add as little or as much Kotlin into your existing codebase as you want and mix the two languages freely within the same project. Calling out to Kotlin code from code written in the Java programming language Just Works™. Going the other direction usually works without any developer effort too via some automatically applied translation conventions. With the help of a few Kotlin annotations, you can also customize how the translation is performed.”

SEE ALSO: What Kotlin is all about — As explained by Hadi Hariri

Developers love Kotlin. Here’s the proof

Cleron also revealed that developers love Kotlin and we couldn’t agree more. According to the results of our annual survey, Kotlin occupies the sixth position. However, since the first two positions are occupied by Java 9 and Java 6, 7 and 8 respectively, one could say that this young programming language is technically in top 5 most beloved (and used) programming languages.

JAXenter annual survey: Programming languages trends 2017

Kotlin on Android FAQ

The Android team took the liberty to answer some of the most pressing questions.

Here are some of the questions and answers included in the FAQ.

 

How do I use Kotlin with Android Studio?

Kotlin is fully supported in Android Studio 3.0 and higher. Previously, using Kotlin required that you add the Kotlin plugin, but all new releases of Android Studio ship with these tools built in. So you can create new projects with Kotlin files, convert Java language code to Kotlin, debug Kotlin code, and more, without any extra steps. See Get Started with Kotlin.

How do I debug Kotlin in Android Studio?

Debugging Kotlin works just like debugging Java code. You don’t need to do anything differently.

What kind of other IDE support is provided for Kotlin (like lint, autocomplete, refactorings, etc.)?

As of Android Studio 3.0, the IDE has full tooling support for Kotlin.

How do I choose between the Java and Kotlin languages?

You don’t have to pick! You can use both together as you see fit. If you need help discovering whether Kotlin is a good fit for you, you can try it on Android or learn more about the language with these Kotlin resources

Can I call Android or other Java language library APIs from Kotlin?

Yes. Kotlin provides Java language interoperability. This is a design that allows Kotlin code to transparently call Java language methods, coupled with annotations that make it easy to expose Kotlin-only functionality to Java code. Kotlin files that don’t use any Kotlin-specific semantics can be directly referenced from Java code without any annotations at all. Combined, this allows you to granularly mix Java code with Kotlin code. To learn more, seeKotlin’s interop documentation.

Can I use both Java files and Kotlin files in the same project?

Yes. You can adopt as much or as little Kotlin as you like and mix it with Java code using Kotlin’s interoperability with Java.

How do I add Kotlin to my new projects?

When you create a new project in Android Studio, just check the Include Kotlin support checkbox. For more information, see Get Started with Kotlin.

How do I add Kotlin to my existing projects?

Select your module in the Project window, and then select File > New, select any Android template, and then choose Kotlin as the Source language. For more information, see Get Started with Kotlin.

Will there be parallel docs, samples, codelabs, and templates in Kotlin?

We’re working to make our documentation and educational materials as useful as possible to both Java and Kotlin language users. In the meantime, developers can rely on Kotlin’s excellent interoperability with the Java language and the ability to automatically translate Java language code to Kotlin in Android Studio.

Do Kotlin coroutines work on Android? How about async/await?

Kotlin coroutines should currently work, but they are currently an experimental implementation. As such, Kotlin makes no guarantees about future status, and thus, neither does Android.

Which versions of Android does Kotlin support?

All of them! Kotlin is compatible with JDK 6, so apps with Kotlin safely run on older Android versions.

 

Check out the entire list of questions and answers here.

asap

Author
Gabriela Motroc
Gabriela Motroc is an online editor for JAXenter.com. Before working at S&S Media she studied International Communication Management at The Hague University of Applied Sciences.

Comments
comments powered by Disqus