packages and imports
A way of organising interfaces and classes, to avoid conflicts. Similar to directories. Logically group similar items together. Applying access restriciton to the package.
Package names are in lowercase and cannot start with special character or digit. Can have _ in the name.
Any class in a package can access anything in other classes that is not private
defined
static imports
import one
import all
Imports all classes from this package
not good if only need to import up to 2 or 3 classes
Same class conflicts
Use fully qualified name
When another import has same Class name and thus conflict
class path
libraries/classes that accessible
Advantages
define their own packages to bundle a group of classes/interfaces
package creates a new namespace there won't be any name conflicts with names in other packages
removes naming collision
it is easier to provide access control
easier to locate the related classes.
Understand the structure of the app, screaming architecture
Last updated
Was this helpful?