Java 9: Building Robust Modular Applications
eBook - ePub

Java 9: Building Robust Modular Applications

Dr. Edward Lavieri, Peter Verhas, Jason Lee

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

Java 9: Building Robust Modular Applications

Dr. Edward Lavieri, Peter Verhas, Jason Lee

Book details
Book preview
Table of contents
Citations

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
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 here.
Is Java 9: Building Robust Modular Applications an online PDF/ePUB?
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 & Programming in C++. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788830706
Edition
1

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