Kotlin was developed by JetBrains and released as an open source language in 2011. In May 2017, Google announced Kotlin as a level 1 programming language for Android at THE I/O Conference. The official website also started to show demos in both Kotlin and Java.

Kotlin is a statically set type programming language that supports both object-oriented and functional programming and is fully compatible with Java. It has many advantages:

  • The code is simple, and the same functionality is only a third of the Java code.
  • Safe to avoid annoying null pointer exceptions in Java.
  • Interoperable, Java can be called from Kotlin, and Kotlin can be called from Java.
  • Functional, based on an object-oriented language, but also uses many of the concepts of functional programs, such as lambda expressions.
  • Open source.

Kotlin is much simpler than Java code, so let’s show me the code! Take the most common Javabeans:

public class Student {
    private int id;
    private String name;
    private int age;
    private String grade;

    public int getId(a) {
        return id;
    }

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

    public String getName(a) {
        return name;
    }

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

    public int getAge(a) {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGrade(a) {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    @Override
    public String toString(a) {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\' ' +
                ", age=" + age +
                ", grade='" + grade + '\' ' +
                '} '; }}Copy the code

If Kotlin was used to implement the above code:

data class Student(var id: Int.var name: String, var age: Int.var grade: String)
Copy the code

Yes, that’s all you need! (I’ll have more time to date my sister later).