Java becomes obsolete due to Kotlin

Kotlin vs. Java - what is suitable for what?

Key facts at a glance

  • Kotlin saves on lines of code, but not on legibility.
  • Thanks to Kotlin, getters and setters are moved to the compiler.
  • NullPointerExceptions are also almost eliminated.
  • The compiled Kotlin code is highly compatible.

What exactly is Kotlin?

Kotlin is developed by the company JetBrains, which also produces the intelligent Java IDE IntelliJ IDEA and the JavaScript IDE Webstorm. This makes Kotlin a cross-platform,statically typed programming languagethat can be converted into Java, JavaScript and machine code. She is thereforevery diverse and can be easily integrated into many projects. The integration is completewithout compatibility problems and also doesn't need any Interface programming.

Compatibility with Java

A big advantage is that the codecompatible with Java is. As an example: A code that is created with Kotlin can be addressed from Java classes. Can the other way aroundJava classes alsoin Kotlin be used. Many existing Java projects can gradually be rewritten in Kotlin without any losses. In this way, you can supplement existing projects with currently secure code without having to change the rest.

Kotlin offers the same performance with less code

Another advantage of Kotlin is thatAvoided a lot of boilerplate code becomes. Often it is part of good programming style, but it bloats the code unnecessarily. With Kotlin, simple tasks that require almost 100 lines of code in Java can be reduced to less than ten percent. In doing so, neither the readability nor the functionality is impaired. Although this is an extreme example, the Java code can usually be avoidedCut 20 to 30 percent.

💡 Good to know: Less code means fewer and fewer possible bugs,less bug fixing and complete projects faster. This not only saves nerves, but also time and money.

NullException checking is no longer necessary

To avoid program crashes, Java must first accessevery variable be checked whether the valuezero amounts. It looks like this:

These calculation steps can theoretically be avoided. In Kotlin it is possible to report directly whether an attributenullableis. When adefault value is set, this check is omitted:

Of course, a zero value can also be allowed, the corresponding test then looks like this:

If a zero value should now appear, is the result of the variablelength also the valuezero. This can be bypassed with the Elvis operator and the assignment of a standard value:

Then no longer has tozero checked and the code becomes shorter. This function is similar to that of Optionalin Java, but gives the option of abbreviation as follows:

instead of

Support for programming Kotlin

In many cases, Kotlin overtakes Java as the standard programming language for Android. thats whyKotlininto the development platformAndroid Studio integratedso you can build and test apps right there.

Since version 5, the Spring framework supports Kotlin without additional plugins. In addition, support for Kotlin is already available in the IntelliJ (Community and Enterprise) and Eclipse development platforms. So Java and Kotlin can be easily connected to each other.

Use as a native programming language is being used more and more

Kotlin is not only at home with Android programming. The tool is now also available as a native programming languageavailable for some widely used systems. Kotlin / Native can currently be used on these operating systems:

  • iOS (arm32, arm64, simulator x86_64)
  • MacOS (x86_64)
  • Android (arm32, arm64)
  • Windows (mingw x86_64, x86)
  • Linux (x86_64, arm32, MIPS, MIPS little endian, Raspberry Pi)
  • WebAssembly (wasm32)

In which cases is Java better suited than Kotlin?

Despite the good support and push from Google, there are still cases whereJava as a programming language does a better job. We have put together the advantages of Java in this overview.

Is Kotlin really the better Java?

Considering all the facts, that could be assumed. Java has long been the top dog when it comes to apps.Java programs run on all platformsthat have a runtime environment. This fact made Java what it is today - one of the most popular programming languages. However, it is also a fact that Java often seems confusing because of its many lines of code in smaller apps and is therefore avoided by many programmers.

The recurring security problems are also slowly causing a decline. SelfOracle recommends meanwhile theUninstalling Javawhen it is not absolutely necessary. Hearing something like this in-house can put off potential programmers. Kotlin will therefore sooner or later replace Java, at least for smaller projects. For larger projects, however, Java is still the better choice.

More articles on the topic:

End of article