Skip to main content
main-content
Top

About this book

Explore the new Java 9 modules, SDK, JDK, JVM, JShell and more in this comprehensive book that covers what’s new in Java 9 and how to use these new features. Java 9 Revealed is for experienced Java programmers looking to migrate to Java 9. Author Kishori Sharan begins by covering how to develop Java applications using the new module system introduced in Java 9 and how to use the JShell tool in Java 9 for prototyping, compiling and testing.
The book provides extensive coverage of new Java 9 features, such as the new layout of the modular JDK/JRE runtime image, new convenience factory methods for creating collections, the new spin-wait hints introduced to improve performance of spin loops in your code, and the new Desktop API for implementing platform-specific desktop features. Along the way you will also learn how to use the Reactive Streams API in Java 9 and, most importantly, this book will show you the breaking changes in Java 9.

What You'll LearnHow JShell facilitates rapid development, code evaluation, and testingDiscover what is new in the Process APIInspect a thread’s stack with the Stack-Walking APIUse the jlink tool to create a custom runtime imageWork with HTML5 Javadoc and use the new search feature in JavadocLearn how to use new methods and collectors in the Streams APILearn how to create a custom logger to log messages from platform classes and how to use JVM logsLearn about new methods in the Optional class and how to use themLearn how to compare arrays and slices of arraysLearn how to use the enhanced try-with-resources blocksMake your object deserialization more secure by using object deserialization filters

Who This Book Is For
Experienced Java programmers and developers.

Table of Contents

Chapter 1. Introduction

In this chapter, you will learn:
Kishori Sharan

Chapter 2. The Module System

This chapter is meant to give you a brief conceptual overview of the module system introduced in JDK 9. Subsequent chapters cover all these concepts in detail, with examples. Don’t worry if you do not understand all module-related concepts the first time. Once you gain experience developing modular code, you can come back and re-read this chapter.
Kishori Sharan

Chapter 3. Creating Your First Module

In this chapter, I explain how to work with a module—from writing the source code to compiling, packaging, and running the program. This chapter is divided into two parts. The first part shows you all the steps to write and run a module program using the command line. The second part repeats the same steps using the NetBeans IDE.
Kishori Sharan

Chapter 4. Module Dependency

The example code in this chapter goes through several steps. The source code for this book contains the code used in the final step. If you want to see those examples in action at every step as you read through this chapter, you need to modify the source code a bit to keep it in sync with the step you are working on.
Kishori Sharan

Chapter 5. Implementing Services

In this chapter, you will learn:
Kishori Sharan

Chapter 6. Packaging Modules

In this chapter, you will learn:
Kishori Sharan

Chapter 7. Creating Custom Runtime Images

Before JDK 9, Java runtime image was available as a huge monolithic artifact—thus increasing the download time, startup time, and the memory footprint. The monolithic JRE made it impossible to use Java on devices with small memory. If you deploy your Java applications to a cloud, you pay for the memory you use; most often, the monolithic JRE uses more memory than required, thus making you pay more for the cloud service. The Compact profiles introduced in Java 8 took a step forward to reduce the JRE size—hence the runtime memory footprint—by allowing you to package a subset of the JRE in a custom runtime image called a compact profile.
Kishori Sharan

Chapter 8. Breaking Changes in JDK 9

Before JDK 9, the JDK versioning scheme was not intuitive to developers and was not easy for programs to parse. Looking at the two JDK versions, you could not tell the subtle differences between them. It was hard to answer a simple question: Which release contains the most recent security fixes, JDK 7 Update 55 or JDK 7 Update 60? The answer was not the obvious one, which you may have guessed—JDK 7 Update 60. Both releases contain the same security fixes. What is the difference between the JDK 8 Update 66, 1.8.0_66, and JDK 8u66 releases? They represent the same release. It was necessary to understand the versioning scheme in detail before you could understand the details contained in the version string. JDK 9 attempts to standardize the JDK versioning scheme, so it can be easily understood by humans, easily parsed by programs, and follows the industry-standard versioning scheme.
Kishori Sharan

Chapter 9. Breaking Module Encapsulation

One of the main goals of JDK 9 is to encapsulate types and resources in modules and export only those packages whose public types are intended to be accessed by other modules. Sometimes, you may need to break the encapsulation specified by a module to enable white-box testing or use unsupported JDK-internal APIs or libraries. This is possible by using non-standard command-line options at compile-time and runtime. Another reason for having these options is backward compatibility. Not all existing applications will be fully migrated to JDK 9 and will be modularized. If those applications need to use the JDK APIs or APIs provided by libraries that used to be public, but have been encapsulated in JDK 9, those applications have a way to keep working. A few of these options have corresponding attributes that can be added to the MANIFEST.MF file of the executable JARs to avoid using the command-line options.
Kishori Sharan

Chapter 10. The Module API

The Module API consists of classes and interfaces that give you programmatic access to modules. Using the API, you can programmatically.
Kishori Sharan

Chapter 11. The Java Shell

The Java shell, which is called JShell in JDK 9, is a command-line tool that provides an interactive way to access the Java programming language. It lets you evaluate snippets of Java code instead of forcing you to write an entire Java program. It is a REPL (Read-Eval-Print loop) for Java. JShell is also an API that you can use to develop an application to provide the same functionality as the JShell command-line tool.
Kishori Sharan

Chapter 12. Process API Updates

The Process API consists of classes and interfaces that let you work with native processes.
Kishori Sharan

Chapter 13. Collection API Updates

How unmodifiable lists, sets, and maps were created before JDK 9 and what were the problems in using them.
Kishori Sharan

Chapter 14. The HTTP/2 Client API

JDK 9 delivered the HTTP/2 Client API as an incubator module named jdk.incubator.httpclient. The module exports a jdk.incubator.http package that contains all public APIs. An incubator module is not part of the Java SE. In Java SE 10, either it will be standardized and become part of Java SE 10 or it will be removed. Refer to the web page at http://openjdk.java.net/jeps/11 to learn more about incubator modules in JDK.
Kishori Sharan

Chapter 15. Enhanced Deprecation

In this chapter, you will learn:
Kishori Sharan

Chapter 16. Stack Walking

In this chapter, you will learn:
Kishori Sharan

Chapter 17. Reactive Streams

In this chapter, you will learn:
Kishori Sharan

Chapter 18. Streams API Updates

In this chapter, you will learn:
Kishori Sharan

Chapter 19. Platform and JVM Logging

In this chapter, you will learn:
Kishori Sharan

Chapter 20. Other Changes in JDK 9

In this chapter, you will learn:
Kishori Sharan

Erratum to: Java 9 Revealed: For Early Adoption and Migration

Kishori Sharan
Additional information