Java vs Kotlin: a Veteran against the Upstart Challenger
What is Java
Java is an object-oriented statically-typed programming language and computing platform. It was released by Sun Microsystems in 1995 (later acquired by Oracle Corporation). Today, most major elements of Java are accessible as open source, and those that do not mostly have open replacements for them.
Sun, the original developers of Java, placed much of it under the GNU General Public Licence in 2006. Java is employed in the development of Android apps, server apps, web apps, websites, embedded systems.
It is especially popular in financial software development.
What is Kotlin
Kotlin boasts the support of all major Java IDEs including IntelliJ IDEA (the brainchild of JetBrains), Android Studio, Eclipse, and NetBeans. It can be used for most kind of apps, be it server-side, client-side web or Android.
Kotlin/Native, that is currently in the pipeline, will provide support for other platforms such as embedded systems, macOS, and iOS.
Java to Kotlin story
Although Kotlin v1.0 was released only on February 15, 2016, the history of this programming language dates back to 2011. Kotlin was created by JetBrains out of their practical needs. The company had 70% of its products build on Java but started to realize its shortcomings - mainly excessive verbosity. They wanted a language that would be Java-compatible since rewriting everything into a completely new language seemed a no-go option. They started experimenting with Scala but were not satisfied. That is when the concept of a new language, Kotlin, was born.
Another motivation behind Kotlin is fairly straightforward:
"We expect Kotlin to drive the sales of IntelliJ IDEA," Dmitry Jemerov, one of the Kotlin blog contributors, confessed.
Java vs Kotlin: Market situation
The influence of Java on the development world is huge, which is backed up by the reputable Tiobe Index. As of June 2018, Java has maintained its number one spot compared to June 2017. Kotlin, though still a young language, has made it to the top 50 of the rankings, setting down at number 49.
Google I/O 2017 conference was marked by the promotion of Kotlin to the ranks of its “first class” programming languages for Android app development. It joined there the good old Java and C++. The announcement has fueled up the interest over Kotlin, causing the spectacular growth in its popularity.
"Android developers have an official guarantee that the language will be supported, which will lead to further adoption of Kotlin," Andrey Breslav, the lead language designer of Kotlin at JetBrains, explains.
Square, Pinterest, Basecamp, Netflix, Amazon, Uber, Trello, and Twitter have already declared their conversion to Kotlin.
AppBrain offers the following numbers for the share of Kotlin apps in Google Play as of June 11, 2018.
According to the Realm report, Kotlin has every chance to overtake Java already by the end of December 2018.
Java vs Kotlin: Painless transition
There may be certain features for which you’d prefer Kotlin or some, where Java seems a better option and it’s ok. Since both Kotlin and Java codes compile to JVM bytecode, end users will not be able to tell where the one ends and the other continues.
"One of the key focuses of Kotlin has been interoperability and seamless support for mixed Java+Kotlin projects," writes Andrey Breslav in his blog post.
Java vs Kotlin: Verbosity
The verbosity of Java has long been its major shortcoming and a source of frustration for the developers. Kotlin is designed to reduce the number of boilerplate code one needs to write.
Kotlin conciseness helps to increase a cut in the lines of code by approximately 40 %, according to JetBrains. Real tests show that after converting “App Lock” app from Java into Kotlin, the number of code lines reduces by 30% (from 12,371 lines of Java, to 8,564 lines of Kotlin).
Kotlin also provides a heap of nice-to-use features that Java does not have, like:
- Extensions, that help to extend a class functionality;
- Coroutines, aimed at avoiding thread blocking, thus minimizing the risk of errors;
- Null-safety, that ensures no null references occur, thus reducing the risk of an app going faulty
As a result, a more robust and safe code can be written with fewer efforts. The time needed for the amount of the output generation and bugs fixing cuts down.
Rob Fletcher, a senior software developer at Netflix, wrote: "Kotlin isn't revolutionary (with the possible exception of its null-handling) but feels like a very careful amalgamation of some of the best features of other languages. Its approach is very pragmatic and emphasizes interoperability with Java and a lack of surprise."
Java vs Kotlin: Android Studio 3.0 Support
Java implementation in Android ecosystem seems to lag behind the demands of the developers’ community. Though the latest version of Java is SE 10, Android Studio 3.0 and later supports Java 7 and only some of Java 8 features. Thus, developers that are denied the opportunity to embrace the full potential of the latest versions are starting to shift more towards Kotlin.
Bearing in mind that Android Studio is based on the JetBrains’ IntelliJ IDEA, it is easy to predict its excellent support for Kotlin.
"For Android developers, Kotlin support is a chance to use a modern and powerful language, helping solve common headaches such as runtime exceptions and source code verbosity," Maxim Shafirov, JetBrains’ CEO, commented in his blog post.
Java vs Kotlin: Adoption Costs
Kotlin is open source, thus you can bring it into play for free. You can start exploring the language simply by translating it via Java-to-Kotlin converter. Kotlin is compatible with all Java libraries and frameworks, even those that rely on annotation processing. It also perfectly integrates into building tools like Gradle, Maven, Ant, or Kobalt. All you need is to install a Kotlin plugin.
"Kotlin is easy to get started with and can be gradually introduced into existing projects, which means that your existing skills and technology investments are preserved," JetBrains' CEO Maxim Shafirov wrote.
However, though similar, at their core Java and Kotlin are two different languages. The latter is currently a new language, that means that there is no established equivalent to the sources like Effective Java for best programming practices. So there will be a learning curve for your in-house team to master the Kotlin tricks.
Java vs Kotlin: Community support
Java is a programming player with more than 2 decades of history. It naturally leads to the unfathomable number of Java projects implemented and an impressive community it gathered. At the time of writing, there were 801,248 repository results for "Java" query at GitHub.
The larger the community is, the more likely that someone has already left tips on the issue you are searching for. This, in its turn, makes the development process in a language more easy and enjoyable.
Despite the fact Kotlin is gaining more and more traction, its community is still small compared to Java’s. GitHub gave us only 33,182 "Kotlin" tagged results.
Therefore, there are few tools to pump up the skills and not so many Kotlin experts to ask (at the time of writing there were 361 job results for "Android Kotlin Developer" www.indeed.com compared to only 2 resumes).
Java vs Kotlin: Performance & compile time
JetBrains claims that a Kotlin application runs as fast as an equivalent Java one, thanks to very similar bytecode structure. Yet, Kotlin's support for inline functions allows a code using lambdas to run even faster than the same code written in Java.
The tests conducted show that Java compiles 10-15 % faster for clean builds. However, for incremental compilation, Kotlin shows identical to Java or even slightly better results. Decreased compile time means less unproductive time for a developer.
Kotlin is not a complete revolution, but rather a pragmatic enhancement of Java. They resemble each other in structure and can peacefully coexist within one project. But because Kotlin is a fresh start to some extent, it adds a variety of state-of-the-art features. Java, however, is like a friend that stood the test of time.