This section describes what is an unnamed package - a package of compilation units with no package name. The main question is how to refer to a compilation unit in an unnamed package.
Unnamed packages contain compilation units (classes or interfaces)
that have no package declaration statement. For example, the following class is a compilation unit in
an unnamed package, Hello.java:
class Hello {
public static void main(String[] a) {
System.out.println("Hello world!");
}
}
There are a number of questions about unnamed packages we need to answer:
How many unnamed packages can JDK support?
How compilation units in each unnamed package are stored?
How to refer to the compilation units in unnamed packages?
Based on the documentation of JDK for Windows system, my guess is that JDK supports
multiple unnamed packages. Each unnamed package is stored in the top
directory of each class path specified in one of the following three ways:
-classpath path;path;...
set CLASSPATH=path;path;...
"current directory"
Let's do some tests to answer these questions and to confirm my guess
in next sections.