Java 9: Building Robust Modular Applications
eBook - ePub

Java 9: Building Robust Modular Applications

  1. 910 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Java 9: Building Robust Modular Applications

About this book

Mastering advanced features of Java and implement them to build amazing projects

Key Features

  • Take advantage of Java's new modularity features to write real-world applications that solve a variety of problems
  • Explore the major concepts introduced with Java 9, including modular programming, HTTP 2.0, API changes, and more
  • Get to grips with tools, techniques and best practices to enhance application development

Book Description

Java 9 and its new features add to the richness of the language; Java is one of the languages most used by developers to build robust software applications. Java 9 comes with a special emphasis on modularity with its integration with Jigsaw. This course is your one-stop guide to mastering the language.

You'll be provided with an overview and explanation of the new features introduced in Java 9 and the importance of the new APIs and enhancements. Some new features of Java 9 are ground-breaking; if you are an experienced programmer, you will be able to make your enterprise applications leaner by learning these new features. You'll be provided with practical guidance in applying your newly acquired knowledge of Java 9 and further information on future developments of the Java platform. This course will improve your productivity, making your applications faster. Next, you'll go on to implement everything you've learned by building 10 cool projects. You will learn to build an email filter that separates spam messages from all your inboxes, a social media aggregator app that will help you efficiently track various feeds, and a microservice for a client/server note application, to name just a few.

By the end of this course, you will be well acquainted with Java 9 features and able to build your own applications and projects.

This Learning Path contains the best content from the following two recently published Packt products:

•Mastering Java 9

•Java 9 Programming Blueprints

What you will learn

  • Package Java applications as modules using the Java Platform Module System
  • Implement process management in Java using the all-new process handling API
  • Integrate your applications with third-party services in the cloud
  • Interact with mail servers, using JavaMail to build an application that filters spam messages
  • Use JavaFX to build rich GUI-based applications, which are an essential element of application development
  • Leverage the possibilities provided by the newly introduced Java shell
  • Test your application's effectiveness with the JVM harness
  • See how Java 9 provides support for the HTTP 2.0 standard

Who this book is for

This learning path is for Java developers who are looking to move a level up and learn how to build robust applications in the latest version of Java.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

New Tools and Tool Enhancements

In the previous chapter, we explored Java 9's new stack walker API and learned how it enables Java applications to walk the calling stack. This is a specialized functionality that is not often implemented in Java applications. That being said, the API may be good for some very special cases, such as for functionality that is delivered by a framework. You learned that if you develop framework-supporting application programming and you want code that depends on the caller context, then the stack walker API is for you. We also discovered that the API gives fast and optimized access to the call stack, implementing lazy access to the individual frames.
In this chapter, we will cover 16 Java Enhancement Proposals (JEPs) that were incorporated into the Java 9 platform. These JEPs cover a wide range of tools and updates to APIs to make developing with Java easier, with greater optimization possibilities for our resulting programs.
Our review of new tools and tool enhancements will include the following:
  • The new HTTP client
  • Javadoc and the Doclet API
  • mJRE changes
  • JavaScript parser
  • Multi-release JAR files
  • The Java-level JVM compiler interface
  • TIFF support
  • Platform logging
  • XML Catalogs
  • Collections
  • Platform-specific desktop features
  • Enhanced method handling
  • Enhanced deprecation

The new HTTP client [JEP-110]

In this section, we will review Java's Hypertext Transfer Protocol (HTTP) client, starting with a pre-Java 9 look and then diving into the new HTTP client that is part of the Java 9 platform. This approach is needed to support an understanding of the changes made in Java 9.

The HTTP client before Java 9

JDK version 1.1 introduced the HttpURLConnection API that supported HTTP-specific features. This was a robust class that included the fields listed here:
  • chunkLength
  • fixedContentLength
  • fixedContentLengthLong
  • HTTP_ACCEPTED
  • HTTP_BAD_GATEWAY
  • HTTP_BAD_METHOD
  • HTTP_BAD_REQUEST
  • HTTP_CLIENT_TIMEOUT
  • HTTP_CONFLICT
  • HTTP_CREATED
  • HTTP_ENTITY_TOO_LARGE
  • HTTP_FORBIDDEN
  • HTTP_GONE
  • HTTP_INTERNAL_ERROR
  • HTTP_LENGTH_REQUIRED
  • HTTP_MOVED_PERM
  • HTTP_MOVED_TEMP
  • HTTP_MULT_CHOICE
  • HTTP_NO_CONTENT
  • HTTP_NOT_ACCEPTABLE
  • HTTP_NOT_AUTHORITATIVE
  • HTTP_NOT_FOUND
  • HTTP_NOT_IMPLEMENTED
  • HTTP_NOT_MODIFIED
  • HTTP_OK
  • HTTP_PARTIAL
  • HTTP_PAYMENT_REQUIRED
  • HTTP_PRECON_FAILED
  • HTTP_PROXY_AUTH
  • HTTP_REQ_TOO_LONG
  • HTTP_RESET
  • HTTP_SEE_OTHER
  • HTTP_SERVER_ERROR
  • HTTP_UNAUTHORIZED
  • HTTP_UNAVAIABLE
  • HTTP_UNSUPPORTED_TYPE
  • HTTP_USE_PROXY
  • HTTP_VERSION
  • instanceFollowRedirects
  • method
  • responseCode
  • responseMessage
