Custom packages:
- Java library is a collection of packages.
- A programmer can create custom package depends on application requirement.
- ‘package’ keyword is used to create the package.
- ‘package’ statement must be the first statement in the source file.
Structure:
- Package statements
- Import statements
- Classes
Syntax:
package <Identity> ;
Example:
package nit ;
Program code : Save the file on desktop
package nit;
import java.lang.*;
class First
{
public static void main(String[] args)
{
System.out.println("nit.First class main...");
}
}
Compile: We compile the above code using ‘–d’ command and by specifying the package creation location.
Syntax:
cmd:\> javac -d path sourcefile
Example:
cmd:\> javac -d …/desktop/ First.java
Run the file belongs to package: