---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 23 Edition"
java_version: 23
chapter: "Chapter 7. Packages and Modules"
section: "7.1"
heading: "7.1. Package Members"
parent: "Chapter 7. Packages and Modules"
source: https://docs.oracle.com/javase/specs/jls/se23/html/jls-7.html#jls-7.1
id: "7.1"
url: https://jvm.obfuscated.software/jls/se23/7.1.html
raw: https://jvm.obfuscated.software/jls/se23/7.1.md
---

# 7.1. Package Members

The members of a package are its subpackages and all the top level classes ([§8 (*Classes*)](8.md)) and top level interfaces ([§9 (*Interfaces*)](9.md)) declared in all the compilation units ([§7.3](7.3.md)) of the package.

For example, in the Java SE Platform API:

- The package `java` has subpackages `awt`, `applet`, `io`, `lang`, `net`, and `util`, but no compilation units.
- The package `java.awt` has a subpackage named `image`, as well as a number of compilation units containing declarations of classes and interfaces.

If the fully qualified name ([§6.7](6.7.md)) of a package is `P`, and `Q` is a subpackage of `P`, then `P.Q` is the fully qualified name of the subpackage, and furthermore denotes a package.

A package may not contain two members of the same name, or a compile-time error results.

Here are some examples:

- Because the package `java.awt` has a subpackage `image`, it cannot (and does not) contain a declaration of a class or interface named `image`.
- If there is a package named `mouse` and a member class `Button` in that package (which then might be referred to as `mouse.Button`), then there cannot be any package with the fully qualified name `mouse.Button` or `mouse.Button.Click`.
- If `com.nighthacks.java.jag` is the fully qualified name of a class, then there cannot be any package whose fully qualified name is either `com.nighthacks.java.jag` or `com.nighthacks.java.jag.scrabble`.

It is however possible for members of different packages to have the same simple name. For example, it is possible to declare a package:

```
package vector;
public class Vector { Object[] vec; }
```

that has as a member a `public` class named `Vector`, even though the package `java.util` also declares a class named `Vector`. These two classes are different, reflected by the fact that they have different fully qualified names ([§6.7](6.7.md)). The fully qualified name of this example `Vector` is `vector.Vector`, whereas `java.util.Vector` is the fully qualified name of the `Vector` class included in the Java SE Platform. Because the package `vector` contains a class named `Vector`, it cannot also have a subpackage named `Vector`.

The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level class or interface ([§7.6](7.6.md)) declared in that package.

For example, there is no special access relationship between a package named `oliver` and another package named `oliver.twist`, or between packages named `evelyn.wood` and `evelyn.waugh`. That is, the code in a package named `oliver.twist` has no better access to the classes and interfaces declared within package `oliver` than code in any other package.
