Java 11 and 12 - New Features

Book description

Enhance your development skills with Java's state-of-the-art features and projects to make your applications leaner and faster

Key Features

  • Overcome the challenges involved in migrating to new versions of Java
  • Discover how Oracle has bridged the gap between Java and native code
  • Make the best use of new Java features and libraries in your applications

Book Description

With its new six-monthly release cadence, Java is moving forward faster. In addition to planned version releases, a lot of work is currently being undertaken on various Java projects at Oracle. In order to make best use of the new features in their applications and libraries, you must be well-versed with the most recent advancements.

Java 11 and 12 - New Features will take you through the latest developments in Java, right from variable type inference and simplified multithreading through to performance improvements, which are covered in depth to help you make your applications more efficient. This book explains the relevance and applicability of Java's new features, and answers your questions on whether to invest in migrating to new Java versions and when to migrate. You'll also get to grips with platform features, such as AppCDS and new garbage collectors, to tune and optimize your application-from reduced launch time and latency to improved performance and throughput.

By the end of this book, you will be equipped with a thorough understanding of the new features of Java 11, 12, and Project Amber, and possess the skills to apply them with a view to improving your application's performance.

What you will learn

  • Study type interference and how to work with the var type
  • Understand Class-Data Sharing, its benefits, and limitations
  • Discover platform options to reduce your application's launch time
  • Improve application performance by switching garbage collectors
  • Get up to date with the new Java release cadence
  • Define and assess decision criteria for migrating to a new version of Java

Who this book is for

