Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Java 11 Cookbook
Java 11 Cookbook

Java 11 Cookbook: A definitive guide to learning the key concepts of modern application development , Second Edition

Arrow left icon
Profile Icon Nick Samoylov Profile Icon Sanaulla
Arrow right icon
$54.99
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1 (1 Ratings)
Paperback Sep 2018 802 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Nick Samoylov Profile Icon Sanaulla
Arrow right icon
$54.99
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1 (1 Ratings)
Paperback Sep 2018 802 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Java 11 Cookbook

Installation and a Sneak Peek into Java 11

In this chapter, we will cover the following recipes:

  • Installing JDK 18.9 on Windows and setting up the PATH variable
  • Installing JDK 18.9 on Linux (Ubuntu, x64) and configuring the PATH variable
  • Compiling and running a Java application
  • What's new in JDK 18.9
  • Using application class-data sharing

Introduction

Every quest for learning a programming language begins with setting up the environment to experiment with our learning. Keeping in sync with this philosophy, in this chapter, we will show you how to set up your development environment and then run a simple modular application to test our installation. After that, we'll give you an introduction to the new features and tools in JDK 18.9. Then, we will compare JDK 9, 18.3, and 18.9. We'll end the chapter with a new feature introduced in JDK 18.3 that allows application-class-data sharing.

Installing JDK 18.9 on Windows and setting up the PATH variable

In this recipe, we will look at installing JDK on Windows and how to set up the PATH variable to be able to access the Java executables (such as javac, java, and jar) from anywhere within the command shell.

How to do it...

  1. Visit http://jdk.java.net/11/ and accept the early-adopter license agreement, which looks like this:
  1. After accepting the license, you will get a grid of the available JDK bundles based on the OS and architecture (32/64-bit). Click to download the relevant JDK executable (.exe) for your Windows platform.
  2. Run the JDK executable (.exe) and follow the onscreen instructions to install JDK on your system.
  3. If you have chosen all the defaults during the installation, you will find JDK installed in C:/Program Files/Java for 64 bit and C:/Program Files (x86)/Java for 32 bit.

Now that we have finished installing JDK, let's see how we can set the PATH variable.

The tools provided with JDK, namely javac, java, jconsole, and jlink, are available in the bin directory of your JDK installation. There are two ways you could run these tools from the Command Prompt:

  1. Navigate to the directory where the tools are installed and run them, as follows:
      cd "C:\Program Files\Java\jdk-11\bin"
      javac -version
  1. Export the path to the directory so that the tools are available from any directory in the command prompt. To achieve this, we have to add the path to the JDK tools in the PATH environment variable. The command prompt will search for the relevant tool in all the locations declared in the PATH environment variable.

Let's see how you can add the JDK bin directory to the PATH variable:

  1. Right-click on My Computer and then click on Properties. You will see your system information. Search for Advanced system settings and click on it to get a window, as shown in the following screenshot:
  1. Click on Environment Variables to view the variables defined in your system. You will see that there are quite a few environment variables already defined, as shown in the following screenshot (the variables will differ across systems; in the following screenshot, there are a few predefined variables and a few variables added by me):

The variables defined under System variables are available across all the users of the system, and those defined under User variables for <user name> are available only to the specific user.

  1. A new variable, with the name JAVA_HOME, and its value as the location of the JDK 9 installation. For example, it would be C:\Program Files\Java\jdk-11 (for 64 bit) or C:\Program Files (x86)\Java\jdk-11 (for 32 bit):
  1. Update the PATH environment variable with the location of the bin directory of your JDK installation (defined in the JAVA_HOME environment variable). If you already see the PATH variable defined in the list, then you need to select that variable and click on Edit. If the PATH variable is not seen, click on New.
  2. Any of the actions in the previous step will give you a popup, as shown in the following screenshot (on Windows 10):

The following screenshot shows the other Windows versions:

  1. You can either click on New in the first screenshot and insert the %JAVA_HOME%\bin value, or you can append the value against the Variable value field by adding ; %JAVA_HOME%\bin. The semicolon (;) in Windows is used to separate multiple values for a given variable name.
  2. After setting the values, open the command prompt and run javac -version. You should be able to see javac 11-ea as the output. If you don't see it, it means that the bin directory of your JDK installation has not been correctly added to the PATH variable.

