Android Studio 3.0 with Kotlin: First Look

The most awaiting release, Android Studio 3.0 has been released a few days back with exciting features including Kotlin and Java 8 support.  Even though developers were able to use Kotlin and Java 8 earlier, this time they do not need any extra configurations to enable them. This article explains how to create a hello world Android application using Kotlin.

Android Studio 3.0 with Kotlin: First Look

Wait... This is Java Helps but I am writing about another language! Am I running out of content? Of course Kotlin is a new language but still, it is running on top of Java Virtual Machine. Kotlin can be compared with Groovy in terms of how it compiles the code. Both of them produce the same binary code that every Java developer is familiar with. Therefore Kotlin is another baby joining the family of JVM languages but with different syntax and more features.

Either download Android Studio 3.0 or upgrade your existing Android Studio to 3.0 before reading further.

Step 1:
Create a new Android Studio project and name it 'Hello World.

When you create the project, tick the "Include Kotlin support" checkbox.

Step 2:
Click all upcoming 'Next' and the last 'Finish' buttons with default values.

Step 3:
Now you should get the MainActivity.kt as shown below. Note the file extension. It is not but MainActivity.kt.

Step 4:
Run the application and make sure that everything works before we play with Kotlin.

Step 5:
JetBrains has a decent documentation on Kotlin. I highly recommend you to go through it. At least, going through the basic syntax will be helpful to understand the code.

Package and import statements are similar to the Java package and import statements. The MainActivity class is defined as a sub-class of AppCompatActivity. The onCreate function is equivalent to the onCreate method of Java version but the syntax is completely different. The onCreate method receives a nullable (because of that ? at the end of Bundle) savedInstanceState object. The rest is similar to Java implementation of MainActivity class.

Step 6:
Modify the activity_main.xml as shown below. This code creates an EditText and a Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

        android:text="Say Hello" />

        tools:layout_editor_absoluteY="151dp" />


Step 7:
Modify the MainActivity.kt as given below. This code finds the etName and btnSayHello components and set the onclick listener to the btnSayHello.
package com.javahelps.helloworld

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        // Find the EditText etName
        var etName = findViewById<EditText>(
        // Find the Button btnSayHello
        var btnSayHello = findViewById<Button>(;

        // Set onclick listener
        btnSayHello.setOnClickListener {
            Toast.makeText(this, "Hello ${etName.text}", Toast.LENGTH_LONG).show();
I am not going to explain the Kotlin specific syntaxes here. Instead, detailed articles I found in the Internet have been shared for your information.

Step 8:
Run the application and check the output.

In conclusion, I find Kotlin interesting due to its modern appearance. The ability to use exsiting Java libraries and the IDE support provided by IntelliJ makes it a reliable alternative to Java. Kotlin also has its drawbacks but since Google has decided to go with Kotlin, I would advise Android beginners to use Kotlin. Java developers can easily adapt to Kotlin eventhough still they can use Java to develop Android applictions.

Find the project @ GitHub.
Next Post »


Write comments
ghazali nadia
January 23, 2018 at 6:50 PM delete

hi , good article , i need help how can contact you plz?


Contact Form


Email *

Message *