Kotlin Vs Java in Android

I started learning Android development with Java and XML as Java is the official language for android development. But in the recent years it has come to light that Java isn’t the only language for Android development. Kotlin, which was launched in 2016, has now become the official language for Android development.

In this blog post I am going to talk about differences between Kotlin and Java and the disadvantages associated with it.

What is Kotlin?

Kotlin is a general purpose, open source, statically typed “pragmatic” programming language for the JVM and Android that combines object-oriented and functional programming features. Kotlin originated at JetBrains, the company behind IntelliJ IDEA, in 2010, and has been open source since 2012.

Kotlin vs Java

Alot of apps are still built in Java since Kotlin was introduced recently. There has been a lot of hype about Kotlin so let us go through the advantages of Kotlin over Java.

  1.  It is synonymous with Java.

One of the strong points of Kotlin is, it can exists in the same project with Java. You can have a part of your code in Java and a part of your code in Kotlin and the project would run perfectly.

kot1

With this advantage you can even use most of the Java libraries and frameworks in your Kotlin projects.

2. More Functionality, Less Code

Kotlin is very concise in its code. You can put in a lot of functionality with few lines of code as compared to Java.

kot2

Above is a usual Java class. It doesn’t do much. It just contains some data. But as you can see the code just to contain data is so large. Where as on the other hand, Kotlin, for that same code is just five lines of code.  Kotlin automatically has getterssettersequals()hashcode(),toString() and copy() functions for your data class.

3. No more view binding.

In java we use findviewbyId() to locate ID’s from the xml file. In Kotlin, viewing an ID becomes easier and concise.

kot3

Why Kotlin does not appeal to me!

Kotlin may claim to be easier and more concise than Java but it confuses a lot of users. It reduces so much that it is confusing to understand where half of the functionality has gone from the code, even though it produces the desired result. Java may be more verbose, but the upside is that everything is clearly spelled out, which means unfamiliar Java code tends to be easier to decipher than unfamiliar Kotlin.

As a new Kotlin programmer, I tend to look for more documents online based on Kotlin to help me understand functionality better. Since Kotlin is relatively new, there are hardly any support documents online.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.