Installing JDK 18.9 on Linux (Ubuntu, x64) and configuring the PATH variable

In this recipe, we will look at installing JDK on Linux (Ubuntu, x64), and how to configure the PATH variable to make the JDK tools (such as javac, java, and jar) available from any location within the Terminal.

How to do it...

  1. Follow steps 1 and 2 of the Installing JDK 18.9 on Windows and setting up the PATH variable recipe to reach the downloads page.
  2. Copy the download link (tar.gz) for the JDK for the Linux x64 platform from the downloads page.
  3. Download the JDK by using $> wget <copied link>, for example, $> wget https://download.java.net/java/early_access/jdk11/26/BCL/jdk-11-ea+26_linux-x64_bin.tar.gz.
  1. Once the download completes, you should have the relevant JDK available, for example, jdk-11-ea+26_linux-x64_bin.tar.gz. You can list the contents by using $> tar -tf jdk-11-ea+26_linux-x64_bin.tar.gz. You can even pipe it to more to paginate the output: $> tar -tf jdk-11-ea+26_linux-x64_bin.tar.gz | more.
  2. Extract the contents of the tar.gz file under /usr/lib by using $> tar -xvzf jdk-11-ea+26_linux-x64_bin.tar.gz -C /usr/lib. This will extract the contents into a directory, /usr/lib/jdk-11. You can then list the contents of JDK 11 by using $> ls /usr/lib/jdk-11.
  1. Update the JAVA_HOME and PATH variables by editing the .bash_aliases file in your Linux home directory:
      $> vim ~/.bash_aliases
      export JAVA_HOME=/usr/lib/jdk-11
      export PATH=$PATH:$JAVA_HOME/bin

Source the .bashrc file to apply the new aliases:

      $> source ~/.bashrc
      $> echo $JAVA_HOME
      /usr/lib/jdk-11
      $>javac -version
      javac 11-ea
      $> java -version
      java version "11-ea" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11-ea+22)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+22, mixed
mode)
All the examples in this book are run against JDK installed on Linux (Ubuntu, x64), except for places where we have specifically mentioned that these are run on Windows. We have tried to provide run scripts for both platforms.

Compiling and running a Java application

In this recipe, we will write a very simple modular Hello world program to test our JDK installation. This simple example prints Hello world in XML; after all, it's the world of web services.

Getting ready

You should have JDK installed and the PATH variable updated to point to the JDK installation.

How to do it...

  1. Let's define the model object with the relevant properties and annotations that will be serialized into XML:
        @XmlRootElement
        @XmlAccessorType(XmlAccessType.FIELD) 
        class Messages{     
          @XmlElement 
          public final String message = "Hello World in XML"; 
        }

In the preceding code, @XmlRootElement is used to define the root tag, @XmlAccessorType is used to define the type of source for the tag name and tag values, and @XmlElement is used to identify the sources that become the tag name and tag values in the XML.

  1. Let's serialize an instance of the Message class into XML using JAXB:
public class HelloWorldXml{
  public static void main(String[] args) throws JAXBException{
    JAXBContext jaxb = JAXBContext.newInstance(Messages.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT,Boolean.TRUE);
    StringWriter writer = new StringWriter();
    marshaller.marshal(new Messages(), writer);
    System.out.println(writer.toString());
  } 
}
  1. We will now create a module named com.packt. To create a module, we need to create a file named module-info.java, which contains the module definition. The module definition contains the dependencies of the module and the packages exported by the module to other modules:
    module com.packt{
      //depends on the java.xml.bind module
      requires java.xml.bind;
      //need this for Messages class to be available to java.xml.bind
      exports  com.packt to java.xml.bind;
    }
We will explain modules in detail in Chapter 3, Modular Programming. But this example is just to give you a taste of modular programming and to test your JDK installation.

