Packages And Imports
Packages give types a namespace and help organize a larger codebase. A package name conventionally reverses an owned domain, followed by project areas such as com.example.cli.
An import lets source code use a type's short name. It does not download a library or copy code into your class.
Source layout
The folder path normally mirrors the package:
src/
└── com/
└── example/
├── cli/
│ └── Command.java
└── reports/
└── PayrollReport.java
Command.java can begin like this:
package com.example.cli;
public class Command {
}
A class in another package can import it:
package com.example.reports;
import com.example.cli.Command;
public class PayrollReport {
private Command command;
}
Classes in the same package do not need to import one another. Two packages can also contain classes with the same short name because their fully qualified names differ.
A package declaration must come first, followed by imports and then type declarations. java.lang types such as String are imported automatically.
Avoid the unnamed default package for real projects. Build tools expect source folders to mirror package names.
Choose the line that brings LocalDate into scope in the question below.