6 min read

Please don't suppose Kotlin developers know Java

Table of Contents

Frustrated experience

Photo by Yan from Pexels

Kotlin is one of the most loved languages in 2019 (following the StackOverlow Developer Survey). Thanks to this new popularity, it is no longer a replacement for Java but a new mainstream language. Yet, this new popularity also raises some onboarding issues for new users which don’t have Java background.

My personal story with … Swift

Around 2015, when Swift appeared, I was very excited to learn this new language to create an iOS app. Apple intended to replace Objective-C with Swift. I had tried Objective-C before but I had trouble to wrap it around my head. Swift was very appealing and it gave me the motivation to adventure again in Apple land. The language itself is modern and easy to understand. After several days, I was able to get familiar with it.

However, the trouble was instead elsewhere. It was about the ecosystem at that time. As I was creating an app, whenever I was looking for help for nontrivial stuff, like errors in UI constraints or how to do something in UIKit, most of the answers, in that I found were written in … Objective-C. In StackOveflow or the Apple documentation, you needed to be very familiar with Objective-C to understand the explanation. I eventually figured out to read some of Objective-C but it was really frustrating. It was a vicious cycle: I wanted to learn Swift because Objective-C was annoying, but I needed to know Objective-C to read the documentation or StackOverflow to do useful stuff in Swift.

Of course, in 2020, it is no longer a problem because Apple has pushed very hard to replace Objective-C with Swift. They have replaced most of their old articles with Swift examples. We should not have any trouble to start with Swift today.

And the same thing is happening with Kotlin

As somebody who knows Java long enough, I had a very fluid experience with Kotlin, so I didn’t think that Kotlin is having the same problem, until recently, when I stumbled upon this discussion thread:

I am loving Kotlin, but ... I don't know Java | Reddit

It totally makes sense. As Kotlin is in the same transition as Swift before, there should be somebody who struggles as me in the past. However, I still wonder if it is an isolated case, so I look into the Jetbrains’ state of Kotlin report for 2019 to find out.

Almost all Kotlin developers (92%) were using Java before they started using Kotlin. Most of them (86% of all Kotlin users) still continue to use Java.

Around 8% of respondents who didn’t know Java before started on Kotlin. That didn’t count who might get started directly with Kotlin, get frustrated, and abandoned after. The report was based on data collected until August 2019, and since Kotlin became the preferred language for Android in the same year 2019, this number should continue to increase faster because new developers will continue to join the workforce every year.

Nearly one-tenth of Kotlin developers don’t background in Java. Who might these fellows be? In my opinion, they are:

  • Veteran iOS developers who want to learn Android
  • New developers whose first programming language is Kotlin
  • Developers who know other programming languages but Java
  • …

The original poster of the discussion thread also mentioned something interesting: Each time he posted a question related to Kotlin, the moderators in StackOverflow considered it as duplicated and forwarded him to the Java solution. But as the author didn’t know enough Java, that didn’t help. It seems that the moderators thought that Kotlin was just a Java replacement. But for somebody who knows only Kotlin, it might not be the same.

What can we do about it?

By raising this concern, I’m hoping that our Kotlin community will be aware of the situation. Documentation is a long time effort. The folks at Kotlin language, Android developer, Spring framework, … have done a fantastic jobs and make progress everyday. The community in StackOverflow might not Kotlin newbie friendly yet but I believe we will reach there, as Swift in the past.

In the mean time, if you want to get started with Kotlin, you still have to start from somewhere. My opinion is that should learn a bit of Java alongside with Kotlin. You might’ve seen advice on the Internet which say you don’t need to learn Java to work with Kotlin. It is technically correct but not helpful. Programming language always has an ecosystem behind which makes the language useful. The current Kotlin’s ecosystem is heavily based on Java one, so knowing Java is essential. More specifically, you should:

  • Learn to read Java. You don’t need to be a Java expert, just to know enough to read Java code. Once you have known what a piece of code in Java is doing, you will be able to write it Kotlin.
  • Don’t use the feature Convert existing Java to Kotlin code in Android Studio / IntelliJ yet. Even if it is very useful and quick, but when you are learning, it’d be better to do it yourself. If you find a Java code elsewhere, try to understand what it does then write the Kotlin code from scratch.
  • If you don’t find how to do something in Kotlin, look for a Java solution and translate it into Kotlin. It takes time at first but it will pay in the long run.