The directory structure with the preceding files is as follows:

  1. Let's compile and run the code. From the hellowordxml directory, create a new directory in which to place your compiled class files:
      mkdir -p mods/com.packt

Compile the source, HelloWorldXml.java and module-info.java, into the mods/com.packt directory:

      javac -d mods/com.packt/ src/com.packt/module-info.java
src/com.packt/com/packt/HelloWorldXml.java
  1. Run the compiled code using java --module-path mods -m com.packt/com.packt.HelloWorldXml. You will see the following output:
<messages><message>Hello World in XML</message></messages>

Don't worry if you are not able to understand the options passed with the java or javac commands. You will learn about them in Chapter 3, Modular Programming.

What's new in Java 11?

The release of Java 9 was a milestone in the Java ecosystem. The modular framework developed under Project Jigsaw became part of Java SE release. Another major feature was the JShell tool, which is a REPL tool for Java. Many other new features introduced with Java 9 are listed in the release notes: http://www.oracle.com/technetwork/java/javase/9all-relnotes-3704433.html.

In this recipe, we will enumerate and discuss some of the new features introduced with JDK 18.3 and 18.9 (Java 10 and 11).

Getting ready

The Java 10 release (JDK 18.3) started a six-month release cycle—every March and every September—and a new release numbering system. It also introduced many new features, the most significant of which (for application developers) are the following:

  • Local variable type inference that allows the declaration of a variable using the reserved var type (see Chapter 15, The New Way of Coding with Java 10 and Java 11)
  • Parallel full garbage collection for the G1 garbage collector, which improves worst-case latencies
  • A new method, Optional.orElseThrow(), that is now the preferred alternative to the existing get() method
  • New APIs for creating unmodifiable collections: The List.copyOf(), Set.copyOf(), and Map.copyOf() methods of the java.util package and new methods of the java.util.stream.Collectors class: toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() (see Chapter 5, Streams and Pipelines)
  • A default set of root Certification Authorities, making OpenJDK builds more appealing to developers
  • A new Javadoc command-line option, --add-stylesheet, provides support for the use of multiple stylesheets in the generated documentation
  • Extending the existing class-data sharing feature to allow application classes to be placed in the shared archive that improves startup time and reduces the footprint (see the Using application class-data sharing recipe)

  • An experimental just-in-time compiler, Graal, can be used on the Linux/x64 platform
  • A clean garbage-collector (GC) interface that makes it simpler to add a new GC to HotSpot without perturbing the current code base and makes it easier to exclude a GC from a JDK build
  • Enabling HotSpot to allocate the object heap on an alternative memory device, such as an NVDIMM memory module, specified by the user
  • Thread-local handshakes, for executing a callback on threads without performing a global VM safepoint
  • Docker awareness: JVM will know whether it is running in a Docker container on a Linux system and can extract container-specific configuration information instead of querying the operating system
  • Three new JVM options, to give Docker container users greater control over the system memory

See the full list of Java 10's new features in the release notes: https://www.oracle.com/technetwork/java/javase/10-relnote-issues-4108729.html.

We will discuss the new features of JDK 18.9 in more detail in the next section.

How to do it...

We have picked a few features that we feel are the most important and useful for an application developer.

JEP 318 – Epsilon

Epsilon is a so-called no-op garbage collector that basically does nothing. Its use cases include testing for performance, memory pressure, and the virtual machine interface. It also could be used for short-lived jobs or the jobs that do not consume much memory and do not require garbage collection.

We discussed this feature in more details in the recipe Understand Epsilon, a low-overhead garbage collector recipe in Chapter 11, Memory Management and Debugging.

JEP 321 – HTTP Client (Standard)

JDK 18.9 standardizes the incubated HTTP API client introduced in JDK 9 and updated in JDK 10. Based on CompleteableFuture, it supports nonblocking requests and responses. The new implementation is asynchronous and provides a better traceable data flow.

Chapter 10, Networking, explains this feature in more detail in several recipes.

JEP 323 – Local-Variable Syntax for Lambda Parameters

A local-variable syntax for lambda parameters has the same syntax as a local-variable-declaration using the reserved var type introduced in Java 11. See the Using local variable syntax for lambda parameters recipe in Chapter 15, The New Way of Coding with Java 10 and Java 11, for more details.