If you're an executive or solutions architect responsible for technology selection or Java migration decisions, this Java book is for you. You'll also benefit from this book if you're a computer science enthusiast curious to learn about the latest and upcoming Java features. This book will help you migrate your solutions from Java 8 or older to the latest Java release.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Java 11 and 12 – New Features
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: JDK 10
  7. Type Inference
    1. What is type inference?
    2. Type inference with var
      1. Compulsory non-null initialization
      2. Local variables
      3. Code check – part 1
      4. Using var with primitive data types
      5. Type inference with derived classes
      6. Type inference with interfaces
      7. Using var with arrays
      8. Type inference with generics
      9. Code check – part 2
      10. Passing inferred variables to a method
      11. Reassigning values to inferred variables
      12. Explicit casting with inferred variables
      13. Assigning null with explicit casting
    3. Type inference in previous versions of Java
      1. Type inference in Java 5
      2. Type inference in Java 7
      3. Type inference in Java 8
    4. Challenges
      1. Limiting the scope of failed assumptions
      2. Breaking existing code
      3. Non-denotable types
      4. Meaningful variable names
      5. Code refactoring
    5. Type inference versus dynamic binding
    6. Summary
  8. AppCDS
    1. Technical requirements
    2. What is CDS?
      1. Location of the shared archive file
      2. Manual creation of classes.jsa
      3. Usage of CDS
    3. AppCDS
      1. Benefits of AppCDS
      2. Enabling application class data archive
      3. Which application classes to archive
      4. Creating an application shared archive file
      5. Using the shared application archive file
    4. Summary
  9. Garbage Collector Optimizations
    1. Technical requirements
    2. The GC interface 
      1. Benefits
      2. Driving factors
      3. Impact
    3. Parallel full GC for G1 (JEP 307)
      1. The design goals of G1 GC
      2. G1 memory
      3. Sample code
      4. Understanding G1 GC logs
    4. Summary
  10. Miscellaneous Improvements in JDK 10
    1. Technical requirements
    2. Mapping JDK 10 features with scopes and JEPs
      1. Consolidating the JDK forest into a single repository
      2. Thread-local handshakes
      3. Removal of the Native-Header Generation Tool (javah)
      4. Additional Unicode language-tag extensions
      5. Heap allocation on alternative memory devices
      6. The experimental Java-based JIT compiler
      7. Root certificates
      8. Time-based release versioning
    3. Summary
  11. Section 2: JDK 11
  12. Local Variable Syntax for Lambda Parameters
    1. Technical requirements
    2. Lambda expressions
      1. Explicitly-typed lambda expressions
      2. Implicitly-typed lambda expressions
    3. Lambda parameters and type inference with var
      1. Adding var to lambda parameters
      2. Adding annotations to lambda parameters
    4. Summary
  13. Epsilon GC
    1. Technical requirements
    2. The motivation behind Epsilon GC
      1. Features of Epsilon
        1. Latency and application performance
          1. GC-induced overheads versus system overheads
        2. Extremely short-lived work
    3. Getting started with the HelloEpsilon GC class
      1. Which memory area does GC collect – stack or heap?
    4. Memory pressure testing with Epsilon
    5. Designing a garbage-free application
      1. VM interface testing
    6. Summary
  14. The HTTP Client API
    1. Technical requirements
    2. A quick flashback
      1. What can you do with HTTP?
        1. The need for the HTTP Client API
        2. HTTP Client usage
      2. A basic example
      3. The HttpClient class 
        1. Creating an HttpClient instance
        2. Methods of the HttpClient class 
        3. HttpRequest
        4. HttpResponse
    3. Some examples
      1. Accessing HTML pages using synchronous GET
      2. Accessing HTML pages using asynchronous GET
      3. Downloading multiple hosted image files
      4. Posting form details
    4. Summary
  15. ZGC
    1. Technical requirements
    2. The motivation
      1. Features of ZGC
      2. Getting started with ZGC
    3. ZGC heap
    4. ZGC phases
    5. Colored pointers
    6. Tuning ZGC
    7. Summary
  16. Flight Recorder and Mission Control
    1. Technical requirements
    2. The motivation behind JFR
      1. Features
      2. Modules
    3. Getting started with JFR
      1. Exploring further
    4. Working with custom events
    5. Summary
  17. Miscellaneous Improvements in JDK 11
    1. Technical requirements
    2. Listing the JEPs that are used in this chapter
    3. Nest-based access control
      1. What is nest-based access?
      2. Affects of nest-based control
    4. Dynamic class-file constants
    5. Improving AArch64 intrinsics
    6. Removing the Java EE and CORBA modules
    7. A key agreement with Curve25519 and Curve448
    8. Unicode 10
    9. ChaCha20 and Poly1305 cryptographic algorithms
    10. Launching single file source code programs
    11. TLS 1.3
    12. Deprecating the Nashorn JavaScript engine
    13. JEP 336 – deprecating the pack200 tools and API
    14. Summary
  18. Section 3: JDK 12
  19. Switch Expressions
    1. Technical requirements
    2. Issues with traditional switch constructs
    3. Using switch expressions
    4. Defining local variables in a switch branch
    5. Another syntax for switch expressions
    6. Comparing break with break <return value>
    7. A preview language feature
    8. Exhaustive cases
    9. What can a switch branch execute other than returning a value?
    10. How not to use labels and continue in switch expressions
    11. Summary
  20. Miscellaneous Improvements in JDK 12
    1. Technical requirements
    2. Mapping features of JDK 12 scope and JEP
    3. Shenandoah – a low-pause-time GC
    4. The microbenchmark suite
    5. The JVM constants API
    6. One AArch64 port, not two
    7. Default CDS archives
      1. What is CDS?
      2. Enhancing CDS
    8. Abortable mixed collections for G1
    9. Promptly return unused committed memory from G1
    10. Summary
  21. Section 4: Project Amber
  22. Enhanced Enums in Project Amber
    1. A quick background
      1. An example
      2. Decompiled enum – behind the scenes
    2. The state and behavior of enum constants
      1. Adding states and behaviors to enum constants
      2. Accessing the state and behavior of enum constants
        1. Workarounds to access enum constants
      3. Using inheritance with enum constants
      4. Adding generics to enums
      5. Sharper typing of enum constants
    3. Summary
  23. Data Classes and Their Usage
    1. An introduction to data classes
      1. What is a data class?
      2. The need to add data classes to the language
    2. Diving into data classes
      1. Example of syntax and semantics
      2. The aggregate and exploded forms of data classes
      3. Limitations
      4. Examples from the past – changes to define enums
      5. Pattern matching with data classes
      6. Encapsulating the state
      7. Abstract and non-abstract data classes
      8. Data classes and inheritance
      9. Extending an abstract data class
      10. Implementing interfaces
      11. Additional variables
      12. Overriding implicit behaviors
      13. Additional methods and constructors
      14. Mutability
    3. Summary
  24. Raw String Literals
    1. Technical requirements
    2. A quick example
    3. Issues with existing multiline string values
      1. A simple task
      2. Escape sequence hell with traditional string literals
      3. Concatenation hell with traditional string literals
      4. Including escape sequences as part of string values
      5. Strings and regex patterns, another hell
    4. Welcoming raw string literals
      1. Rewriting using raw strings
      2. The delimiter (backtick)
      3. Treating escape values
      4. Raw string literals versus traditional string literals
      5. Interpreting escape sequences
        1. The unescape() method
        2. The escape() method
    5. Managing margins
      1. The align() method
      2. The indent(int) method
      3. The overloaded align(int) method
      4. The detab(int) and entab methods
      5. The transform() method
    6. Common examples
      1. JSON data
      2. XML data
      3. File paths
      4. Database queries
    7. Summary
  25. Lambda Leftovers
    1. Technical requirements
    2. Marking unused parameters with underscores
      1. An example of lambda parameters
      2. The journey of getting there
    3. Shadowing of lambda parameters
      1. The existing case of lambda parameters
      2. Why should lambda parameters overshadow enclosing variables?
      3. A few of the known issues
    4. Disambiguation of functional expressions
      1. Issues with resolving overloaded methods – passing lambdas 
      2. Issues with resolving overloaded methods – passing method references
      3. The proposed solution
    5. Summary
  26. Pattern Matching
    1. Technical requirements
    2. Pattern matching
    3. Existing issues with type testing
    4. Type test patterns
    5. Using pattern matching with switch constructs
    6. Summary
  27. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Java 11 and 12 - New Features
  • Author(s): Mala Gupta
  • Release date: March 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789133271