Kotlin compared to Java

Mustafa Atik
2 min readSep 28, 2023

--

I want to write rough ideas comparing Kotlin to Java. My goal is not to praise Kotlin or criticize Java which is still one of the best languages. Instead, my intention is to put my thoughts into text and share them with Java programmers who are curious about Kotlin.

Kotlin was developed to fill the missing gaps in Java that were slow to evolve. Java’s main selling point, and what I love about it, are its compatibility, maturity, and robustness. You don’t have to deal with new breaking changes every year. Java is mature and lets programmers focus on delivering business value rather than constantly learning new paradigms or methods. Kotlin, being a new language, does not need to maintain backward compatibility strictly, which allows it to fix some of Java’s problems immediately. Importantly, Kotlin is interoperable with Java, making migration easy.

Null safety

Kotlin makes sure you will never get null pointer exceptions as it does not allow assigning null to variables unless you explicitly define the variable nullable.

Data classes

Kotlin has data classes that free you from boilerplate getters and setters, hash and equal method implementations, and the need to use Lombok. The good news is that Java now also has a Record concept equivalent of data classes.

Both OOP and functional programming

Kotlin allows you to follow both programming styles or combine them together.

No checked exception

Kotlin does not allow you to define checked exceptions. This might be a missing feature for some but freedom for others. A controversial subject.

No primitive types

Kotlin does not have primitiveint and classInteger variations. It is only class type Int so no need for type boxing.

Method extensions

Kotlin allows you to define additional functionalities to the existing classes. For example, if you have a library that is serialized to XML, text, or binary-only and you want to add support for Json, you can do it.

Concise and more readable code

Kotlin’s syntactic sugars enable us to write more readable code. It lets us write concise code through range expressions, Elvis operator, primary constructors, and chained methods checking nullability or string templates.

Overall, there is a trend of migration from Java to Kotlin, particularly when starting a new project from scratch. I believe Kotlin will continue to evolve and mature over time, and its rapid development pace will likely slow down. Java may also close the gap by adding similar features. As engineers, we should pick whatever works for us today, when Java has the same features in 5 years, then we can start new projects with Java.

--

--

Mustafa Atik

You can find my notes I take when learning something new or reading, watching. So, they only help me to refresh and remember what I’ve consumed.