Kotlin an official language on Android

Kotlin an official language on Android

Kotlin an official language on Android

Kotlin android

Kotlin an official language on Android

     Normally we will create the native Android applications in Java programming language.When run we run the java application, the application compiled into bytecode contains set of instructions and runs in the virtual machine.JetBrains is a software development company. Who developed the android studio based on IntelliJ.
  • Now JetBrains introduced the Kotlin language.
  • Kotlin is programming language runs on the JVM.

Why Kotlin For Android?

     Kotlin is very easy to start because it works side by side with Java and C++ on Android.So you can keep your existing code, continue to use the various Android libraries, and incrementally add Kotlin code to your project
  • Kotlin reduces the amount of boilerplate code.
  • you can call into the Java language from Kotlin, and you can call into Kotlin from the Java language.
  • Kotlin is expressive, concise, extensible, powerful, and a joy to read and write.
  • Kotlin has safety features like nullability and immutability to increase the performance and health of the Android application.

install the Kotlin plugin

Kotlin plugin is inbuilt in android studio 3.0 version,For the earlier version, you can use following steps to install the Kotlin plugin in your android studio.

  1. open your android studio.
    go to File files, select Settings.
Kotlin android
File > Settings


2. In Settings, you can see the many items like Appearance, Editor, Plugins, version control and etc in these select Plugins.

Kotlin android

     3. Under plugin, you can see the Install JetBrains plugin at the bottom of the window.

select Install JetBrains plugin.
In the Browse JetBrains plugin window, search for the kotlin.
Kotlin android
     4. Install the kotin plugin.
Once the installation completed it will ask you to restart the android studio.
Kotlin android

The kotlin plugin installed in your android studio, Now you can develop the android application with kotlin language.Please check this installation of kotlin plugin in android studio.

First Kotlin android applicattion
Below, I am going to show you how to develop kotlin android application in android studio.

1. open android studio and create new project.

Kotlin android
Create new project

After entering the Application and company domain click Next,
In my case, I have named the application name as FirstKotlinApp.

Then, Select for what purpose you are going to develop this application like Mobile and Tablet and wear or TV.
Please select Mobile and Tablet, press Next,

Kotlin android
Mobile and Tablet

Create new Blank Activity to start the app as a Normal blank activity,

Click Next,
Kotlin android
Blank Activity

In this step It will ask you to configure the Activity Name and Layout Name, In my project I set the default name for both activity and layout.

Then click finish.
Kotlin android
Activity Name

Now you can see the default java android project be created.

Kotlin android
You need to convert the Java project into Kotlin project. You can also do convert Kotlin to java project.
To convert the Java language to Kotlin, you need to “Enter Action” in the android studio.
Press “ctrl + shift + a” to open the Enter action tool.
Kotlin android
Enter action

In the enter action search for “Convert Java File to Kotlin File” then press enter to convert the java files into Kotlin files.

Now you can see the Java file is converted into Kotlin file. the extension of the file changed from .java to .kt
Kotlin android
After converting the java files into Kotlin you cannot directly edit the code. still Kotlin not configured.
You need to configure the Kotlin in the Gradle build system.
Kotlin android
Kotlin not configured
select the config > android with Gradle to add the Kotlin into the Gradle.
Kotlin android
Adding the Kotlin into Gradle make the changes in the Gradle file.
Kotlin android
Once added the Kotlin into the Gradle in will ask you the sync the project.
Kotlin android
Once the sync is done, Now your application is ready to run.
You can’t see any difference in java language android application and Kotlin language android application UI.
It will be in the speed and processing.
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

Screenshot of the FirstKotlinApp
Kotlin android

Leave a Reply

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