Packages and Interfaces  «Prev  Next»

Lesson 8

Java Packages and Interfaces Conclusion

This module explored packages, access modifiers, and interfaces. You began the module by learning about packages and how they allow you to organize Java classes into functional groups. From there you learned about access modifiers which provide a means of controlling access to classes, member variables, and methods. Finally, you wrapped up the module by taking a look at interfaces, which provide a means of defining the general design for a class without getting into the details of an implementation.

Java Packages from Java 1.1 to Java 17: A Consistency Review

Java packages have been integral to the language since its early versions. They provide a namespace mechanism to organize classes and interfaces, ensuring modular structure and avoiding name clashes. Let's evaluate the consistency of the concept of Java packages from Java 1.1 to Java 17.
  1. Basic Purpose: From Java 1.1 to Java 17, the fundamental purpose of packages has remained unchanged. They serve to group related classes and interfaces, providing a namespace mechanism that ensures no two members have the same name.
  2. Directory Structure: The way in which the directory structure mirrors package hierarchy has remained consistent. A class declared in the package `com.example.module` is expected to reside in a directory path corresponding to `com/example/module/`.
  3. Package Declaration and Usage: The syntax for declaring a package within a Java source file (`package com.example.module;`) and the syntax for importing classes/interfaces from other packages (`import com.example.module.ClassName;`) have been consistent across versions.
  4. Package-Private Visibility: The concept of package-private visibility, where a class or member without any access modifier is accessible only within its own package, has been steadfast from Java 1.1 to Java 17.
  5. Archiving and Distribution: Java Archive (JAR) files, introduced early in Java's evolution, are used to bundle related classes in packages for distribution. This concept and its application haven't seen a fundamental shift in purpose or structure across the versions.
  6. Enhancements:
    1. Annotations: With the introduction of annotations in Java 5, packages can now be annotated using a special file named `package-info.java`. This was an enhancement to provide metadata about the package.
    2. Java Platform Module System (JPMS): Java 9 introduced the Java Platform Module System (JPMS) with the concept of modules, bringing a higher level of organization above packages. While this altered the modular landscape of Java, the intrinsic concept and structure of packages within these modules remained consistent. Each module can contain multiple packages, and the `module-info.java` file defines module directives (like `requires`, `exports`, etc.). Yet, packages inside these modules still retain their original purpose and structural characteristics.


From Java 1.1 to Java 17, the essential concept, structure, and purpose of Java packages have remained consistent. While there have been enhancements in the broader landscape, such as the introduction of annotations and the JPMS, the foundational role of packages as a mechanism for namespace organization and modularization in the Java language has been unwavering.

Glossary Terms

This module discussed how the following terms relate to Java:
  1. Package: A package is a collection of reusable classes and interfaces.
  2. Interface: An interface is a set of methods that Java classes can implement.
  3. Access modifier: Access modifiers define different levels of access for class members including private, protected, public, and a default access level.

Packages Interfaces - Quiz

Click the Quiz link below to test what was discussed in this module.
Packages Interfaces - Quiz