
Java programmer expert
The Java programming language is subject to regular updates that bring various changes. Some are significant, others less so. The list can be quite long, so we have selected only the most important ones from each version.
Java is one of the most widely used programming languages. It is versatile, stable, object-oriented and has a long history. It was first introduced in 1995. Oracle, the company that created it, initially released new major versions every 3-4 years. However, technology is constantly evolving, so it was necessary to move to an agile method of releasing a new version every 6 months.
The first agile version was Java SE 9, released in September 2017. Version 10 followed after a further six months. Other updates have been released at similar intervals.
According to Snyk’s annual survey, Java 11 was the most used version in 2021. Up to 61.5% of respondents were using it. Only 12% had upgraded to the latest version, which at the time of the survey was Java 15.
Also interesting were the responses to the question of why people had not upgraded to a newer version. Most agreed that they were unable or unwilling to migrate Java every 6 months. Others, around 51%, say they do not need to change because their current environment works well.
Other reasons given by respondents for staying with older versions include:
In contrast, the 2020 survey found that the strategy of most developers (55%) is to stick with long-term releases. Despite this, up to 22% of respondents say they plan to decide whether or not to innovate. They want to see if the new features introduced are important enough to justify migration.
Each new version brings with it some changes. Some are bigger, others smaller. We’ve picked out the key changes for you that could be useful to anyone who uses Java.
Java SE 9 was released in September 2017 and brought with it several changes. But not all of them were significant and important. These are the top three:
The most significant change in the Java 9 environment was the modularity system, which was named the Project Jigsaw. A module is a group of code characterized by certain properties. The modularity feature breaks down a programming language into smaller models to:
To create a new model, you need the module-info.java file in your src.main.java directory. In it you can define your module requirements.
Another Java 9 feature is the ability to write private and static methods in interfaces to avoid redundant code.
Oracle has developed a new REPL tool called JShell. REPL stands for Read – Evaluate – Print – Loop. As the name suggests, it is used to execute commands, create variables, classes and methods, and allows you to test them quickly. It’s great for testing small snippets of code that would otherwise require creating a new class with the main method.
JShell can be found in the <JAVA_HOME> / bin folder and you can run it by typing jshell at the command line and start writing code immediately.
Interactive Java jshell comes with history and autocomplete. It also provides features such as saving and loading from files and all or some lines of code:
Java SE 10 was released by Oracle in March 2018. It brought two important changes for developers:
To make the Java community more Java friendly, Oracle has started promoting OpenJDK binaries as the primary JDK for the future. The problem is that if you want to get extended support for older versions of Java, for example, you have to pay for the services.
The var variable is not new, as it exists in other programming languages. Its main advantage is that it reduces the verbosity of the language. In practice, this means using it to avoid long object names or typing the same name twice.
However, developers may wonder what the difference is between var and object. The var keyword means that you want the compiler to determine the type itself. On the other hand, you use Object to convert your object instance to the type Object. This means that although you can use the general methods of the Object class, you cannot use its class-specific methods. This will cause a compilation error.
Java SE 11 was released six months after version number 10, in September 2018. It brought two major changes:
The main change in this version is that developers no longer need to explicitly compile the ava source files using the javac command.
Instead, you can run the file directly with the java command.
Java 11 provides support for using local variable syntax in lambda parameters. This can be used to apply modifiers to local variables, for example to define an annotation.
Version 12 was released in March 2019 and had only one significant improvement. It was an alternative notation for switch. The following example compares the old and new switch notation. The code distinguishes between weekdays and weekends.
The code in the new notation looks much cleaner and shorter. The new switch form also removes the need for break keywords. This means that when the code finds the first match, it stops working. Another difference is that a variable can be assigned a value directly from a switch expression.
Java 13 was released in September 2019. The update came with two major improvements:
The new text block feature makes it easier for developers to read multi-line text. It uses three quotation marks, similar to Python and Groovy.
In addition, all the functions of the String class are available.
Java 13 enhances the switch expression from version 12 with the yield keyword. You can use yield to return values from a switch expression.
Java SE 14 was released in March 2020, bringing up to four major enhancements:
Introduced as a preview in Java 12 and enhanced in version 13, the switch expression has become a language standard.
NullPointerException didn’t have much use in the past. The reason was that it could only detect that a given value in a given set was zero. However, things are different in the new version. The function has been extended and developers will finally know which variable caused the exception.
Records have been introduced to reduce repetitive standard code in POJO data models. They simplify day-to-day development, increase efficiency and significantly reduce the risk of human error. For example, a data model for a user with an ID and password can simply be defined as
In this case, the new record keyword was also used, which automatically adds constructor methods, getters, equals, hashCode and toString.
Pattern matching was introduced in version 14 to simplify the code. Without the new feature the code would look like this:
However, thanks to the new version of Java, the code looks much simpler and shorter:
Java SE 15 was released in September 2020 and brought with it three major updates:
Text blocks, which were introduced as a preview in the Java 13 environment, have become a language standard.
The public, protected and private access modifiers provide very coarse control. The keywords sealed, non-sealed and permits allow the developer to play with the inheritance hierarchy. The goal of sealed classes is to allow individual classes to declare which types can be used as subtypes. This also applies to interfaces and determining which types can implement them.
In this example, we have declared an abstract class called Person. We have also specified that the only classes that can extend it are Employee and Manager. Extending a sealed class is done in the same way as in Java today, using the extends keyword:
Any class that extends a sealed class must itself be declared sealed, non-sealed, or final. This ensures that the class hierarchy remains finite and is known to the compiler.
The purpose of hidden classes is to allow you to create classes that are not visible. This means that they cannot be associated with other classes, nor can they be discovered by reflection. Such classes tend to have a short lifecycle, so they are primarily designed to be efficient. They are particularly useful for developers working with the JVM.
Version 16 was released in March 2021 and brought one major change, which was the migration of OpenJDK to Git. The OpenJDK source code was migrated from Mercurial to Git. This was due to the size of the metadata files, better tools and hosting.
Until March 2022, the latest version of Java 17, which brings a new rendering pipeline for MacOS systems, port support for Apple’s latest M1 chip, and support for sealed classes. There are also language improvements and the removal of ahead-of-time and just-in-time complications.
Individual Java updates have many more new features. But not all of them are as big and important as the ones we have selected. They will not only give you cleaner code, but also better code and faster and better implementation. If you’d like to see all the news, check out the following resources: