Kotlin GetStarted

Kotlin

In Google IO, Google announced that Kotlin becomes official support language of Android.

Kotilin is powered by Jetbrain which made IntelliJ, Android Studio, WebStorm, PHP Storm, Ruby Mine etc…
Kotlin works with JVM.

To learn Kotlin, I did following.

  • Read Kotlin Official Document
  • Try Android Basic Sample

First Impression

  • Grammar looks like Swift
  • Compare to Java, it’s simple
  • package and project structure is based on Java

Prepare development Environment

If you have IntelliJ IDE, you can start now.
If you want to install kotlin command tool(2017/06/03)
you can install by brew(Mac)

brew intall kotlin

The details are Working with the Command Line Compiler

Hello Kotlin

This is very simple kotlin project.
Create Kotlin project from IntelliJ.

HelloKotlin
|- src
    |- com.atmarkplant
           |- HelloKotlin

HelloKotlin.kt

fun main(args: Array<String>) {
   println("Hello, ${args[0]}!")
   println("Hello World!")
}

Compile Kotlin by command

Compile example

kotlinc CommandKotlin.kt -include-runtime -d CommandKotlin.jar

Run Program

java -jar CommandKotlin.jar

Performance

Basically, it’s almost same as Java (From Kotlin manual)

Android Basic Sample

To work with Kotlin in Android Studio, you need to install preview version 3.0(2017/06)

The details are Getting started with Android and Kotlin

From This document, create Android project and convert project from Java to Kotlin.

We can write both Kotlin and Java in the same project.