So, you want to learn how to develop apps for android and are wondering which language to pick. Kotlin vs Java, which is best? Which one should you choose? The answer is………it depends.
I know that is a bit of a cop-out answer but hear me out. Both Kotlin and Java are viable, first-class languages. They are both officially supported on Android. Both compile down to the same byte code and run on the JVM (Java Virtual Machine). So what the heck is the difference?
Kotlin vs Java: What is Kotlin?
Kotlin is a statically typed language developed by JetBrains in 2011. Similar to Java, Kotlin has become a top choice for developing Android applications. This is evident from the fact that Android Studio comes with inbuilt support for Kotlin like it has for Java.
Kotlin tends to be much more concise that Java. What you can do in Java with 20 lines of code, you can do in Kotlin with 5 lines. Kotlin has also removed checked exceptions so no more working with Try/Catch blocks. Kotlin has added something called coroutines, which make working with asynchronous processes much easier than threading in Java.
For a bit more detailed look at features of Kotlin, visit Kotlin vs Java: Most Important Differences That You Must Know.
Google announced in May 2017 at I/O that Android would now support Kotlin. It would later announce in May 2019 at I/O that Android would be a Kotlin first platform. This means that Google itself will be favoring Kotlin for android development going forward. Java support is not going away. Most of the libraries and frameworks you will use in your project are still written in Java. What Kotlin first means is that new features and versions will be released for Kotlin first. All Android documentation will list the Kotlin example code first.
For more information about what it means that Kotlin is the preferred language for Android, visit Kotlin is now Google’s preferred language for Android app development
Kotlin vs Java: Not as clear as we thought
Below is a quick summary from and expert, Tim Buchalka. Check it his YouTube channel here: https://www.youtube.com/user/TimBuchalka
Also check out some of his Udemy courses here: https://www.udemy.com/user/timbuchalka/
Being that Kotlin is rapidly gaining in popularity and Google now prefers Kotlin for Android development, it might be a good idea to make Kotlin your target language.
That all might seem pretty straight forward. If Kotlin is Googles’ preferred language for Android, why would you need to compare Kotlin vs Java? The answer to that might be that you already have Java experience. If Java is still a supported language and will be for the foreseeable future, why would somebody need to learn Kotlin? The answer to this question is, you don’t. If you want to stick with the language you already know, you certainly can. This is actually what I did. I am a Java developer so I started working on my Android projects using Java for now.
If you are feeling a little overwhelmed by learning more languages and you start feeling line you are not good enough, you may benefit from reading Overcoming Impostor Syndrome.
It is becoming more clear
You might now be thinking, ‘If I start a new Android project using Java, it’s going to be hell to convert it to Kotlin later’. Lucky for you, the smart people at JetBrains (the maker of Kotlin….and IntelliJ) already thought of that. Java and Kotlin are interoperable. What the heck does this mean you ask? This means that you can use both Kotlin and Java code in the same project, and they can work with each other.
In the same Android project, you can have a mixture of Java classes and Kotlin classes. They can then work with each other as if it was all written in the same language. From a Java class, you can instantiate a new object from a Kotlin class, you can call Kotlin functions from a Java method, and vice versa.
What does all of this mean to you? This means, if you want to start an Android project using Java, you can convert the project to Kotlin one class at a time. The project will still function as normal (assuming you wrote the new Kotlin code correctly.)
You can’t make decisions based on fear and the possibility of what might happen.Michelle Obama
So, which language should you choose to start with? They are both great languages and both have pros and cons. If you do not know either language and you are just starting out, my opinion would be to go with Kotlin. Since this is now Googles’ preferred language, it makes sense to use it.
If you already know Java, you might as well use Java for Android. Since the languages are interoperable you can choose to slowly migrate your app to Kotlin as you learn it if you want to. This is the approach I have taken. In my last two Android apps, I have written in Java. I am now starting to convert some of the more simple classes to Kotlin such as model objects and util classes.