JEP 333 – ZGC

The Z Garbage Collector (ZGC) is an experimental low-latency garbage collector. Its pause times should not exceed 10 ms and there should be no more than 15% application throughput reduction compared to using the G1 collector. ZGC also lays a foundation for future features and optimizations. Linux/x64 will be the first platform to get ZGC support.

New API

There are several additions to the standard Java API:

  • Character.toString(int codePoint): Returns a String object representing the character specified by the provided Unicode code point:
var s = Character.toString(50);
System.out.println(s); //prints: 2
  • CharSequence.compare(CharSequence s1, CharSequence s2): Compares two CharSequence instances lexicographically. Returns the difference between the position of the second parameter and the position of the first parameter in the ordered list:
var i = CharSequence.compare("a", "b");
System.out.println(i); //prints: -1

i = CharSequence.compare("b", "a");
System.out.println(i); //prints: 1

i = CharSequence.compare("this", "that");
System.out.println(i); //prints: 8

i = CharSequence.compare("that", "this");
System.out.println(i); //prints: -8
  • The repeat(int count) method of the String class: Returns a String value composed of count times repeated in the String source value:
String s1 = "a";
String s2 = s1.repeat(3); //prints: aaa
System.out.println(s2);

String s3 = "bar".repeat(3);
System.out.println(s3); //prints: barbarbar
  • The isBlank() method of the String class: Returns true if the String value is empty or contains only white spaces, otherwise false. In our example, we have contrasted it with the isEmpty() method, which returns true if, and only if, length() is zero:
String s1 = "a";
System.out.println(s1.isBlank()); //false
System.out.println(s1.isEmpty()); //false

String s2 = "";
System.out.println(s2.isBlank()); //true
System.out.println(s2.isEmpty()); //true

String s3 = " ";
System.out.println(s3.isBlank()); //true
System.out.println(s3.isEmpty()); //false

  • The lines() method of the String class: Returns a Stream object that emits lines extracted from the source String value, separated by line terminators \n, \r, or \r\n:
String s = "l1 \nl2 \rl3 \r\nl4 ";
s.lines().forEach(System.out::print); //prints: l1 l2 l3 l4
  • Three methods of the String class that remove leading space, trailing space, or both from the source String value:
String s = " a b ";
System.out.println("'" + s.strip() + "'"); // 'a b'
System.out.println("'" + s.stripLeading() + "'"); // 'a b '
System.out.println("'" + s.stripTrailing() + "'");// ' a b'
  • Two Path.of() methods that construct a java.nio.file.Path object:
Path filePath = Path.of("a", "b", "c.txt");
System.out.println(filePath); //prints: a/b/c.txt

try {
filePath = Path.of(new URI("file:/a/b/c.txt"));
System.out.println(filePath); //prints: /a/b/c.txt
} catch (URISyntaxException e) {
e.printStackTrace();
}
  • The asMatchPredicate() method of the java.util.regex.Pattern class, which creates an object of the java.util.function.Predicate functional interface, which then allows us to test a String value for matching the compiled pattern. In the following example, we test whether a String value starts with the a character and ends with the b character:
Pattern pattern = Pattern.compile("^a.*z$");
Predicate<String> predicate = pattern.asMatchPredicate();
System.out.println(predicate.test("abbbbz")); // true
System.out.println(predicate.test("babbbz")); // false
System.out.println(predicate.test("abbbbx")); // false

There's more...

