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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Java 9 Programming Blueprints
Java 9 Programming Blueprints

Java 9 Programming Blueprints: Master features like modular programming, Java HTTP 2.0, and REPL by building numerous applications

eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Billing Address

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

Java 9 Programming Blueprints

Managing Processes in Java

With a very quick tour through some of the big new features of Java 9, as well as those from a couple of previous releases, let's turn our attention to applying some of these new APIs in a practical manner. We'll start with a simple process manager.

While having your application or utility handle all of your user's concerns internally is usually ideal, occasionally you need to run (or shell out to) an external program for a variety of reasons. From the very first days of Java, this was supported by the JDK via the Runtime class via a variety of APIs. Here is the simplest example:

    Process p = Runtime.getRuntime().exec("/path/to/program"); 

Once the process has been created, you can track its execution via the Process class, which has methods such as getInputStream(), getOutputStream(), and getErrorStream(). We have also had...

Creating a project

Typically speaking, it is much better if a build can be reproduced without requiring the use of a specific IDE or some other proprietary tool. Fortunately, NetBeans offers the ability to create a Maven-based JavaFX project. Click on File | New Project and select Maven, then JavaFX Application:

Next, perform the following steps:

  1. Click on Next.
  2. Enter Project Name as ProcessManager.
  3. Enter Group ID as com.steeplesoft.
  4. Enter Package as com.steeplesoft.processmanager.
  5. Select Project Location.
  6. Click on Finish.

Consider the following screenshot as an example:

Once the new project has been created, we need to update the Maven pom to use Java 9:

    <build> 
      <plugins> 
        <plugin> 
          <groupId>org.apache.maven.plugins</groupId> 
          <artifactId>maven-compiler-plugin</artifactId> 
          <version...

Bootstrapping the application

As noted in the introduction, this will be a JavaFX-based application, so we'll start by creating the skeleton for the application. This is a Java 9 application, and we intend to make use of the Java Module System. To do that, we need to create the module definition file, module-info.java, which resides in the root of our source tree. This being a Maven-based project, that would be src/main/java:

    module procman.app { 
      requires javafx.controls; 
      requires javafx.fxml; 
    } 

This small file does a couple of different things. First, it defines a new procman.app module. Next, it tells the system that this module requires two JDK modules: javafx.controls and javafx.fxml. If we did not specify these two modules, then our system, which we'll see below, would not compile, as the JDK would not make the required classes and packages...

Defining the user interface

When building the user interface for a JavaFX application, you can do it in one of two ways: code or markup. To keep our code smaller and more readable, we'll build the user interface using FXML--the XML-based language created specifically for JavaFX to express user interfaces. This presents us with another binary choice--do we write the XML by hand, or do we use a graphical tool? Again, the choice is a simple one--we'll use a tool, Scene Builder, which is a WYSIWYG tool originally developed by Oracle and now maintained and supported by Gluon. We will, however, also be looking at the XML source so that we can understand what's being done, so if you don't like using a GUI tool, you won't be left out.

Installing and using Scene Builder is, as you would expect, pretty straightforward. It can be downloaded from http://gluonhq.com...

Initializing the user interface

While the FXML defines the structure of the user interface, we do need some Java code to initialize various elements, respond to actions, and so forth. This class, referred to as the controller, is simply a class that extends javafx.fxml.Initializable:

    public class Controller implements Initializable { 
      @FXML 
      private TableView<ProcessHandle> processList; 
      @Override 
      public void initialize(URL url, ResourceBundle rb) { 
      } 
    } 

The initialize() method comes from the interface, and is used by the JavaFX runtime to initialize the controller when it is created in the call to FXMLLoader.load() from the preceding Application class. Note the @FXML annotation on the instance variable processList. When JavaFX initializes the controller, before the initialize() method is called, the system looks for FXML elements...

Adding menus

Menus in JavaFX start with a component called MenuBar. We want this menu to be at the top of the window, of course, so we add the component to the top section of our BorderPane. If you use Scene Builder, you will end up with something like this in your FXML file:

    <MenuBar BorderPane.alignment="CENTER"> 
      <menus> 
        <Menu mnemonicParsing="false" text="File"> 
          <items> 
            <MenuItem mnemonicParsing="false" text="Close" /> 
          </items> 
        </Menu> 
        <Menu mnemonicParsing="false" text="Edit"> 
          <items> 
            <MenuItem mnemonicParsing="false" text="Delete" /> 
          </items> 
        </Menu> 
        <Menu mnemonicParsing="false&quot...

Creating a project