As you can see from the list of fields, there was a great support for HTTP. In addition to a constructor, there are a plethora of available methods, including the following ones:
  • disconnect()
  • getErrorStream()
  • getFollowRedirects()
  • getHeaderField(int n)
  • getHeaderFieldDate(String name, long Default)
  • getHeaderFieldKey(int n)
  • getInstanceFollowRedirects()
  • getPermission()
  • getRequestMethod()
  • getResponseCode()
  • getResponseMessage()
  • setChunkedStreamingMode(int chunklen)
  • setFixedLengthStreamingMode(int contentLength)
  • setFixedlengthStreamingMode(long contentLength)
  • setFollowRedirects(boolean set)
  • setInstanceFollowRedircts(boolean followRedirects)
  • setRequestMethod(String method)
  • usingProxy()
The class methods listed earlier are in addition to the methods inherited from the java.net.URLConnection class and the java.lang.Object class.
There were problems with the original HTTP client that made it ripe for updating with the new Java platform. Those problems were as follows:
  • The base URLConnection API had, defunct protocols such as Gopher and FTP increasingly over the years
  • The HttpURLConnection API predated HTTP 1.1 and was overly abstract, making it less usable
  • The HTTP client was woefully under documented, making the API frustrating and difficult to use
  • The client only functioned on one thread at a time
  • The API was extremely difficult to maintain due to the above points about it predating HTTP 1.1 and it lacking sufficient documentation
Now that we know what was wrong with the HTTP client, let's look at what's in store for Java 9.

Java 9's new HTTP client

There were several goals associated with creating the new HTTP client for the Java 9 platform. JEP-110 was the organizing proposal for the new HTTP client. The primary goals of JEP-110 are listed here and featured the creation of the new HTTP client presented. These goals are presented in the broad categories of ease of use, core capabilities, additional capabilities, and performance:
  • Ease of use:
    • The API was designed to provide up to 90 percent of HTTP-related application requirements.
    • The new API is usable, without unnecessary complexity, for the most common use cases.
    • A simplistic blocking mode is included.
    • The API supports modern Java language features. Lambda expressions, a major new introduction released with Java 8, are an example.
  • Core capabilities:
    • Supports HTTPS/TLS
    • Supports HTTP/2
    • Provides visibility on all details related to HTTP protocol requests and responses
    • Supports standard/common authentication mechanisms
    • Provides headers received event notifications
    • Provides response body received event notifications
    • Provides error event notifications
  • Additional capabilities:
    • The new API can be used for WebSocket handshakes
    • It performs security checks in concert with the current networking API
  • Performance:
    • For HTTP/1.1:
      • The new API must perform at least as efficiently as the previous API.
      • Memory consumption must not exceed that of Apache Ht...

Table of contents

  1. Title Page - Courses
  2. Copyright and Credits - Courses
  3. Packt Upsell - Courses
  4. Preface
  5. Mastering Java 9
  6. The Java 9 Landscape
  7. Discovering Java 9
  8. Java 9 Language Enhancements
  9. Building Modular Applications with Java 9
  10. Migrating Applications to Java 9
  11. Experimenting with the Java Shell
  12. Leveraging the New Default G1 Garbage Collector
  13. Microbenchmarking Applications with JMH
  14. Making Use of the ProcessHandle API
  15. Fine-Grained Stack Tracing
  16. New Tools and Tool Enhancements
  17. Concurrency and Reactive Programming
  18. Security Enhancements
  19. Command Line Flags
  20. Best Practices In Java 9
  21. Future Directions
  22. Java 9 Programming Blueprints
  23. Introduction
  24. Managing Processes in Java
  25. Duplicate File Finder
  26. Date Calculator
  27. Sunago - A Social Media Aggregator
  28. Sunago - An Android Port
  29. Email and Spam Management with MailFilter
  30. Photo Management with PhotoBeans
  31. Taking Notes with Monumentum
  32. Serverless Java
  33. DeskDroid - A Desktop Client for Your Android Phone
  34. What is Next?
  35. Bibliography

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Java 9: Building Robust Modular Applications by Dr. Edward Lavieri, Peter Verhas, Jason Lee in PDF and/or ePUB format, as well as other popular books in Computer Science & Object Oriented Programming. We have over one million books available in our catalogue for you to explore.