Java is one of the world’s most popular languages. One of the major uses of Java is Android operating systems. However, Java isn’t built for Android, and because of this, there are many Java features that are unnecessary for Android development. The design rationale for Kotlin is to create a streamlined Java that uses the JVM and still plays nice with Java. How does the successor, Kotlin, stand up to the current king, Java? Let’s find out! But first, let’s look at both languages individually.
Java holds a weighty crown. It’s often labeled as the most used language, and it’s design policy of ‘write once, run anywhere’ (WORA) means it has numerous applications both on and off the desktop. It’s statically typed, compiled, and general-purpose. Java runs on the Java Virtual Machine (JVM) which acts as an interpreter for the already compiled Java. The Java programming language was developed by Sun Microsystems, and it was originally released back in 1995.
Java is the preferred language for Android. Although Android operating systems are not written in Java, all Android apps are written in Java (at least partially) and run on a custom JVM made for devices with lower power.
Kotlin is jealous of Java’s crown. Kotlin, unveiled in 2011 by JetBrains, is cross-platform, statically typed, open-source, and general-purpose. Kotlin also runs on the JVM just like Java does. It also has type inference, meaning that while the language is statically typed, the type declarations don’t have to be explicit. This is just one reflection of how Kotlin is designed to be efficient, practical, and effective.
One of the major targets for Kotlin is the Android platform. The goal for Kotlin was not only to create an efficient, modern, and practical programming language, but to create a programming language that is more efficient, modern, and practical than Java. How does it stack up?
Java VS. Kotlin
These languages are easy to compare, and they have one target where they compete the most: Android. So we will compare the two languages based on how they work for software development on that platform (even though both have applications outside of Android).
Typing and Syntax
This is what Kotlin code was designed to do better than Java. Kotlin’s type inference has a big hand in this victory, as it removes the extra lines of code needed for variable declarations. It also helps with the headache-inducing ‘nullpointerexception’ problem in Java. Kotlin has built in null safety; it doesn’t use null values, therefore it can’t run into these exceptions.
Kotlin also removes a lot of boilerplate code. For example, semicolons are no longer necessary to end a line statement, a new line is enough.
However, Kotlin’s brevity works against it for new users. For existent Java Android app developers making the switch is easy, Kotlin is, at its heart, essentially a smoother Java. However for new users that have little to zero knowledge of Java, Kotlin’s brevity can be difficult to understand.
The run speed, after compilation, should be nearly identical for both of these languages as they are converted into the same type of low-level language that is later interpreted at runtime. Speed here will refer to the compile-time: how long it takes to turn your high-level code into that low-level code.
The compile-time matters; when you’re creating and debugging your Android applications you’ll likely have to compile and recompile countless times. Having a quick compile-time does wonders for development speed.
In most tests, Kotlin’s compile is behind. Java currently compiles faster than Kotlin, though Kotlin is catching up. The difference in speed isn’t major: while it depends on a variety of factors, Java averages a speed increase of around 13%.
This is another keyword in the push for Kotlin. Java is a general-purpose language, it’s not built for Android. Because of this, it doesn’t always play nice with Android software.
Kotlin does, and Kotlin also plays nice with Java as well; it can function alongside other Java code. It even runs on the JVM as mentioned before. This provides huge advantages for anyone looking to migrate from Java to Kotlin. They don’t even have to migrate everything all at once for everything to still function.
Java has been king for a long time. It has a massive community surrounding it and mobile app development with Java. Kotlin also has a community, but it’s not even close to the same size that Java has. This means it can be more difficult to find answers to your Kotlin specific questions, and there are fewer resources for learning how to code in Kotlin.
In short, Kotlin is designed to be an improved Java. Kotlin has shorter code, more security features, and easier typing. While Java is still faster and has a larger user base, Kotlin has interoperability with Java and runs on the JVM, so Kotlin runs on Android just as well as Java.
Which Should You Pick?
According to Jetbrains, Kotlin is used for nearly 60% of the top 1000 Android apps at the end of 2019. Despite it’s few drawbacks Kotlin is not only the future of Android app development but its present. Kotlin also has many safety features that come built-in that Java doesn’t. Kotlin seems to succeed in its design, to be a better Java.
Kotlin is also beloved by developers. In a survey of Stack Overflow programmers, it ranks #4 in the ‘most beloved’ category. Java, for reference, is in the top 10 ‘most dreaded’ languages.
While selecting Java for Android development isn’t a bad choice, for most people choosing the heir (Kotlin) is the better choice. However, for purposes outside of Android development Java is still ahead.
If you already know Java, transitioning to Kotlin may change how you develop for the better. It can increase security, improve your development speed, and you may just love it. If you’re looking to get into Kotlin or Java development, now is the time to do it. With dozens of effective coding bootcamps available to you, there’s no good reason not to start today.