Showing posts with label Kotlin-Hello World. Show all posts

Hello World - Kotlin

Google officially announced Kotlin as a first class language for Android development at Google I/O 2017. From Android Studio 3.0, Kotlin is included as Support for Android Studio. In this post, we will start the development of Android Application with Kotlin.

To Getting Started, you have to download Android Studio 3.0 Canary 1 or Add the Kotlin plugin in your existing Android Studio.

Create Android Project with Kotlin

Create new project in Android studio check the Kotlin support and start as usual with Android Studio 3.0. 
Android Studio 3.0
But for Android Studio with version less than 3.0, we have install plugin form Plugins menu manually by Selecting File-->Settings-->Plugins-->Browse Repositories--> Search and Select Kotlin. Then Click Install

Now inside activity_main.xml create the following UI
<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""

        android:text="Hello World!"
        app:layout_constraintTop_toTopOf="parent" />

In Android Studio 3.0, by default you have Kotin Activity. For Android Studio with Version less than 3.0, can convert their Java activity into Kotlin Activity.
Install Kotlin Plugin
  1. Select Tools --> Kotlin --> Configure Kotlin --> Click Sync Now. 
  2. Open Quick Search or Click Ctrl + Shift + A for Windows Users. 
  3. Search and Select convert java to kotlin or simply Selct Ctrl + Shift + Alt + K for Windows Users. 
Now your MainActivity.kt looks like in the following.
package com.androidmads.kotlinsample_helloworld

import android.os.Bundle
import android.widget.TextView
import android.widget.Toast

class MainActivity : AppCompatActivity() {

    // Declaration
    var helloTextView: TextView? = null
    override fun onCreate(savedInstanceState: Bundle?) {

        // Initialization
        helloTextView = findViewById( as TextView
        // Assigning data to TextView in runtime
        helloTextView!!.text = "Hello Kotlin!";

        // Click Listener in Kotlin
            Toast.makeText(applicationContext, "Hello TextView Clicked", Toast.LENGTH_LONG).show();
Kotlin is a new Programming Language for Android Development. I hope Java is not deprecated for Android Development. Please tell what do you think about this tutorial as well as the future of Java in Android development in Comment Section.