Packages

suggest change

Versions

Packages have been in the language since Java 1.0.

Introduction

A package in Java is used to group classes and interfaces. This helps developers avoid name conflicts when there are many classes. Classes and interfaces in different packages can have the same simple name.

Another class can import a type from a package.

There are many built-in packages in Java, such as

We can define our own user-defined packages.

Remarks

Packages provide access protection.

The package declaration must be the first statement in the source file. Comments may precede it, and a source file has at most one package declaration.

Packages can also avoid name conflicts between different parts of a program.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents