Java is a language that has become one of the standards for business. Thanks to its multifunctionality, backward compatibility of versions and cross-platform software it is suitable for almost any task, such as the development of large portals and online stores, the creation of mobile applications, the work with corporate programs.
However, every coin has two sides. Thus, here 's a negative side to enterprise-oriented Java: the need to support all the existing projects at the time of the release of new versions seriously hinders the development of the language. You also have to wait for the appearance of plenty of important possibilities like first-order functions for years.
The JetBrains company was not happy with such state of affairs, so they introduced their own JVM-compatible language - Kotlin, - back in 2011. Let's find out what are its disadvantages and advantages in comparison with his "parent".
Java vs Kotlin code
Moving from Java to another language is always a problem, often insoluble, especially when it comes to a large and old projec, as it is almost impossible to rewrite it entirely at a go. That's why Kotlin can be built into any existing Java code. This will allow the user to immediately continue to work on the project on Kotlin, step by step rewriting its old Java-parts.
The main task that JetBrains set for itself was to simplify the language and to finally solve some problems that caused discomfort even to experienced Java programmers.
- The declaration of the variables and the creation of objects are simplified.
- There's no need to explicitly specify a type for the variables.
- There's a support for string templates that allow you to use dynamic data and method calls right inside the line.
- There's a set of tools that simplify and accelerate the writing of code for Android-applications. For example, you can access all the views with a unique ID in XML markup by adding just one line in the import section.
Kotlin uses several additional features that speed and simplify the process of writing code and give the developer a greater arsenal of the programming tools:
- Lambda functions that reduce the amount of code that needs to be written several times.
- Higher-order functions that allow taking functions as an argument and return the new functions.
- Operator overloading that simplifies the call of the functions and allows using several variants of using operators with the same names in one scope.
Kotlin in general is focused on functional programming, thus, it is likely that there will be the support for other functions in the future.
Speed of work
The tests conducted usually show that the first assembly of the project on Kotlin is 10-20% slower than the similar on Java. However, this type of compilation is rarely used, while when carrying out more popular incremental assemblies, Kotlin as a whole shows no less speed than its "parent" and in some cases even slightly exceeds it. Therefore, it can be said that this language is not slower than Java.
The emergence of the NullPointerException error disturbed even experienced Java developers and made it take a long time to figure out the reasons for the error and fix them. In Kotlin, the null and non-null types are additionally used, so it is impossible to write null and perform the operations leading to NPEs.
Kotlin is quite flexible and allows the programmer to add features missing specially to him without any special problems. To do this, the extension functions are used. Thus, you simply need to specify the prefix of the extensible type and apply the resulting function to any list. There's a possibility to add new features to both your own classes and the standard ones.
Documentation and the Community
On the Java's side there are several decades of active use and many implemented projects including quite complex enterprise applications. The low rate of the changes'occurrence also makes numerous solutions published in the community two or three years ago still relevant.
Kotlin can't boast of such an amount of available information, however, JetBrains documentation is quite well-developed, while the orientation to business structures increases both the number of programmers working with the language and its popularity in the thematic communities.
In favour of Kotlin:
- Rapid development and the emergence of new features that can not be implemented in Java.
- Simplifying of the code writing.
- Functional programming orientation.
- Excellent extensibility.
- Protection against NullPointerException.
In favour of Java:
- A widely recognized standard in the development of enterprise applications.
- A large fully formed community.
- Slow development saves the developers from "race for technology".
- Plenty of specialists mastered the language.
What programming language do you prefer? Kotlin or Java? Or maybe you are already using some of them? Please, share your thoughts with the community. Also, after the voting, you will be able to see what people like the most. Your opinion is very valuable for the Hype.Codes team.