Packages In Java
Chapter:
Miscellaneous
Last Updated:
24-03-2017 04:25:21 UTC
Program:
/* ............... START ............... */
package com.reallybigindex.java.maths.formulas;
public class Area {
/**
* calculate the area of Rectangle
* */
public double calculateArea(double width, double height){
double area = width*height;
return area;
}
/**
* calculate the area of Square
* */
public double calculateArea(double side){
double area = side*side;
return area;
}
}
/* ............... END ............... */
Notes:
-
A package is a namespace that organizes a set of related classes and interfaces. Java packages can be stored in compressed files called JAR files.
- 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.
- Java package is used to categorize the classes and interfaces so that they can be easily maintained.
- Java package provides access protection.
- Java package removes naming collision.
- Advantages of using a package
- Reusability: Reusability of code is one of the most important requirements in the software industry. Reusability saves time, effort and also ensures consistency. A class once developed can be reused by any number of programs wishing to incorporate the class in that particular program.
- Easy to locate the files.
Tags
Packages, Java, Miscellaneous