Wildcards Flashcards
What is the purpose of an import statement ?
Import statements tell Java which packages to look in for classes
What is the purpose of packages ?
Containment: Packages serve as containers for classes, interfaces, and sub-packages, helping to group related functionalities together.
Organization: They provide a structured way to manage and organize code, making it easier to locate and use classes, especially in larger applications.
Namespace Management: Packages help avoid naming conflicts by providing a namespace for classes. For instance, you can have classes with the same name in different packages.
Define the following sentence “ Package names are hierarchical” !
The sentence “Package names are hierarchical” means that Java package names are structured in a nested manner, similar to a directory structure in a file system.
Hierarchy:
Package names are composed of multiple components separated by dots (.). For example, in the package name com.example.project, com is the top-level package, example is a sub-package within com, and project is a sub-package within example.
Organization:
This hierarchical structure helps organize classes and interfaces logically, making it easier to manage and locate related components.
Namespace Management:
The hierarchy also helps avoid naming conflicts by allowing packages with the same name to coexist in different levels of the hierarchy.
Define the rules for package names !
The rule for package names is that they are mostly letters or numbers separated by dots. Technically, you’re allowed a couple of other characters between the dots. The rules are the same as for variable names
What is a Wildcard ?
an asterisk wildcard (*) is used to import all classes and interfaces from a specific package.
Give an important characteristic of the wildcard !
It doesn’t import child packages, fields, or methods; it imports only classes.