“If I want to learn Android development, should I start with Java or Kotlin?”
This question comes up in different communities quite a lot and I will try to clarify it here. To answer it, I’ve looked into different articles, posts, and opinions of different developers and tried to summarize what the general consensus is. This article is more of a reflection what the community thinks rather than my own opinion. I am not experienced enough to tell you if you should start with Java or Kotlin, but I can search for the answer. For this, I tried to filter for unbiased opinions. If someone tells you that Kotlin is the way to go while he is trying to sell you his new Kotlin book or course, it makes sense to keep that in the back of your head.
You’ve probably noticed that Kotlin gets pushed in the Android community quite a lot recently. First introduced in 2011, Kotlin is (compared to Java) a relatively new language. It is developed by the JetBrains team, the folks who also made IntelliJ IDEA (the IDE on which Android Studio is based). In 2016, version 1.0 of Kotlin was released, and in 2017, at the Google I/O, it was introduced as an official first-class language for native Android development, which means that Google works closely together with JetBrains to fully support and improve the language, and you can use it in Android Studio right out of the box. Kotlin is not meant to replace Java on Android, but rather to coexist alongside of it, so you can do everything with Kotlin that you can do with Java and vice-versa. Google is not planning to drop Java.
However, a lot of developers see Kotlin as the future of Android programming, because it comes with a lot of improvements, like null-safety, more concise code and a ton of additional features and “syntactic sugar” that make writing, reading and maintaining code easier and less error-prone. If you want to see a full comparison between Kotlin and Java, click here.
At first, I wasn’t sure if Kotlin was just a fad and the people supporting it were just very noisy, that’s why I waited a while before I started learning it myself. And while there is definitely a certain level of hype involved, it doesn’t look like it’s going away anymore. The adoption of Kotlin is growing quickly, a lot of big apps like Pinterest and Trello use it already, Google seems to prioritize it over Java now, and more and more documentation and code snippets written in Kotlin are popping up around the web. As you can see in the screenshot below, in some parts of the Android documentation, Kotlin is now the default tab for code examples, degrading Java to the alternative selection. According to this StackOverflow survey, Kotlin is the 2nd most loved language in 2018. So I think it’s pretty clear that we should not ignore it.
If you already have experience with Java and you are able to read and understand Java code written by others, then it’s a good idea to start learning Kotlin and also write your future Android projects in Kotlin from the ground up. You will have a lot of fun and appreciate the more concise code and increased productivity. It’s very likely that Kotlin will be the primary programming language for Android in the future. More and more apps will be written in Kotlin, which means that a lot of Android jobs will require Kotlin skills.
Because it can compile to Java bytecode, Kotlin is 100% interoperable with Java, which means that you can gradually add pieces of Kotlin code to your existing Android Java projects, call Java methods from Kotlin, and still use all the Java libraries and Android APIs. And since the language is developed by JetBrains, it has first-class support in IntelliJ IDEA and Android Studio. You can use it without adding any plugins, and you get proper code-completion, syntax highlighting, debugging and refactoring tools, and other features, like a Java-to-Kotlin code converter that helps you get started.
However, while pretty much everyone agrees that Kotlin is the better language, most people (even big Kotlin fans) recommend to still start with Java as a beginner.
For one, there are much more Java tutorials out there than Kotlin tutorials and almost every solution for Android problems on pages like StackOverflow from the last years have been written in Java. Most of the documentation is in Java as well and if you start with Kotlin right away, this can make the learning process very difficult and confusing. Understanding the syntax of a language is one thing, but to actually build apps you have to learn how to use the different framework and library APIs. You have to learn what classes you have to use and which methods you have to call in the different phases of your app. And for this you need practice and a lot of examples you can refer to. Knowing the syntax of a language is actually secondary. And most Kotlin tutorials at the moment even compare Kotlin to Java occasionally to point out its advantages, which makes the learning process even more confusing. If you want to learn Android development right now, you can’t completely avoid Java. This might change over the next years, but we are not there yet. Also, while annoying for experienced developers, Java’s verbosity is what makes it so easy to read and understand. Kotlin solves a lot of Java’s pain-points and increases productivity by reducing boiler-plate code, but a lot of what Kotlin does makes more sense when you have some knowledge of how Java works.
Java is not going to be obsolete, even on Android. While I am writing this post, a discussion thread on Reddit appeared, asking the “Java or Kotlin for an Android beginner” question. The answer with the most upvotes comes from Zhuinden, who himself uses Kotlin extensively:
The bottom line is: Even though Kotlin is the new big thing, it is reasonable to start with Java and then learn Kotlin later on. Java is still more widespread and it is hard to find a job with only Kotlin skills right now. Java is robust, battle-tested and easy to learn. Since Kotlin and Java are 100% interoperable, you can start implementing Kotlin into your existing Java projects when you feel ready and it won’t break anything. Once you have some experience with Java, learning Kotlin as an additional language will be pretty easy. It’s not like you have to start from scratch.
Just don’t get religious and stubborn about programming languages. As someone who has spent a lot of time learning Java himself, I am aware that it is important to stay open to new experiences. Learning new things is what makes programming so exciting. While all my video tutorials are in Java right now, I am going to start a Kotlin beginner tutorial on my Youtube channel soon, where we will learn the language together. I will release these lessons in small, bite-sized pieces, and I will keep making my other tutorials in Java for now. So you can keep learning Android development with Java as your primary language and still get a hold on Kotlin parallel to it when you feel ready.
What do you think about the Kotlin-vs-Java decision? Let me know in the comments below!