Zeek_64_JavaPackages(Understanding Encapsulation)

 

WHAT IS JAVA PACKAGE?


java package is a group of similar types of classes, interfaces and sub-packages.


Package in java can be categorized in two form:

 1-Built-in package 

 2-User-defined package

Built-in packages  include java, lang, awt, javax, swing, net, io, util, sql etc.

We will have the detailed learning of creating and using user-defined packages.


How to access package from another package?

There are three ways to access the package from outside the package.

  1. import package.*;
  2. import package.classname
  3. fully qualified name.

Advantage of Java Package

1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.

(Use Eclipse IDE or Intellij and you will understand)

2) Java package provides access protection.

(giving access by keywords like private,default,public,etc We get protection)

3) Java package removes naming collision.

(If you have used more than one same name it shows message )



Hierarchy of Package in Java





Comments

Popular posts from this blog

Zeek_31_MethodInJava.java