How to start With Kotlin?

By | November 5, 2017

Life is good and everything will be ok, Kotlin is here…

In this article we will check how we can start with Kotlin for Android.

Pre-requisites

First you have to download Android Studio Beta 3.0 from here.

Make sure you won’t overwrite your old Android Studio when you install the new version.

Let’s start
Android Studio has support for Kotlin. Go to Create Android Project. You will see new thing there: Checkbox with label include Kotlin support. It is checked by default. Press next twice and select Empty Activity, then finish.

package com.coderzheaven.kotlin_demo

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

.kt is the extension for Kotlin Files.

? in savedInstanceState: Bundle? ? It means that savedInstanceState parameter can be Bundle type or null. Kotlin is null safety language that means in Kotlin, you will never see the famous Null Pointer Exception.

Leave a Reply

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