What are the Advantages of using packages in java ?



What is Java Package ?

  • A java package is a group of similar types of classes, interfaces and sub-packages.
  • Package in java can be categorized in two form, built-in package and user-defined package.
  • There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.

Example of java package

//save as Simple.java  
	package mypack;  
	 public class Simple
       {  
	    public static void main(String args[])
           {  
	         System.out.println("Welcome to java package");  
	       }  
	   }  

How to access package from another package

  • import package.*;
  • import package.classname;
  • Fully qualified name.

What are the Advantages of using packages in java ?

  • Java package is used to categorize by the classes and interfaces.
  • It is easy to maintained.
  • Java package is provide as access protection.
  • It may removes naming collision.
  • This packages can be provide reusability of code.
  • We can create our own package or extend already available package.

Related Searches to What are the Advantages of using packages in java ?