Book Image

Java 11 Cookbook - Second Edition

By : Nick Samoylov, Mohamed Sanaulla
Book Image

Java 11 Cookbook - Second Edition

By: Nick Samoylov, Mohamed Sanaulla

Overview of this book

For more than three decades, Java has been on the forefront of developing robust software that has helped versatile businesses meet their requirements. Being one of the most widely used programming languages in history, it’s imperative for Java developers to discover effective ways of using it in order to take full advantage of the power of the latest Java features. Java 11 Cookbook offers a range of software development solutions with simple and straightforward Java 11 code examples to help you build a modern software system. Starting with the installation of Java, each recipe addresses various problem by explaining the solution and offering insights into how it works. You’ll explore the new features added to Java 11 that will make your application modular, secure, and fast. The book contains recipes on functional programming, GUI programming, concurrent programming, and database programming in Java. You’ll also be taken through the new features introduced in JDK 18.3 and 18.9. By the end of this book, you’ll be equipped with the skills required to write robust, scalable, and optimal Java code effectively.
Table of Contents (18 chapters)

What this book covers

Chapter 1, Installation and a Sneak Peek into Java 11, helps you to set up the development environment for running your Java programs and gives a brief overview of the new features and tools in Java 11.

Chapter 2, Fast Track to OOP – Classes and Interfaces, covers Object-Oriented Programming (OOP) principles and design solutions, including inner classes, inheritance, composition, interfaces, enumerations, and the Java 9 changes to Javadocs.

Chapter 3, Modular Programming, introduces Jigsaw as a major feature and a huge leap for the Java ecosystem. This chapter demonstrates how to use tools, such as jdeps and jlink, to create simple modular applications and related artifacts, such as modular JARs, and finally, how to modularize your pre-Jigsaw applications.

Chapter 4, Going Functional, introduces a programming paradigm called functional programming. The topics covered include functional interfaces, lambda expressions, and lambda-friendly APIs.

Chapter 5, Streams and Pipelines, shows how to leverage streams and chain multiple operations on a collection to create a pipeline, use factory methods to create collection objects, create and operate on streams, and create an operation pipeline on
streams, including parallel computations.

Chapter 6, Database Programming, covers both basic and commonly used interactions between a Java application and a database, right from connecting to the database and performing CRUD operations to creating transactions, storing procedures, and working
with large objects.

Chapter 7, Concurrent and Multithreaded Programming, presents different ways of incorporating concurrency and some best practices, such as synchronization and immutability. The chapter also discusses the implementation of some commonly used patterns, such as divide-conquer and publish-subscribe, using the constructs provided by Java.

Chapter 8, Better Management of the OS Process, elaborates on the new API enhancements regarding the Process API.

Chapter 9, RESTful Web Services Using Spring Boot, deals with creating simple RESTful web services using Spring Boot, deploying them to Heroku, dockerizing Spring Boot-based RESTful web service applications, and monitoring Spring Boot applications using Prometheus.

Chapter 10, Networking, shows you how to use different HTTP client API libraries; namely, the new HTTP client API shipped with latest JDK, the Apache HTTP client, and the Unirest HTTP client API.

Chapter 11, Memory Management and Debugging, explores managing the memory of a Java application, including an introduction to the garbage collection algorithm used in Java 9, and some new features that help in advanced application diagnostics. We'll also show how to manage resources by using the new try-with-resources construct and the new stack-walking API.

Chapter 12, The Read-Evaluate-Print Loop (REPL) Using JShell, shows you how to work with the new REPL tool and JShell, provided as part of the JDK.

Chapter 13, Working with New Date and Time APIs, demonstrates how to construct time zone-dependent and independent date and time instances, how to create a date- and time-based period between date instance, how to represent epoch time, how to manipulate and compare date and time instances, how to work with different calendar systems, and how to format dates using the DateTimeFormatter.

Chapter 14, Testing, explains how to unit test your APIs before they are integrated with other components, including stubbing dependencies with some dummy data and mocking dependencies. We will also show you how to write fixtures to populate test data and then how to test your application behavior by integrating different APIs and testing them.

Chapter 15, The New Way of Coding with Java 10 and Java 11, demonstrates how to use local variable type inference and when and how to use local variable syntax for lambda parameters.

Chapter 16, GUI Programming Using JavaFX, explains how to use JavaFX for creating a GUI using FXML Markup, and CSS. It will demonstrate creating a bar chart, a pie chart, a line chart, an area chart. It will also show how to embed HTML in an application and a media source and how to add effects to controls. Also, we will learn about the newly released Robot API in the OpenJFX 11 update.