Kotlin VS Java

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

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.

What is Web3j?

Small review of lightweight Java and Android library for integration with Ethereum clients
15 December 2017   833

What is webj3?

web3j is a lightweight, highly modular, reactive, type safe Java and Android library for working with Smart Contracts and integrating with clients (nodes) on the Ethereum network:

web3j architecture
Web3j Architecture

This allows you to work with the Ethereum blockchain, without the additional overhead of having to write your own integration code for the platform.

According to the developers, these are the features:

  • Complete implementation of Ethereum's JSON-RPC client API over HTTP and IPC
  • Ethereum wallet support
  • Auto-generation of Java smart contract wrappers to create, deploy, transact with and call smart contracts from native Java code (Solidity and Truffle definition formats supported)
  • Reactive-functional API for working with filters
  • Ethereum Name Service (ENS) support
  • Support for Parity's Personal, and Geth's Personal client APIs
  • Support for Infura, so you don't have to run an Ethereum client yourself
  • Comprehensive integration tests demonstrating a number of the above scenarios
  • Command line tools
  • Android compatible
  • Support for JP Morgan's Quorum via web3j-quorum

It has five runtime dependencies:

  • RxJava for its reactive-functional API
  • OKHttp for HTTP connections
  • Jackson Core for fast JSON serialisation/deserialisation
  • Bouncy Castle (Spongy Castle on Android) for crypto
  • Jnr-unixsocket for *nix IPC (not available on Android)

It also uses JavaPoet for generating smart contract wrappers.

Lear more at GitHub.