In this chapter,we will explore the newly implemented, time-based versioning system for the Java platform. We will surveyÂ the current Java landscape with a specific focus onÂ changes introduced with Java 9, 10 (18.3), and 11 (18.9). Our exploration will include an overview of Java 9's modularity,Â Java Shell, external process control, garbage collection, Java Microbenchmark Harness (JMH), and more. For Java 10, we willÂ highlightÂ key changes to include local variable type inference,Â Java Development Kit (JDK) consolidation, garbage collection, application class-data sharing (CDS), root certificates, and more. Finally, we will explore changes introduced in Java 11, including dynamic class-file constants, garbage collection, local variable type inference for Lambdas, and more.
Things we will learn by the end of this chapter include:
- Understanding the Java platform's new versioning model
- Understanding the significance of Java 9
- Benefiting from changes introduced with Java 10Â
- Benefiting from changes introduced withÂ Java 11Â
This chapter and subsequent chapters feature Java 11.Â The Standard Edition (SE) of the Java platform can be downloaded from Oracle's official download site (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
AnÂ integrated development environment (IDE) software package is sufficient. IntelliJ IDEA, from JetBrains, was used for all coding associated with this chapter and subsequent chapters. The Community version of IntelliJ IDEA can be downloaded from the site (https://www.jetbrains.com/idea/features/).
The first version of Java was released as Java 1 in 1996. Since then, there have been several incremental releases, each of which followed a feature-driven release model. Starting with Java 10, Oracle has implemented a new, time-based release model. In this section, we will look at the original model to provide a foundation to show how the Java platform evolved, and look at the new versioning model and why it matters.
Following the 1996 launch of Java 1, subsequent releases had the nomenclature of 1.1, 1.2, 1.3, and 1.4. With the release of 1.5, the Java platform was referred to as Java 5. Frequent updates were released for Java 5 until Java 6 was released followed by Java 7, Java 8, and Java 9.Â
The following table provides a condensed view of the Java release history until Java 9:
(Abigail, Brutus, Chelsea)
*Code names no longer used
The release of Java 9 was a significant change to the Java platform and how each of the versions was numbered. With the post-Java 9 releases, Oracle decided to abandon their feature-based model, opting for a time-released model instead.Â
Java 9 was released in 2017 and two releases were scheduled for 2018. Those releases were Java 10 and Java 11. The version numbers for these post-Java 9 releases followed the YY.M format. So, with Java 10 released in March 2018, the version number was 18.3. Java 11, released in September 2018, has a version number of 18.9.
- Feature releases: Issued every six months (each March and September)
- Update releases: Issued every quarter
- Long-term support release: Issued every three years
There are great gains to be had, from a developer's perspective, with this model. Developers no longer need to wait long for releases to the Java platform. More significant is the fact that no release will represent a major change to the platform of the kind that Java 9 was.
Unarguably, the modularization of the Java platform, developed as part of Project Jigsaw, wasÂ the greatest change introduced to the Java platform with Java 9. Initially planned for Java 8,Â but postponed, Project Jigsaw was one of the main reasons why the final release of Java 9Â was itself postponed. Jigsaw also introduced a few notable changes to the Java platformÂ and was one of the reasons Java 9 was considered a major release. We will explore these featuresÂ in detail in subsequent chapters.
Apart from the Jigsaw-related Java enhancement proposals, there is a long listÂ of other enhancements that made it in Java 9. This section explores the mostÂ significant features introduced in Java 9, specifically:
- Breaking the monolith
- Using the Java Shell
- Taking control of external processes
- Boosting performance with G1
- Measuring performance withÂ Java Microbenchmark Harness (JMH)
- Getting ready for HTTP 2.0
- Encompassing reactive programming
Over the years, the utilities of the Java platform have continued to evolve and increase,Â making it into one big monolith. In order to make the platform more suitable for embedded andÂ mobile devices, the publication of stripped-down editions, such as Java Connected Device Configuration (CDC) and JavaÂ Micro Edition (ME), was necessary. These, however, did not prove to be flexible enough for modern applicationsÂ with varying requirements in terms of the functionality provided by the JDK. In that regard, theÂ need for a modular system came in as a vital requirement, not only to address the modularization of the Java utilities (overall, there are more than 5,000 Java classes and 1,500 C++Â source files with more than 250,000 lines of code for the HotSpot runtime), but also toÂ provide a mechanism for developers to create and manage modular applications using theÂ same module system as that used in the JDK. Java 8 provided an intermediate mechanism toÂ enable applications to use only a subset of the APIs provided by the entire JDK, and thatÂ mechanism was named compact profiles. In fact, compact profiles also provided the basisÂ for further work that had to be done in order to break dependencies between the variousÂ distinct components of the JDK. This breaking of dependencies was required to enable the implementation of a module system inÂ Java.
The module system itself was developed under the name of Project Jigsaw, on the basisÂ of which several Java enhancement proposals and a targetÂ Java Specification Request (JSR 376) were formed. A complete restructuring of the JDK code base was made, along with a complete reorganization of the JDK distributable images.
There was considerable controversy in the community as to whether an existing and matureÂ Java module system, such as OSGi, should be adopted as part of the JDK, instead ofÂ providing a completely new module system. However, OSGi targets runtime behavior, suchÂ as the resolution of module dependencies, installation, uninstallation, starting and stoppingÂ of modules (also named bundles in terms of OSGi), custom module classloaders, and so on.Â
OSGi refers to the OSGi Alliance, formally known as theÂ Open Services Gateway Initiative. OSGi is an open standard for a Java platform modular system.
Project Jigsaw, however, targets a compile-time module system where the resolution ofÂ dependencies happens when the application is compiled. Moreover, installing andÂ uninstalling a module as part of the JDK eliminates the need toÂ include itÂ explicitly as a dependency during compilation. Furthermore, the loading of module classes is made possibleÂ through the existing hierarchy of classloaders (the bootstrap, and the extension and systemÂ classloaders).
Additional benefits from the Java module system include enhanced security andÂ performance. By modularizing the JDK and applications into Jigsaw modules, developers are ableÂ to create well-defined boundaries between components and their corresponding domains.Â This separation of concerns aligns with the security architecture of the platform and is anÂ enabler of better resource utilization.Â
For a long time, there has been no standard shell shipped with the Java programmingÂ language to experiment with new language features or libraries, or for rapid prototyping. IfÂ you wanted to do this, you could write a test application with a
main()Â method, compile itÂ with
javac, and run it. This could be done either in the command line or using a Java IDE;Â however, in both cases, this is not as convenient as having an interactive shell for theÂ purpose.
Starting an interactive shell in JDK 9 is as simple as running the following commandÂ (assuming the
bin directory of your JDK 9 installation is in the current path):
You may find it somewhat puzzling that an interactive shell has not been introduced earlierÂ in the Java platform, as many programming languages, such as Python, Ruby, and a numberÂ of others, already come with an interactive shell in their earliest versions. However, this didn't make it on the priority features list until Java 9. The Java Shell makes use of a JShell API that providesÂ capabilities to enable autocompletion or evaluation of expressions and code snippets,Â among other features. Chapter 6,Â Experimenting with the Java Shell, is dedicated to discussing the details of the Java ShellÂ so that developers can make the best use of it.
Runtime.getRuntime.exec()method, which allows us to execute aÂ command in a separate OS process. Using this approach would require you to get a
java.lang.Processinstance over which toÂ provide certain operations in order to manage the external process.
- The newÂ
java.lang.ProcessBuilderclass, which has some more enhancements withÂ regard to interactingÂ with the external process. You would also need to create a
java.lang.Processinstance to represent theÂ external process.
Both approaches were inflexible and also nonportable, as the set ofÂ commands executed by the external processes were highly dependent on the operatingÂ system. An additional effort had to be exerted in order to make the particular processÂ operations portable across multiple operating systems. Chapter 9, Making Use of the Process API, is dedicated to the newÂ process API, providing developers with the knowledge to create and manage externalÂ processes in a much easier way.
The G1 garbage collector was already introduced in JDK 7 and is now enabled by default inÂ JDK 9. It is targeted for systems with multiple processing cores and a lot of availableÂ memory. What are the benefits of the G1 compared to previous types of garbage collectors?Â How does it achieve these improvements? Is there a need to tune it manually, and in whatÂ scenarios? These and several more questions regarding G1 will be discussed in Chapter 7, Leveraging the Default G1 Garbage Collector.
On many occasions, Java applications may suffer from performance degradation.Â Exacerbating the issue is a lack of performance tests that can provide at least a minimal setÂ of guarantees that performance requirements are met and, moreover, the performance ofÂ certain features will not degrade over time. Measuring the performance of Java applications isÂ not trivial, especially due to the fact that there are a number of compiler and runtimeÂ optimizations that may affect performance statistics. For that reason, additional measures, such as warm-up phases and other tricks, must be used in order to provide more accurateÂ performance measurements. The JMH is a framework thatÂ incorporates a number of techniques, along with a convenient API that can be used for thisÂ purpose. It is not a new tool but was included with the distribution of Java 9. If you have notÂ added JMH to your toolbox yet, read Chapter 8, Microbenchmarking Applications with JMH, to learn about the use of JMH in theÂ context of Java application development.
HTTP 2.0 is the successor to the HTTP 1.1 protocol, and this new version of the protocolÂ addresses some limitations and drawbacks of the previous one. HTTP 2.0 improvesÂ performance in several ways and provides capabilities such as request/responseÂ multiplexing in a single TCP connection, sending of responses in a server push, flowÂ control, and request prioritization, among others.Â Java provides the
java.net.HttpURLConnection utility that can be used to establish aÂ nonsecure HTTP 1.1 connection. However, the API was considered difficult to maintain, an issue which was further complicated by the need to support HTTP 2.0 and, so, an entirely new client API wasÂ introduced in order to establish a connection via the HTTP 2.0 or the web socket protocols.Â The HTTP 2.0 client, along with the capabilities it provides, will be covered in Chapter 11, New Tools and Tool Enhancements.
Reactive programming is a paradigm used to describe a certain pattern for the propagation ofÂ changes in a system. Reactiveness is not built in Java itself, but reactive data flows can beÂ established using third-party libraries, such as RxJava or Project Reactor (part of the SpringÂ Framework). JDK 9 also addressed the need for an API that aids the development of highly responsiveÂ applications built around the idea of reactive streams by providing theÂ
java.util.concurrent.Flow class for the purpose. The
Flow class, along with otherÂ related changes introduced in JDK 9, will be covered in Chapter 12,Â Concurrency Enhancements.
- Local variable type inference
- Consolidation of the JDK forest into a single repository
- Garbage collection interface
- Parallel full garbage collector for G1
- Application class-data sharing
- Thread-local handshakes
- Removal of the native-header generation tool (javah)
- Additional Unicode language-tag extensions
- Heap allocation on alternative memory devices
- Experimental Java-based JIT compiler
- Root certificates
A brief overview of these features is covered in this chapter, with more detailed coverage in subsequent chapters.
Starting with Java 10, declaring local variables has been simplified. Developers no longer have to include manifest declarations of local variable types. This is accomplished using the new
var identifier, as shown in this example:
var myList = new ArrayList<String>();
Using the preceding code,
ArrayList<String> is inferred, so we no longer need to use
ArrayList<String> myList = new ArrayList<String>();.Â
Local variable type inference is covered in Chapter 3,Java 11 Fundamentals.Â
Prior to Java 10, there were eight repositories for the JDK (CORBA, HotSpot, JDK, JAXP, JAX-WS, langtools, Nashorn, and ROOT). With Java 10, these repositories have been consolidated into a single code base. Notably, Java FX was not part of this consolidation. This topic will be explained further in Chapter 2, Discovering Java 11.
Java 10 ushered in enhancements to the garbage collection process. A new garbage collector interface results in improvements that will be detailed in Chapter 7, Leveraging the Default G1 Garbage Collector.Â
In Java 10, the G1 full garbage collector was made parallel. Starting with Java 9, G1 was made the default garbage collector, so this change was of special significance. This change will be detailed in Chapter 7, Leveraging the Default G1 Garbage Collector.Â
Class-data sharing (CDS) has been extended to support faster application startup and smaller footprints. Using CDS, developers can have specific class files pre-parsed and stored in a shareable archive. We will explore this change to the Java platformÂ in Chapter 2,Discovering Java 11.
With Java 10 and beyond, it is possible to stop individual threads without having to perform a global virtual machine safepoint. We will fully explore this change in Chapter 3,Java 11 Fundamentals.Â
A concerted effort was undertaken to remove the javah tool from the JDK. This change was warranted because of the functionality available in
javac. We will detail this changeÂ in Chapter 11,New Tools and Tool Enhancements.
The Java platform has supported language tags since Java 7. In Java 10, changes were made to
java.util.Local and related APIs to incorporate additional Unicode language tags. Details will be coveredÂ in Chapter 2,Discovering Java 11.
The HotSpot virtual machine, as of Java 10, supports non-DRAM memory devices. This will be explainedÂ in Chapter 3,Java 11 Fundamentals.Â
Java 9 introduced us to a Java-based just-in-time (JIT) compiler. This JIT compiler has been enabled for Linux/x64 platforms. This experimental compiler will be further exploredÂ in Chapter 14,Command-Line Flags.
Starting with the release of Java 10, there hasÂ been a default set of Certification Authority (CA) certificates as part of the JDK. This change and its benefits will beÂ coveredÂ in Chapter 3, Java 11 Fundamentals.Â
- Dynamic class-file constants
- Epsilonâan arbitrarily low-overhead garbage collector
- Removal of the Java EE and CORBA modules
- Local variable syntax for Lambda parameters
A brief overview of these features is covered in this chapter, with more detailed coverage in subsequent chapters.
In Java 11, the file format for Java class files was extended to support
CONSTANT_Dynamic, which delegates creation to a bootstrap method. This change will be fully exploredÂ in Chapter 3,Java 11 Fundamentals.Â
Garbage collection enhancements are seemingly part of every Java platform release. Java 11, includes a passive garbage collector that does not reclaim memory. We will explore thisÂ in Chapter 7,Leveraging the Default G1 Garbage Collector.Â
The Java Enterprise Edition (JavaEE) and Common Object Request Broker Architecture (CORBA) modules were depreciated in Java 9 and have been removed from the Java platform as of Java 11. Details are providedÂ in Chapter 3,Java 11 Fundamentals.Â
As discussed earlier in this chapter, the
var identifier was introduced in Java 10. With the latest version, Java 11,
var can be used in implicitly typed Lambda expressions. This use of the
var identifierÂ is covered in Chapter 3,Java 11 Fundamentals.Â
In this chapter, we explored the newly implemented, time-based versioning system for the Java platform. We also learned, at a high level, the changes introduced in Java 9, 10, and 11 (referred to as versions 9, 18.3, and 18.9 respectively). Java 9's most significant change was modularity based on Project Jigsaw and included additional changes focusing on the Java shell, controlling external process, garbage collection, JHM, and more. Key features of Java 10 were covered, including local variable type inference, JDK consolidation, garbage collection, application CDS, root certificates, and more. Changes introduced in Java 11 included dynamic class-file constants, garbage collection, local variable type inference for Lambdas, and more.
In the next chapter, we will look at several internal changes introduced in the Java platform, including changes from Java 9, 10, and 11.
- What will the first Java version be in 2019?
- What is a key benefit of the new Java time-based release model?Â
- What was the most significant change to the Java platform with JDK 9?
- What was removed with Java 11: CORBA, Lambda, or G1?
- Does CDS support faster startup or more efficient garbage collection?
- What is Epsilon?
vara datatype, identifier, reserved word, or keyword?
- Which Java release introduced root certificates to the Java platform?
- Which release included enhancements to garbage collection?
- What is the default garbage collector in Java?
This survey chapter took a broad-brush approach to recent changes to the Java platform. If any of the concepts were unfamiliar to you, consider brushing up on your Java knowledge with one or more of the following resources:
- Java: Object-Oriented Programming Concepts [Integrated Course], available atÂ https://www.packtpub.com/application-development/java-object-oriented-programming-concepts-integrated-course.
- Java 9 High Performance, available at https://www.packtpub.com/application-development/java-9-high-performance.