Typically speaking, it is much better if a build can be reproduced without requiring the use of a specific IDE or some other proprietary tool. Fortunately, NetBeans offers the ability to create a Maven-based JavaFX project. Click on File | New Project and select Maven, then JavaFX Application:

Next, perform the following steps:

  1. Click on Next.
  2. Enter Project Name as ProcessManager.
  3. Enter Group ID as com.steeplesoft.
  4. Enter Package as com.steeplesoft.processmanager.
  5. Select Project Location.
  6. Click on Finish.

Consider the following screenshot as an example:

Once the new project has been created, we need to update the Maven pom to use Java 9:

    <build> 
      <plugins> 
        <plugin> 
          <groupId>org.apache.maven.plugins</groupId> 
          <artifactId>maven-compiler-plugin</artifactId> 
          <version>3.6.1</version> 
          <configuration> 
            <source>9</source> 
            <target...

Bootstrapping the application


As noted in the introduction, this will be a JavaFX-based application, so we'll start by creating the skeleton for the application. This is a Java 9 application, and we intend to make use of the Java Module System. To do that, we need to create the module definition file, module-info.java, which resides in the root of our source tree. This being a Maven-based project, that would be src/main/java:

    module procman.app { 
      requires javafx.controls; 
      requires javafx.fxml; 
    } 

This small file does a couple of different things. First, it defines a new procman.app module. Next, it tells the system that this module requires two JDK modules: javafx.controls and javafx.fxml. If we did not specify these two modules, then our system, which we'll see below, would not compile, as the JDK would not make the required classes and packages available to our application. These modules are part of the standard JDK as of Java 9, so that shouldn't be an issue. However...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • See some of the new features of Java 9 and be introduced to parts of the Java SDK
  • This book provides a set of diverse, interesting projects that range in complexity from fairly simple to advanced and cover HTTP 2.0
  • Take advantage of Java's new modularity features to write real-world applications that solve a variety of problems

Description

Java is a powerful language that has applications in a wide variety of fields. From playing games on your computer to performing banking transactions, Java is at the heart of everything. The book starts by unveiling the new features of Java 9 and quickly walks you through the building blocks that form the basis of writing applications. There are 10 comprehensive projects in the book that will showcase the various features of Java 9. 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 a few. The book covers various libraries and frameworks in these projects, and also introduces a few more frameworks that complement and extend the Java SDK. Through the course of building applications, this book will not only help you get to grips with the various features of Java 9, but will also teach you how to design and prototype professional-grade applications with performance and security considerations.

Who is this book for?

This book is for Java developers who are already familiar with the language. Familiarity with more advanced topics, such as network programming and threads, would be helpful, but is not assumed.

What you will learn

  • Learn how to package Java applications as modules by using the Java Platform Module System
  • Implement process management in Java by 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
  • Learn to use JavaFX to build rich GUI based applications, which are an essential element of application development
  • Write microservices in Java using platform libraries and third-party frameworks
  • Integrate a Java application with MongoDB to build a cloud-based note taking application

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781786464446
Vendor :
Oracle
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Billing Address

Product Details

Publication date : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781786464446
Vendor :
Oracle
Category :
Languages :

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 $ 147.97
Java 9 Programming By Example
$48.99
Java 9 Data Structures and Algorithms
$43.99
Java 9 Programming Blueprints
$54.99
Total $ 147.97 Stars icon

Table of Contents

12 Chapters
Introduction Chevron down icon Chevron up icon
Managing Processes in Java Chevron down icon Chevron up icon
Duplicate File Finder Chevron down icon Chevron up icon
Date Calculator Chevron down icon Chevron up icon
Sunago - A Social Media Aggregator Chevron down icon Chevron up icon
Sunago - An Android Port Chevron down icon Chevron up icon
Email and Spam Management with MailFilter Chevron down icon Chevron up icon
Photo Management with PhotoBeans Chevron down icon Chevron up icon
Taking Notes with Monumentum Chevron down icon Chevron up icon
Serverless Java Chevron down icon Chevron up icon
DeskDroid - A Desktop Client for Your Android Phone Chevron down icon Chevron up icon
What is Next? Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Joseph Ottinger Aug 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is amazingly ambitious. It walks through a number of sample applications, leveraging APIs being offered by the upcoming Java 9 release (still upcoming as of when this review's being written!). As such, it has a lot of ground to cover, and it does a really good job of presenting a lot of programming approaches that look entirely appropriate for Java 9. (Time will tell how idiomatic they become, but there's nothing in the projects that suggests that they wouldn't serve as valid, workable blueprints.)The first edition has a few editorial difficulties - arrows get lost in translation sometimes, etc - but the actual content and sample code seems to be quite valid. Well done by the author, and I'm glad I bought this book. Recommended.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.