Kotlin VS Java

Language comparison: is it worth to move from Java to Kotlin?
18 August 2017   4928

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 Java vs Kotlin code

Compatibility

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.

Syntax

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.
In Kotlin:

  • 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.

Additional Features

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.

Error protection

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.

Expansion Capabilities

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.

The Conclusion

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 technology do you choose, Kotlin or Java?

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.

Kotlin
52% (50 votes)
Java
48% (47 votes)
Total votes: 97

New Vulnerability to be Found in Google+

Due to this vulnerability it was possible to obtain private information of 52.5 million accounts
11 December 2018   65

Google decided to close the social network Google+ not in August 2019, but in April. The reason was another vulnerability in the API, due to which it was possible to obtain private information of 52.5 million accounts. The company plans to close the social network API until mid-March 2019.

By December 10, 2018, the following error information was published:

  • Third-party applications requesting access to profile data, because of the bug in the API, received permission to view information, even if it is hidden by privacy settings;
  • the names of users, their email addresses, information about occupation, age and other confidential information were at risk;
  • passwords, financial data and national identification numbers have not been compromised;
  • the company has no evidence that anyone has exploited the vulnerability;
  • the error was fixed within 6 days: from November 7 to November 13, 2018.
  • Google said it sends notifications to all users affected by the bug.

The previous data leak of Google+ users occurred in October 2018. Then about 500 thousand accounts were compromised. The attackers could get the names, email addresses, age, gender and occupation of users.