CHAPTER 14

image

Packages and Import

Packages are used to avoid naming conflicts and to organize code files into different directories. So far in this book the code file has been located at the root of the project’s source directory. Therefore, it has belonged to the so called default package. In Java, the directory a file belongs to, relative to the project’s source directory, corresponds to the package name.

To assign a code file to a package, for example “mypackage”, it must be moved to a folder by that name, under the project directory. Furthermore, the file must specify which package it belongs to by using the package keyword followed by the ...

Get Java Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.