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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781786460196
Vendor :
Oracle
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781786460196
Vendor :
Oracle
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 $ 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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.