Kotlin 1.3 is an Exciting Option for Android Mobile Apps Development

by Jul 30, 2019Android

Printer Icon
f

Introduction

Kotlin is a new programming language, it is designed to interoperate fully with Java. It offers a more concise syntax for developers, but also, it can improve the quality of your app due that its null safety checks, by default it won’t allow any property to be null preventing the most common error in Java/Android applications, the famous NullPointerException.

Kotlin is mainly used for Android development, and it has been adopted for most of the developers and companies because it offers a better and concise programming syntax which makes developers more comfortable writing code, also it is preferred because its stability preventing the common errors seen in a Java program, but also, because it is easy to switch to iOS development given that Kotlin syntax is very similar to Swift.

Here is a couple of examples that compare Java vs Kotlin, you will notice that Kotlin requires much less code and it is easier to read.

Data Class

In Java, you need to declare all the getters and setters as well as the different combinations of its constructor. In the other side, Kotlin just require you to declare this with the “data” keyword and have its arguments in the constructor, and you can have this in one single line of code.

Java

public class Movie {
  private int id; 
  private String name;           
  private String synopsis;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
     return name;
  }

  public void setName(String name) {
     this.name = name;
  }

  public String getSynopsis() {
     return synopsis;
  }

  public void setsynopsis(String synopsis) {
     this.synopsis = synopsis;
  }
}

Kotlin

data class Movie (
      var id: Int,
      var name: String,
      var synopsis: String)

Collections

Kotlin comes with a very useful helper method to manage and iterate over the collections. For example, what if your application is required to get the average age of employees in the company in Dallas. Let’s see how we could accomplish this in Java and Kotlin.

Java

public double getAvgAge
  (@NotNull List<Employee> employees) {
  int ageSum = 0;
  int count= 0;

  for (Employee employee : employees) {
    if (“Dallas”.equals(employee.getCity()) {
      ageSum += employee.getAge();
      count++;
    }
  }

  if (count == 0) return 0;
  return ageSum / count;
}

Kotlin

fun getAvgAge (val employees: List<Employee>):
    Double {
      return employees.filter{
        it.city == City.Dallas }
        .map{ it.age }.average()
    }

Check the official documentation for further details on Kotlin.

Photo by Marc Reichelt on Unsplash

About Us

Krasamo is an award-winning mobile app development company. Our experience and predictable process will make your next project successful.

Learn More

3 Comments

  1. Avatar

    I concur that Kotlin is a viable option for Android mobile apps development. As an IT consultant with some experience in Java/Android software development, I can attest that null safety checks are a significant improvement over traditional Java programming. However, it’s worth noting that switching from Java to Kotlin requires additional training and adaptation, particularly for larger teams. Furthermore, some companies may still prefer the use of traditional Android app development tools, such as Eclipse or IntelliJ IDEA, before transitioning to an Android app development company utilizing Kotlin. Nonetheless, I agree that its concise syntax and stability make it a preferred choice among developers.

    Reply
  2. Avatar

    I completely agree that Kotlin 1.3 offers a compelling alternative for Android mobile app development! As an engineer, I’ve had the opportunity to work with experienced mobile app development company clients who have seen significant improvements in app stability and performance after migrating from Java to Kotlin. The concise syntax and null safety checks are indeed game-changers. I’d love to see more examples of Kotlin’s capabilities in the future!

    Reply
  3. Avatar

    I’m loving this post! As a digital marketer with some Android dev experience, I can attest that Kotlin is definitely gaining traction. For those who are looking to build robust mobile apps, it’s worth noting that partnering with an experienced mobile app development company could also be beneficial in terms of scalability and maintenance. Can’t wait for the next update on Kotlin!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You need to sign in to LinkedIn to post a comment.

By signing in, you consent to the processing of your personal data in line with our Privacy Policy.

Related Blog Posts