What Is an Unnamed Package?

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:

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:

Let's do some tests to answer these questions and to confirm my guess in next sections.

Table of Contents

 About This JDK Tutorial Book

 JDK (Java Development Kit)

 Java Date-Time API

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

Calling and Importing Classes Defined in Unnamed Packages

What Is an Unnamed Package?

 One Class in an Unnamed Package - Hello.java

 Two Classes in Unnamed Packages - Hello.java and CallingHello.java

 Importing Classes Defined in Unnamed Packages

 Importing Classes from Unnamed to Named Packages

 Importing Classes from Unnamed to Named Packages - JDK 1.4.1

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Java Logging

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials

 References

 Full Version in PDF/EPUB