Search code examples
javajava-9java-module

Java module glossary


What is the difference between all these terms used in the Java module specification? I can't find a definition of these terms that doesn't circularly reference itself.

  • Visible
  • Observable
  • Accessible

The spec makes such statements as this, but I have not yet figured out what these words actually mean:

Specifically, the host system must limit the ordinary compilation units that would otherwise be observable, to only those that are visible to M

(JLS 11 section 7.3 p.183)


Solution

  • First, in JLS terms like visibility may have different meaning when applied to a compilation unit, or a package, or a type.

    Some references where terms are defined in JLS:

    • Observable:

      • Compilation unit: §7.3, sentence starting "The host system determines which compilation units are observable".

      • Package: §7.4.3, first paragraph.

      • Intuition: elements that participate in compilation.

    • Visible:

      • Compilation unit: §7.3, sentence starting "The ordinary compilation units that are visible to M" - note that visibility is defined relative to a module

      • Package: §7.4.3, sentence starting "A package is visible to a module M" - again relative to a module.

      • Intuition: elements that are observable from the perspective of a given module considering requires and exports.

    • Accessible:

      • General definition: §6.6

    Additionally, the central new notion since JLS 9 is "uniquely visible" (§7.4.3), plus the terms "potentially accessible", "reads" / "read by", "associated with". Historically, JLS 9 made a further distinction between "technically observable" and "really observable", which has been dropped as of JLS 11.

    Also, historically (up-to JLS 8), "visible" was used in the definition of shadowing (§6.4.1), but this use has been withdrawn in JLS 9.

    Finally note, that some of these notions (explicitly or implicitly) pull in definition from the API in java.lang.module.

    I suggest to consider these terms as technical terms, not meant to appeal to the intuition of a broader audience, in part because many definitions in JLS reason about "compilation units", which are not necessary for an intuitive understanding. For a comparison of a possible intuitive understanding vs. the JLS-based understand please see Slide #20 of JDT embraces Java™ 9 - An insiders' view.