Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Modular Programming in Java 9
  • Table Of Contents Toc
  • Feedback & Rating feedback
Modular Programming in Java 9

Modular Programming in Java 9

By : Kothagal
4.5 (2)
close
close
Modular Programming in Java 9

Modular Programming in Java 9

4.5 (2)
By: Kothagal

Overview of this book

The Java 9 module system is an important addition to the language that affects the way we design, write, and organize code and libraries in Java. It provides a new way to achieve maintainable code by the encapsulation of Java types, as well as a way to write better libraries that have clear interfaces. Effectively using the module system requires an understanding of how modules work and what the best practices of creating modules are. This book will give you step-by-step instructions to create new modules as well as migrate code from earlier versions of Java to the Java 9 module system. You'll be working on a fully modular sample application and add features to it as you learn about Java modules. You'll learn how to create module definitions, setup inter-module dependencies, and use the built-in modules from the modular JDK. You will also learn about module resolution and how to use jlink to generate custom runtime images. We will end our journey by taking a look at the road ahead. You will learn some powerful best practices that will help you as you start building modular applications. You will also learn how to upgrade an existing Java 8 codebase to Java 9, handle issues with libraries, and how to test Java 9 applications.
Table of Contents (13 chapters)
close
close

What this book covers

Chapter 1, Introducing Java 9 Modularity, covers the status quo of code structuring and management in Java 8 and before. It outlines the challenges and pitfalls in maintaining and organizing large code bases over time, with the example of a large Java code base everyone is familiar with--the JDK. It then introduces Project Jigsaw and explains how the concept of modularity attempts to solve the challenges outlined in the previous chapter. It discusses the module-based changes to the JDK structure as well as the ability to create modules in application code.

Chapter 2, Creating Your First Java Module, gets you started on a sample code project that is written without using the module construct. It then guides you step-by-step through creating your first Java 9 module. It introduces you to the module keyword, the module-info.java class and how to define a custom Java module. It then covers compiling and running a module. It explains the structure of the .class files and how the runtime uses the same module definition to infer the module structure.

Chapter 3, Handling Inter-Module Dependencies, shows how modules can hardly work well in isolation. They are designed to be parts of a bigger unit and are meant to work with each other. This chapter covers creating a second module and having the modules depend on each other. You'll learn how to define such a relationship in Java 9, as well as how to compile and run a multi-module application.

Chapter 4, Introducing the Modular JDK, switches our attention to the Java platform, specifically the JDK. You'll learn about the important changes to the JDK that has resulted from the modularization of the platform. You'll learn about the modules that come out of the box with the JDK. You'll also learn about the tools and techniques to browse and get more information about any of those modules.

Chapter 5, Using Platform APIs, teaches you how to use the platform modules in the sample application through a hands-on step-by-step guide. You'll understand some of the challenges that you may typically face when depending on platform modules and how to solve them.

Chapter 6, Module Resolution, Readability, and Accessibility, delves deep into inter-module dependencies and how you can control the level of encapsulation for their modules and libraries. It continues the module resolution discussion of the previous chapter by adding two new criteria that influences the encapsulation and availability of Java elements--accessibility and readability.

Chapter 7, Introducing Services, looks at a vital element of coupling that exists between two modules in the sample application and how that prevents the extensibility and "plugging-in" of new modules. It explains the new Java 9 services, provides step-by-step instructions to encapsulate implementation classes, and uses ServiceLoader to look them up.

Chapter 8, Understanding Linking and Using jlink, introduces the static linking step in the Java 9 development process and what happens during it. It explains how linking plays an important part when developing modules in Java 9. It then provides step-by-step instructions to create a runtime image for the sample project, how to optimize it, and how to execute the image.

Chapter 9, Module Design Patterns and Strategies, covers several best practices when it comes to building modular applications in Java. Now that you have a good understanding of the Java module system features and how it works, the next question is when and how to use them? You'll learn how to establish module scopes and boundaries, how to define good module interfaces, and how to tackle some common challenges when building a modular application.

Chapter 10, Preparing Your Code for Java 9, walks you through getting an old sample code base (written in Java 7) ready to be migrated to Java 9. It illustrates the optional nature of Java modules and how a classpath-based code is automatically assigned to an "unnamed" module. It then provides step-by-step instructions to get legacy code to compile and run in Java 9. It also shows you how to handle issues with usage of encapsulated types, and how to work around them.

Chapter 11, Migrating Your Code to Java 9, walks you through upgrading legacy code to use the new modularity features of Java 9. You'll learn how to form a migration strategy for your code, as well as how to deal with dependencies that are not compatible with Java 9. You'll learn how to use Java 9 features that are designed to assist such migration, such as automatic modules and command-line overrides.

Chapter 12, Using Build Tools and Testing Java Modules, covers two important aspects of Java programming--build tool integration and unit testing. You'll learn to use Maven to structure your projects and align Maven's multi-module project concepts with Java 9 modular applications. You'll also learn how to test Java modules using JUnit.

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY