
Project Technical Lead
The Java programming language undergoes regular updates that bring various changes. Some are significant, others less so. The list of these can be quite long, so we’ve selected only the most important ones from each version.
Java is one of the most popular programming languages. It is versatile, stable and 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 moving forward, which has made it necessary to move to an agile method of releasing a new version every 6 months.
The first agile version was Java SE 9, which was released in September 2017. Version 10 subsequently appeared after another six months. Other updates started to be released at a similar interval.
Java 11 was according to annual survey by Snyk the most used version in 2021. Up to 61.5% of respondents used it. Only 12% had upgraded to the latest version, which was Java 15 at the time of the survey.
Also interesting were the answers to the question what are the reasons that people have not switched 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 changes because their current environment is working well.
Other reasons why survey participants stick with older versions include:
The 2020 survey, on the other hand, found that the strategy of most developers (55%) is to stick to 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 newly introduced functions are important enough to justify migration.
Each new version brings with it some changes. Some are larger, 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 three most important ones:
The most significant change in the Java 9 environment was the modularity system, which was named the Jigsaw Project. A module is a group of code characterized by certain features. The modularity feature breaks a programming language into smaller models to provide:
To create a new model, you need the module-info.java file in your src.main.java directory. Inside you can define your module requirements.
Another Java 9 feature allows writing 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 its name suggests, it is used to run commands, create variables, classes, methods and allows you to quickly test them. It’s great for testing small snippets of code that would otherwise require creating a new class using the main method.
JShell can be found in the <JAVA_HOME> / binfolder and you can run it by typing jshell in 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, for example, extended support for older versions of Java, 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 eloquence of the tongue. In practice, this means that you can avoid long object names or typing the same name twice.
However, developers may wonder what the difference between var and Object is. The var keyword means that you want the compiler to detect the type itself. On the other hand, you use Object to convert your object instance to the Object type. This means that although you can use the general methods of the Object class, you cannot use its class-specific methods. This will create a compilation error.
Java SE 11 was released six months after version number 10, in September 2018. It brought two major changes:
The major change in this version is that the developers does not need to explicitly compile the ava source files with the javac command.
Instead, it can execute the file directly using the java command.
Java 11 has support for using local variable syntax in lambda parameters. The function can be used to apply modifiers to local variables, for example, to define an annotation.
Version 12 was released in March 2019 and came with only one significant improvement. It was an alternative switch entry. The following example compares the old and new notation of switch. 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 directly assigned a value from a switch statement.
Java 13 was released in September 2019. The update came with two major improvements:
The new text block feature made it easier for developers to read multi-line text. It uses three quotes, similar to Python and Groovy.
In addition, all 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.
In March 2020, Java SE 14 was released and brought up to four major enhancements:
The switch expression, which was introduced as a preview in Java 12 and was improved in version 13, has become a language standard.
NullPointerException hasn’t had much meaningful value in the past. The reason was that it could only detect that a certain value was zero in a given set. However, everything is different in the new version. The function has been extended and developers will finally know which variable caused the exception.
Records were introduced to reduce repetitive standard code in the POJO data models. They simplify day-to-day development, increase efficiency and significantly minimise the risk of human error. For example, a data model for a user with an ID and password can be simply defined as:
In this case, the new record keyword was also used, which automatically adds constructor methods, getters, equals, hashCode and toString.
Version 14 introduced pattern matching 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. Using the keywords sealed, non-sealed and permits , the developer can 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 also specified that the only classes that can extend it are Employee and Manager. Extending a sealed class is done 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 by the compiler.
The goal 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. Classes such as these usually have a short life cycle, so they are designed to be mainly efficient. They are especially 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 has been migrated from Mercurial to Git. The reason was the size of the metadata files, better tools and hosting.
Until March 2022, the latest version of Java 17, which brought 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. However, not all of them are as big and important as the ones we have selected. With them, you not only get cleaner, but also better code and faster and better implementation. If you’d like to see all the news, please take a look at the following resources: