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.
- 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.
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.
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 getters
, setters
, equals()
, 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.
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.