Introduction to working with packages and interfaces
Although classes are the centerpiece of object-oriented programming in Java, there are some other useful OOP features included in Java.
One of these features involves packages, which are used to organize classes into functionally-related groups. Interfaces are also an important part of Java's OOP support, and allow you to define the structure of classes.
This module discusses packages and interfaces, and also shows you how to control access to members of a class.
Packages are containers for classes. They are used to keep the class name space compartmentalized. For example, a package allows you to create a class named List, which you can store in your own package without concern that it will collide with some other class named List stored elsewhere.
Packages are stored in a hierarchical manner and are explicitly imported into new class definitions.
In previous modules of this website, you have seen how methods define the interface to the data in a class.
Through the use of the interface keyword, Java allows you to fully abstract an
interface from its implementation. Using interface, you can specify a set of methods that can be implemented by one or more classes. The interface, itself, does not actually define any implementation. Although they are similar to abstract classes, interfaces have an additional capability, namely a class can implement more than one interface.
Module Learning Objectives
After completing the module, you will have the skills and knowledge necessary to:
- Understand how packages are used to organize Java classes
- Organize classes into packages
- Control access to class members
- Create interfaces that define the structure of classes