fun sayHello(){
println(" Hello, Kotlin! ")
}
sayHello()

What Is Kotlin?

Kotlin is a modern programming language developed and introduced by JetBrains, the maker of the world’s best IDEs. It is a general-purpose, cross-platform, statically typed, and an object-oriented programming language which supports type inference. It is generally considered to be a better language than Java. Still, it is entirely interoperable with code written in Java. While developing Kotlin, the main focus was on conciseness, clarity, and safer code. It is also sometimes referred to as Swift for Android. In addition to that, Google had announced first-class support for Kotlin on Android in the year 2017. 

Some Intriguing Features of Kotlin

Robust Code:

You must be knowing how null-pointer exceptions in software have caused substantial monetary losses, dramatic system crashes, and lead to several hours of debugging. For this reason, Kotlin distinguishes between non-nullable and nullable data types, which help in catching and avoiding more errors at compile time.

Type Inference:

More often, due to type inference, we do not need to indicate the type of a variable, as Kotlin is capable of detecting it. Type inference makes our code shorter and our life easier!

For example:

var a : Int = 24 // compiles successfully
var b = 8 // also compiles successfully

Object-oriented and Functional Programming:

Every fragment of data handled by a Kotlin program is an object, and every object has a type. Furthermore, Kotlin is also a part of the functional programming trend of today. From lambda functions, properties, higher-order functions, operator overloading, compact functions to lazy initialization and coroutines, Kotlin has it all! These features allow you to write less code with fewer bugs. You say what you want to do, not how to do it! 

Tool friendly:

To develop with Kotlin, you are free to use any Java IDE such as IntelliJ IDEA, Android Studio, and Eclipse. Otherwise, you can use any editor and build from the command line as well.

Concise and Readable:

Kotlin was designed in such a way that it drastically eliminates the amount of boilerplate code such as the getters and setters. For example, consider the following code written in Java:

public class Student {
private int studentID;
public Student() { }
public int getStudentID() {
return studentID;
}
public void setStudentID(int studentID) {
this.studentID = studentID;
}
@Override
public String toString() {
return "Student(" + "Student ID =" + studentID + ")";
}
}

The above code can be reduced concisely and written in a single line like this in Kotlin:

data class Student (var studentID: Int = 0) 

This way, it ensures readability and keeps things concise!

Interoperable With Java:

You can use Kotlin and Java code side-by-side and continue to leverage existing libraries for the browser, Android, and the JVM. You can also add Kotlin code to any existing Java code. Additionally, you could also migrate your current Java program to Kotlin code entirely using the tools included in IntelliJ IDEA and Android Studio.

 

Statically Typed:

Kotlin is a statically typed programming language. It means that a variable can only be assigned to a fixed type. This acts as an advantage because the compiler can catch type errors during the compile time itself even before the program is executed.

For example:

var num : Int = 24
num = 8 // compiles successfully
num = "eight" // compile time error!
num = 11.0 // compile time error!

Those were some of the most intriguing features of Kotlin. Other than that, Kotlin has not only been used for Android development but also for server-side development and to build web applications. In conclusion, if you are interested in Andriod development, then you owe it to yourself to give it a try!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.