Home Java Overview Maven Tutorials

Saturday, 14 January 2017

Package in java with example

For Video Tutorial : Move on Youtube Channel

Note : Select the playlist as per your need & move with number sequence

Package in java with example

Video for this tutorials : CLICK HERE

When we talk about the package means that we are talking about certain similar things.
Same is in java package, So java package is a collection of similer files, classes, methods etc.
In java , there s two type of package :
1) Built-in package such as java, lang, awt, javax , swing, net, io, etc.
2) User defined package.

Advantage of Java package

1. It removes the naming collision.
2. It provides access protection.
3. Effective way to maintain classes and interface.
Note : It is good practice to give package name in small letter. Example : In below example we have created a package & inside it there is a class then we have created another class in another package and then we imported the package and accessed the class.
package csc_pack; public class Chandan1
public void sum(int a, int b)
System.out.println("Your sum is :" +(a+b));
Now import this package in another class :
import csc_pack.Chandan1;
public class Mainclas
public static void main(String args[])
Chandan1 obj = new Chandan1();
Output :
Your sum is :7

1 comment:

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.