OnlyRuntimeLibraryPackagesDRAFT
Only the creators of the JDK can create packages
Normal developers can create packages
CorrectionHere is what's right.
Every developer can place any class in a package.
While the Java runtime library that is part of the JDK
consists of classes that are placed in packages
like java.lang
or java.util
.
However, developers can place their own classes in packages as well.
For example, the following source code,
to be stored in a file OnlyRuntimeLibraryPackages.java
in a subdirectory org/progmiscon/misconception/java
,
defines a class with the fully-qualified name
org.progmiscon.misconception.OnlyRuntimeLibraryPackages
:
package org.progmiscon.misconception;
public class OnlyRuntimeLibraryPackages {
//...
}
All that is needed to put a class in a package is
to put a package declaration at the top of the Java source file
(e.g., package org.progmiscon.misconception;
)
and place the source file in a subdirectory
that corresponds to the package’s name
(e.g., org/progmiscon/misconception
).
ValueHow can you build on this misconception?
This misconception provides an opportunity to discuss the ideas of modularity, hierachical name spaces, and separate compilation.