There are quite a few other changes introduced in JDK 18.9:

  • The Java EE and CORBA modules are removed
  • JavaFX is separated and removed from the Java standard libraries
  • The Pack200 and Unpack200 tools and the Pack200 API in util.jar are deprecated
  • The Nashorn JavaScript engine, along with the JJS tool, are deprecated with the intent to remove them in the future
  • The Java class file format is extended to support a new constant pool form, CONSTANT_Dynamic
  • Aarch64 intrinsics are improved, with the implementation of new intrinsics for the java.lang.Math sin, cos, and log functions, on Aarch64 processorsJEP 309—Dynamic Class-File Constants
  • Flight Recorder provides a low-overhead data-collection framework for troubleshooting both Java applications and the HotSpot JVM
  • The Java launcher can now run a program supplied as a single file of Java source code, so these programs can run directly from the source
  • A low-overhead heap profiling, providing a way to sample Java heap allocations, is accessible via JVM Tool Interface
  • Transport Layer Security (TLS) 1.3 increases security and improves performance
  • Support of Unicode version 10.0 in the java.lang.Character, java.lang.String, java.awt.font.NumericShaper, java.text.Bidi,java.text.BreakIterator, and java.text.Normalizer classes

Read the Java 11 (JDK 18.9) release notes for more details and other changes.

Using application class-data sharing

This feature has existed in Java since Java 5. It was extended in Java 9 as a commercial feature by allowing not only bootstrap classes but also application classes to be placed in the archive shared by JVMs. In Java 10, this feature became part of the open JDK. It decreases startup time and, when several JVMs are running on the same machine with the same application being deployed, reduces memory consumption.

Getting ready

The advantages of loading classes from the shared archive became possible for two reasons:

  • The classes stored in the archive are preprocessed, which means that the JVM memory mapping is stored in the archive too. It reduces the overhead of class-loading when a JVM instance starts.
  • The memory region can even be shared between the JVM instances running on the same computer, which reduces overall memory consumption by eliminating the need to replicate the same information in each instance.

The new JVM functionality allows us to create a list of classes to be shared, then use this list to create a shared archive, and use the shared archive to fast-load archived classes into memory.

How to do it...

  1. By default, JVM can create an archive using the list of classes that comes with JDK. For example, run the following command:
java -Xshare:dump

It will create the shared archive as a classes.jsa file. On a Linux system, this file is placed in the following folder:

/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/lib/server
On a Windows system, it is placed in the following folder:
C:\Program Files\Java\jdk-11\bin\server

If this folder is accessible by the system admin only, run the command as an admin.

Please notice that not all classes can be shared. For example, the .class files located in the directory on the classpath and classes loaded by custom class loaders cannot be added to the shared archive.

  1. To tell the JVM to use the default shared archive, use the following command:
java -Xshare:on -jar app.jar

The preceding command maps the content of the archive at a fixed address. This memory-mapping operation may occasionally fail when the required address space is not available. If that happens when the -Xshare:on option is used, the JVM exits with an error. Alternatively, the -Xshare:auto option can be used, which just disables the feature and loads the classes from the classpath if the shared archive cannot be used for whatever reason.

  1. The simplest way to create a list of loaded application classes is by using the following command:
java -XX:+UseAppCDS -XX:DumpLoadedClassList=classes.txt -jar app.jar

The preceding command records all the loaded classes in the classes.txt file. If you would like to make your application load faster, stop the JVM just after the application has been started. If you need it to load certain classes faster but these classes are not loaded at the application startup automatically, make sure that the use cases that require these classes are executed.

  1. Alternatively, you can manually edit the classes.txt file and add/remove any classes you need to put in the shared archive. Create this file once automatically and see the format. It is a simple text file that lists one class in each line.
  2. Once the list is created, use the following command to generate the shared archive:
java -XX:+UseAppCDS -Xshare:dump -XX:SharedClassListFile=classes.txt -XX:SharedArchiveFile=app-shared.jsa --class-path app.jar

Notice that the shared archive file has a name other than classes.jsa, so the default shared archive is not overwritten.

  1. Use the created archive by executing the following command:
java -XX:+UseAppCDS -Xshare:on -XX:SharedArchiveFile=app-shared.jsa -jar app.jar

Again, you can use the -Xshare:auto option to avoid an unexpected exit of the JVM.

The effect of the shared archive usage depends on the number of classes in it and other particulars of the application. So, we recommend you experiment and test various configurations before committing to a certain list of classes in production.

Left arrow icon Right arrow icon

Key benefits

  • Explore the latest features of Java 11 to implement efficient and reliable code
  • Develop memory-efficient applications, understanding new garbage collection in Java 11
  • Create restful webservices and microservices with Spring boot 2 and Docker

