When we think of mobile applications for any smartphone in the market (except the iPhone) we think of Java, this because during the first years of life of the Android operating system, this one was the only language supported by Google to develop native applications. But this stopped being like this in 2017 when Google named Kotlin the new official language for native Android applications.

Now, focusing more on why everybody should use Kotlin instead of Java for mobile applications, let me explain the points that made me decide to migrate my applications to Kotlin and write any new application in it.

Write less, do more.

One of the things that bothers me the most when writing code in Java is the unnecessary amount of code that has to be written to define an object, Kotlin on the other hand is much more concise when defining an object so much so that if you want to define a class only with the methods that all objects contain such as get and set you can do it in one line while in Java you have to define it for each variable that has that object.

It’s Null Safe.

I’m sure more than one Java programmer has come across the infamous NullPointerException which can cause the entire application to fail and stop working. In Kotlin this error is much easier to foresee and control, while in Java we have to lock up the code fragment that we think can give us this error, instead Kotlin wants to end this billion-dollar error with a simple “?” operator. If we add this operator before invoking a method on a variable and for some reason that variable is null the language will simply ignore that line of code and continue its execution.

Is Interoperable with Java

Although in my opinion Kotlin is an improved version of Java (because it also runs on the JVM) it is still a rather young language so it doesn’t have a sufficient library at its disposal. Fortunately, since it is interoperable with Java we can use almost any library written for Java in our Kotlin applications.

Interpolation

This without any joke was what closed the deal to change my language when developing native applications.

One of the most time-consuming tasks in the development process of an App is debugging and because the debugger of Android Studio is not one of my favorites I choose to use the LogCat tool to check the one that contains my variables and so on. The problem with Java is that until the arrival of Java 8 you could not even interpolate variables and the way it is done is very impractical:

print(String.format(“u1=%s;u2=%s;u3=%s;u4=%s;”, u1, u2, u3, u4))) 

On the other hand, if we wanted to do the same operation in Kotlin, it is a much more intuitive way and with less repeated code as I said in the first point:

print(“$u1 $u2 $u3 $u4”);

For this and many other reasons that I will explain at some other time I invite you to at least give Kotlin the benefit of the doubt and use it for your next Android application.


Posted by

Andres Maldonado – Systems Engineer

IS KOTLIN THE NEW KING OF ANDROID PROGRAMMING? | LA ELECTRONIC
Software Technology

IS KOTLIN THE NEW KING OF ANDROID PROGRAMMING?

When we think of mobile applications for any smartphone in the market (except the iPhone) we think of Java, this because during the first years of life of the Android operating system, this one was the only language supported by Google to develop native applications. But this stopped being like this in 2017 when Google named Kotlin the new official language for native Android applications.

Now, focusing more on why everybody should use Kotlin instead of Java for mobile applications, let me explain the points that made me decide to migrate my applications to Kotlin and write any new application in it.

Write less, do more.

One of the things that bothers me the most when writing code in Java is the unnecessary amount of code that has to be written to define an object, Kotlin on the other hand is much more concise when defining an object so much so that if you want to define a class only with the methods that all objects contain such as get and set you can do it in one line while in Java you have to define it for each variable that has that object.

It’s Null Safe.

I’m sure more than one Java programmer has come across the infamous NullPointerException which can cause the entire application to fail and stop working. In Kotlin this error is much easier to foresee and control, while in Java we have to lock up the code fragment that we think can give us this error, instead Kotlin wants to end this billion-dollar error with a simple “?” operator. If we add this operator before invoking a method on a variable and for some reason that variable is null the language will simply ignore that line of code and continue its execution.

Is Interoperable with Java

Although in my opinion Kotlin is an improved version of Java (because it also runs on the JVM) it is still a rather young language so it doesn’t have a sufficient library at its disposal. Fortunately, since it is interoperable with Java we can use almost any library written for Java in our Kotlin applications.

Interpolation

This without any joke was what closed the deal to change my language when developing native applications.

One of the most time-consuming tasks in the development process of an App is debugging and because the debugger of Android Studio is not one of my favorites I choose to use the LogCat tool to check the one that contains my variables and so on. The problem with Java is that until the arrival of Java 8 you could not even interpolate variables and the way it is done is very impractical:

print(String.format(“u1=%s;u2=%s;u3=%s;u4=%s;”, u1, u2, u3, u4))) 

On the other hand, if we wanted to do the same operation in Kotlin, it is a much more intuitive way and with less repeated code as I said in the first point:

print(“$u1 $u2 $u3 $u4”);

For this and many other reasons that I will explain at some other time I invite you to at least give Kotlin the benefit of the doubt and use it for your next Android application.


Posted by

Andres Maldonado – Systems Engineer