From the course: Intermediate Kotlin for Android Developers

What Kotlin has to offer

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

What Kotlin has to offer

- [Instructor] Let's take a look at some of the highlights of the Kotlin programming language. Kotlin is a statically typed language. This means that the types of every expression is known at compile time. This allows the compiler to perform verification on your behalf, which reduces crashes and runtime. This also allows for better code completion when working with any modern IDE. It also allows for refactoring support when you need to make future changes. Additionally, when you cull methods, you get better performance over a dynamically typed program because you don't have the extra overhead of figuring out which methods to cull during runtime. Further, Kotlin was designed to target the Java platform, so it works seamlessly on the server side and on Android. Really, anywhere that Java can be run. But it can also be compiled into JavaScript and has support for native that can be compiled into machine code. Ultimately, it should be possible to use Kotlin in each component of a modern application, whether it's the back end, web, or mobile. Another feature of Kotlin is its concise nature. In this sample code, we're declaring a data class which contains properties for a particular user, their name, age, and email address. Not only is the code minimal, but behind the scenes, a Kotlin compiler generates the necessary constructors, getters, and setters and more. The language is also safe, meaning that it helps you to avoid common pitfalls when programming. One way it does this is by tracking values that can and cannot be null. In this example, the first variable declared name can be null. Notice the use of the question mark after string. However, that second variable cannot be null. Attempting to set it to null will cause an error. Another benefit of Kotlin is that it supports functional programming. Functional programming is becoming very popular in the tech space. It has several benefits, such as conciseness, multithreading, and easier testing. This is due to the use of first class and pure functions, as well as immutability of objects. Here's an example of a lambda expression. It takes in the numbers X and Y and it performs multiplication on them. This can be passed around as a value, perhaps input to a function. Here's another example of how Kotlin supports functional programming, and that's by means of functional style methods available on objects and collections. In this case, we're mapping the list of numbers to a new list, which has the values doubled. Finally, the interoperability with Java is where Kotlin really shines. You can use existing Java methods and classes in your Kotlin code and vice versa. And if you use the Kotlin tooling, you can navigate effortlessly between your various files. Now, let's take a look at some of the specific advantages of Kotlin on Android.

Contents