Skip to content

DA2. Kotlin Vs Java

Statement

  • What are the features in Kotlin that have made it so popular?
  • Why is it preferred for android development over Java?

Solution

Kotlin is a statically typed language that combines string typing with flexibility using type inference. I first met Kotlin this week through this class and I found it beautiful and worth checking. This beatifulnesss is not only because of its syntax but also because of its features. Some of the features that make Kotlin so popular are:

  • Kotlin was adopted by big companies like Google, Netflix, Uber, Pinterest, etc (AndroidDeveloper, n.d.).
  • Kotlin is a modern language that is easy to learn and use, with a lot of abstractions that hide the complexity of the code.
  • Kotlin is a statically typed language that combines string typing with flexibility using type inference. This means that the compiler can infer the type of a variable or return type of a function if it is not explicitly declared; and yet, the compiler ensures type safety during compile time.
  • Kotlin is totally compatible with Java. this means that Kotlin code is being compiled to Java bytecode and runs on JVM. This also mean that Kotlin can use any Java code/libraries and vice versa. Even more, you can escape any java code that is considered a keyword in Kotlin by using backticks (KotlinLang, n.d.).
  • With all of the above features, Kotlin code is 40% shorter than Java code (AndroidDeveloper, n.d.).

Why is it preferred for android development over Java?

The points in the previous section indicate why Kotlin is preferred for android development over Java. However, there are some other points that make Kotlin more preferred for android development over Java (KotlinLang, n.d.):

  • Kotlin prevents null pointer exceptions by introducing immutable variables and nullable types. Where a variable can be declared as nullable by adding a ? after its type; and the compiler will force you check that object is not null before using it. This is a great feature that prevents a lot of bugs.
  • Kotlin has a rich standard library that provides a lot of useful functions and extensions, in an elegant and easy-to-use way.
  • Kotlin has wide wrang of collections that are more efficient than Java collections, and they are all immutable by default, but can be mutable at well.
  • More features include: Type inference, Smart casts, String templates, Data classes, Extension functions, Higher-order functions, Operator overloading, etc.

References