Professional Documents
Culture Documents
PACKAGE
• Java package is used to categorize the classes and interfaces so that they can be easily
maintained.
• Java package provides access protection. 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.
• Java package removes naming collision (namespace management) For example there
can be two classes with name Student in two packages, college.students.cse.Student and
college.students.ee.Student
PACKAGE KEYWORD
• If a package statement is not used then the class, interfaces, enumerations, and annotation types will be
placed in the current default package, which has no name.
• To compile the Java programs with package statements, you have to use -d option as shown below. javac
-d Destination_folder file_name.java
• This is the general form of the package statement:
package pkg;
Here, pkg is the name of the package.
• For example, the following statement creates a package called MyPackage:
package myPackage;
IMPORTING PACKAGE
• import keyword is used to import built-in and user-defined packages into your
java source file so that your class can refer to a class that is in another package
by directly using its name.
• There are three ways to access the package from outside the package.
1. fully qualified name.
2. import packagename.classname
3. import packagename.*;