1//A java package is a group of similar types of classes, interfaces and sub-packages.
2
3Package in java can be categorized in two form, built-in package and user-defined package.
4
5There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
6
7Advantages Of Packages
8Java package is used to categorize the classes and interfaces so that they can be easily maintained.
9Java package provides access protection.
10Java package removes naming collision.
11Example
12//save as Simple.java
13package com.revature;
14public class Simple{
15 public static void main(String args[]){
16 System.out.println("Welcome to package");
17 }
18}
19
20Accessing a package from other packages
21There are three ways to access the package from outside the package.
22
23import package.*;
24import package.classname;
25fully qualified name.
1Package is a mechanism to group related classes ,interfaces and enums
2in to a single module.
3Package can be declared using the following statement :
4Syntax : package <package-name>
5Coding Convention : package name should be declared in small letters.
6package statement defines the namespace.
7The main use of package is
81) To resolve naming conflicts
92) For visibility control : We can define classes and interfaces that are
10not accessible outside the class
1// import <package> -> Imports the whole package
2// import <package>.<class> -> Imports a certain class
3import java.util.Scanner;
1//A java package is a group of similar types of classes, interfaces and sub-packages.
2
3Package in java can be categorized in two form, built-in package and user-defined package.
4
5There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
6
7Advantages Of Packages
8Java package is used to categorize the classes and interfaces so that they can be easily maintained.
9Java package provides access protection.
10Java package removes naming collision.
11Example
12//save as Simple.java
13package com.revature;
14public class Simple{
15 public static void main(String args[]){
16 System.out.println("Welcome to package");
17 }
18}