Author: Amanda Tissot

  • Creating JAR Files – Java Module System

    19.7 Creating JAR Files A JAR (Java Archive) file is a convenient way of bundling and deploying Java executable code and any other resources that are required (e.g., image or audio files). A JAR file is created by using the jar tool. The jar command has many options, akin to…

  • Running an Application from a Modular JAR – Java Module System

    Running an Application from a Modular JAR The adviceApp application can be run from the modular JARs in the mlib directory by any of the following java commands, giving the same output as before: Click here to view code image >java –module-path mlib –module main or Click here to view…

  • Open Modules and the opens Directive – Java Module System

    19.8 Open Modules and the opens Directive Reflection is a powerful feature in Java that enables inspection and modification of runtime behavior of Java programs. The Reflection API is primarily in the java.lang.reflect package. Reference types (classes, interfaces, and enums) can be inspected at runtime to access information about the…

  • Qualified Opens Directive – Java Module System

    Qualified Opens Directive Sometimes it is necessary that only certain modules can access an open package for reflection. This can be achieved by using the opens-to directive, as shown below at (1), where package org.liberal.sesame in module org.liberal is only open to modules com.aladdin and forty.thieves. This is known as…

  • Making the Case for Modules – Java Module System

    19.1 Making the Case for Modules We begin by briefly examining the issues that modules address and the benefits they provide. Stronger Encapsulation Modules in Java provide a new level of encapsulation above packages. Whereas a package encapsulates classes and interfaces, a module encapsulates a set of packages and any…

  • Services – Java Module System

    19.9 Services Programming to interfaces is a powerful design paradigm that advocates writing code using interfaces and abstract classes—that is, using abstract types and not concrete types. This allows new implementations of abstract types to be used by the code if and when necessary. This strategy results in the code…

  • Additional Support for Formatting in the Java SE Platform APIs – Localization

    Additional Support for Formatting in the Java SE Platform APIs In this subsection we mention additional support for formatting values that is provided by various classes in the Java SE Platform APIs. The class java.util.Formatter provides the core support for formatted text representation of primitive values and objects through its…

  • Specifying the Service Interface – Java Module System

    Specifying the Service Interface The service is represented by the interface IAdvice that is declared in package org.advice.si of the serviceinterface module (Example 19.3). It specifies the functionality that the service will provide: two abstract methods getContent() and getLocale() that return the advice (as a string) and the associated locale…

  • Implementing the Service Locator – Java Module System

    Implementing the Service Locator The class java.util.ServiceLoader<S>, where the type parameter S designates the type of service, is at the core of finding and loading service providers for the service S. A service loader for a specific service is created by calling the static method load() of the ServiceLoader class,…

  • Implementing the Service Consumer – Java Module System

    Implementing the Service Consumer The class AdviceConsumer implements a simple service consumer for the IAdvice service in the package org.advice.serviceconsumer of the serviceconsumer module (Example 19.6). The code at (1) shows how advice for the UK locale is obtained via the org.advice .servicelocator.AdviceLocator class in the servicelocator module. The static…