What is Kotlin Language



Kotlin new programming language targeting JVM platform.it is complete interoperable with java meaning that we can use any java code, libraries and frameworks in Kotlin project. Like java we can develop desktop applications, web applications and android applications with Kotlin language.

Kotlin language is as fast as java so it has all amazing features of java, features of modern programming languages and interoperability with java will help companies to migrate java applications to Kotlin.

Official website of Kotlin language also provide Java to Kotlin Converter to convert your existing java code to equivalent Kotlin code.

History

Jetbrains started working on Koltin language back in 2011.

In Feb 2012 jetbrains made kotlin project open sourced and in Feb 2016 first stable version of kotlin language was released.

In May 2017 at Google I/O confrence, google announced Kotlin as official language for Android Development, which proves Kotlin language has bright future and it is worth learning language.

Scala is modern JVM language but compile time is very slow as compare to java. Developers of Kotlin language wanted language which will have robustness of java, modern features of scala. Lets discuss key features of kotlin language.

Kotlin Features

Runs Everywhere

Like java Kotlin also runs everywhere. We can build server-side code (backend of web applications) with Kotlin, we can build android applications we can use Kotlin to build desktop applications by using Kotlin and javaFx together.

Kotlin also works in other contexts like, we can use intel Multi-OS engine to run Kotlin code on IOS devices.

Statically Typed

Like Java language Kotlin is statically typed language means that the type of every expression is known at compile time.

But unlike java Kotlin does not require you to provide every data type of variable. In most cases Kotlin is smart enough to determine datatype of variable from its expression, we will talk more about this in details when we will learn about variables in Kotlin.

Expressive

Unlike java Kotlin language is expressive and removes all unnecessarily explicit code that we used to write in java.

For example, if we want to write simple data class for Person object in java, we will write this code.


public class Person {
    
    private int id;
    private String name;
    private int age;

    public Person(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    
   
    @Override
    public String toString(){
        return "id: "+Integer.toString(this.getId())+",name: "+this.getName()+",age: "+this.getAge();
    }
        
}

But in Kotlin language we will write this code

data class Person(
        var id: kotlin.Int,
        var name: String,
        var age: kotlin.Int
)

Kotlin will generate all fields, getters, setters and some other useful methods such as toString() method for us.

Null Safe

If you are java developer then you will be familiar with annoying NullPointerException. Using safe call operator (written ?) Katlin’s type system tracks values that can and can’t be null and forbids operations which will lead to NullPointerException.

Interoperability

Kotlin is interoperable with java. We can call java methods, extends java classes, implement interfaces apply java annotations to Kotlin classes.

We can call Kotlin code from java as well. Because Kotlin languages is new and it does not have its own collection of libraries but with Kotlin we can use any library written in java in our Kotlin project.