Description

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.

Who is this book for?

The book is for intermediate-to-advanced Java programmers who want to make their applications fast, secure, and scalable.

What you will learn

  • Set up JDK and understand what s new in the JDK 11 installation
  • Implement object-oriented designs using classes and interfaces
  • Manage operating system processes
  • Create a modular application with clear dependencies
  • Build graphical user interfaces using JavaFX
  • Use the new HTTP Client API
  • Explore the new diagnostic features in Java 11
  • Discover how to use the new JShell REPL tool
Estimated delivery fee Deliver to Argentina

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 29, 2018
Length: 802 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789132359
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Argentina

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date : Sep 29, 2018
Length: 802 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789132359
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 152.97
Java 11 Cookbook
$54.99
Mastering Java 11
$48.99
Java Projects
$48.99
Total $ 152.97 Stars icon
Banner background image

Table of Contents

17 Chapters
Installation and a Sneak Peek into Java 11 Chevron down icon Chevron up icon
Fast Track to OOP - Classes and Interfaces Chevron down icon Chevron up icon
Modular Programming Chevron down icon Chevron up icon
Going Functional Chevron down icon Chevron up icon
Streams and Pipelines Chevron down icon Chevron up icon
Database Programming Chevron down icon Chevron up icon
Concurrent and Multithreaded Programming Chevron down icon Chevron up icon
Better Management of the OS Process Chevron down icon Chevron up icon
RESTful Web Services Using Spring Boot Chevron down icon Chevron up icon
Networking Chevron down icon Chevron up icon
Memory Management and Debugging Chevron down icon Chevron up icon
The Read-Evaluate-Print Loop (REPL) Using JShell Chevron down icon Chevron up icon
Working with New Date and Time APIs Chevron down icon Chevron up icon
Testing Chevron down icon Chevron up icon
The New Way of Coding with Java 10 and Java 11 Chevron down icon Chevron up icon
GUI Programming Using JavaFX Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
(1 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 100%
JK Oregon Dec 07, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
I don't understand how this book made it into print. It is filled with errors and awful advice. Almost ever few pages I want to set the book on fire.For example, let's look at the treatment of 'var' which was added in Java 10. The authors list all the different ways you can use var, including (cover your eyes):var var = 1:andpackage com.packt.cookbook.var:Why would you even suggest the first example or include the completely irrelevant second one?Next example: They discuss the Epsilon garbage collector (which is used for tuning and actually never collects garbage). They write an overly complex loop to allocate 4GB and they run it with a 4GB heap. When the allocations cause a memory error, they simply assert that is what they were expecting. That a reader unfamiliar with GC would want to know why allocating the full available space would cause an error apparently doesn't cross their minds. The reader is left to guess why they were expecting it. To top it off, as printed, the command-line options to run Epsilon contain a typo.Their discussion of Optional: "It was intended to help avoid the dreaded NullPointerException. But so far, the introduction of Optional helped to accomplish it only to a degree and mostly in the area of streams" They later repeat that it's not terribly useful when not used in streams. But they don't understand that *the whole intent* of Optional was precisely to be used in collections and streams. So the repeated complaints and general dismissal of Optional demonstrate ignorance rather than insight. Optional is a super-useful tool when working with streams.Even facts that would have been trivial to check are wrong (and this is a second edition!). For example, the first sentence on the back cover: "For more than three decades, Java has been at the forefront..." Java is about to celebrate its 25th birthday. More than three decades?The whole book is like this. I can't say that every page has a technical problem, but many sections do.Finally, there is the language. Neither author is a native speaker nor is the technical editor. And apparently no editor cleaned up the language after the authors turned in the drafts. There are many twisted sentences, others where subjects or verbs are missing, others where an expression is misused--all leading to frustrating lack of clarity at crucial points.Top to bottom, this book should be avoided.If you're looking for a good recipe book, I recommend Ken Kousen's "Modern Java Recipes" It doesn't go through Java 11, but everything in it is technically correct and the writing is clear.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela