NestedPackages
DRAFT

Misconception:

A package (like java.awt) can contain other packages (like java.awt.event).

Incorrect

Packages can contain other packages

Correct

Correction
Here is what's right.

In Java, packages cannot cannot be nested. All packages are top-level packages. Package java.awt and package java.awt.event are both top-level packages. Package java.awt.event is not inside package java.awt.

This may sound strange, especially because package names consist of various pieces (“java”, “awt”, “event”) that seem to represent a path in a tree, and because in the file system, directories that represent packages indeed are nested (e.g., there will be a directory “awt” that contains a file “Component.java” and also contains a subdirectory “event”). Nevertheless, the Java language treats each package as a separate entity that is not related to any other package (e.g., there are no privileged access permissions between the classes in java.awt and the classes in java.awt.event).

Language

Java

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.