자바에서 패키지란
자바에서 패키지란 클래스들과 서브패키지들 그리고 인터페이스를 캡슐화하는 매커니즘입니다.
- Preventing naming conflicts. For example there can be two classes with name Employee in two packages, college.staff.cse.Employee and college.staff.ee.Employee
- Making searching/locating and usage of classes, interfaces, enumerations and annotations easier
- Providing controlled access: protected and default have package level access control. A protected member is accessible by classes in the same package and its subclasses. A default member (without any access specifier) is accessible by classes in the same package only.
- Packages can be considered as data encapsulation (or data-hiding).
자바에서 패키지(package)란 클래스와 인터페이스의 집합을 의미합니다.
이렇게 서로 관련이 있는 클래스나 인터페이스를 함께 묶음으로써 파일을 효율적으로 관리할 수 있게 됩니다.
또한, 협업 시 서로 작업한 클래스 사이에서 발생할 수 있는 이름 충돌 문제까지도 패키지를 이용하면 피할 수 있습니다.
자바에서 패키지는 물리적으로 하나의 디렉터리를 의미합니다.
따라서 하나의 패키지에 속한 클래스나 인터페이스 파일은 모두 해당 패키지 이름의 디렉터리에 포함되어 있습니다.
이러한 패키지는 다른 패키지를 포함할 수 있으며, 이때 디렉터리의 계층 구조는 점(.)으로 구분됩니다.
이름 없는 패키지(unnamed package)
자바의 모든 클래스는 반드시 하나 이상의 패키지에 포함되어야 합니다.