Introduction to Kotlin

Kotlin is an open-source programming language, which supports both functional as well as object-oriented programming. Advancement in language is being taken care of by Kotlin Foundation group, created by Google and JetBrains. In 2017, Google announced first-class support for the language. Recently, Google also announced that Kotlin will be its preferred language for Android Application development.

Furthermore, the language can be compiled through a Java Virtual Machine, we can also develop Android applications, server-side applications, transpile JavaScript code etc. In addition to, if we are working on a Java-based application there also we can use Kotlin alongside as it is interoperable with Java.

Kotlin – A Statically Typed Programming Language

Programming languages have been classified as Dynamically typed and Statically typed. In Dynamically typed programming languages, the type is checked during run time thus saving us lot of space and time. But, our code will compile despite having run-time errors. In case of Statically typed programming languages, type is checked during compile time and it will not compile until we have fixed the errors. Also, data types need to be declared beforehand in case of statically typed programming languages. Kotlin is a statically typed programming language. In contrast to Java, which is also a statically typed programming language we need to declare variable types before assigning any values. But in Kotlin, we don’t have to explicitly define variable types in our source code. Kotlin in most cases will determine the variable type. The attribute which assists programming language to identify the type of a variable is defined as type inference.

Supports Object-Oriented and Functional Programming

It also supports both object-oriented programming as well as functional programming. As the name suggests, the object-oriented programming is based on objects. These objects are the instances of classes defined. On the other hand, we get to work with functions in functional programming. We can store functions as values in variables, pass them as parameters etc.

Special Attribute

The attribute that makes it stand out is – Kotlin code can be called from Java and Java code can be called from Kotlin. It is interoperable with Java and also let developers to write concise codes. Concise codes can help increase developers’ productivity as the time needed to read, analyze the code is cut short and developers’ could devote their time to some other relevant work. Further, Java developers wouldn’t have to put in a lot of effort to understand Kotlin.

Forbids NullPointerException

Last but not least, we can use operator (?) in our code to get rid of NullPointerException. In case our variable contains null value then it would exclude any operations on it thereby eliminating the event that leads to NullPointerException. For example,

var a: String = null

This code will fail to compile as variable “a” can’t be null. On the other hand, we can use operator (?) to make sure our code compiles.

var a: String? = null

Kotlin programming language is provided under Apache License 2.0 and we can build our applications through any of the following IntelliJ IDEA, Eclipse, & Command line compiler.

In conclusion, we have just introduced you to the beautiful world of Kotlin.

Similar Posts