Java vs Kotlin: Which one should I use?

Java and Kotlin are both very similar languages. But which one is best for you?

June Redwood
4 min readOct 11, 2021
Image by JetBrains

Why would I need to switch from Java anyway?

Java is not a perfect language. Well, none of them are. Java can be really useful and fast, and sometimes it can just be super annoying. Some of the problems with java are: Errors that are sometimes impossible to understand, Picky syntax errors, Long camel case names, No global variables, and more.

Kotlin, on the other hand, is definitely closer to perfect. It has safety from NullPointerExceptions, global variables, actually readable errors, which means Kotlin is basically a solution to all of your Java pet peeves. Kotlin was introduced by JetBrains in 2011.

Kotlin also runs on the JVM, meaning that most of your Java code will run fine on Kotlin!

Although everything has its ups and downs. So let’s get into it!

Java

Java is a statically typed OOP (object-oriented programming language) that was introduced by Oracle in 1995:

Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!

Pros

  • Lots of resources

If you’re new or more seasoned with programming, you’ll still at some point need to find help. Well, you’re in luck, because Java has lots of online resources! Not from oracle, but from the community. Websites like Javatpoint and W3Schools have easy-to-read tutorials for a new and sometimes experienced learner.

  • Backward compatibility

Java is very good at dealing with legacy software! Java updates almost never remove things, they usually just create new things. This means that if you wrote a program on the day of its release in 1995, it could still work today!

  • Large community

Java has a large community and userbase. You will rarely go without the perfect class or component that doesn't fit your needs, and if you do, there’s probably something similar out there in the Javaverse.

Cons

  • Picky errors

Java errors can be very picky. If you do one thing wrong, there isn’t really a failsafe. Your program will almost definitely immediately crash, and print a very hard-to-understand error, which will be my segway!

  • Errors can be very difficult to understand

Whoever programmed Java errors didn’t have ease of use in mind. When I first started with Java, I had to ask someone who knew more than me about almost every single error that I got.

Kotlin

Kotlin was released by JetBrains in 2011, as a kind of extra layer of improvement on Java, trying to make it’s level of DX (Developer Experience) higher. The goal of Kotlin was to make Java developers have an easier experience with coding harder things, and enjoy programming more.

Pros

  • More versatile functions

Kotlin has many different types of functions. Lambda, high order, and inline functions are all very popular features in the community, and help you write clean code.

  • Null safety

Kotlin keeps you safe from NullPointerExceptions! It has a special ?modifier, that when applied, allows a null value to be the value for the variable. If the ? modifier is not present in the declaration, a NullPointerException can never occur!

  • Compatibility with Java

Because Kotlin is built on the JVM (Java Virtual Machine), you can have .java and .kt files in the same project! You can even use a class defined in Java in your kotlin code, and use all of its methods!

Cons

  • Almost too clean

Sometimes, code like this can be unreadable:

To a beginner or even an advanced Kotlin programmer, this is not understandable. There are functions with not very descriptive names, methods using {s, I could go on.

  • Classes are final by default

This one is kind of self-explanatory. Classes are final by default, which can be annoying if you need to change something in the class dynamically.

Conclusion

Kotlin and Java are similar but different in many ways. There are so many things I wasn’t able to include here, and I’m sorry for that. But at the end of the day, here is my final opinion:

If you read this to make a major decision, like change your job or switch a big program from Java to Kotlin, it might not be the right time to switch. Java still has lots of time left to go, and switching to Kotlin might require rewrites of certain parts of your program.

If you’re new to programming, definitely go with Kotlin. Learning modern concepts first is a lot better for your programming skills and ability to get a job, as Kotlin won’t die any time soon.

Thanks for reading this! I hope this helped, and if it did, clap for this post or follow me!

--

--

June Redwood

Hiya! I’m June. Front-end Enthusiast | React learner | School student