answersLogoWhite

0


Best Answer

Packages provide an alternative to creating procedures and functions as stand-alone schema objects, and they offer the following advantages:

  • Modularity: Logically related programming structures can be encapsulated in a named module. Each package is easy to understand, and the interface between packages is simple, clear, and well-defined.
  • Easier Application Design: Package specification and package body can be coded and compiled separately. A package specification can be coded and compiled without its body. Then, stored subprograms that reference the package can also be compiled. A user does not need to fully define the package body until he is ready to complete the application.
  • Hiding Information: The programming constructs declared in the package specification are public (visible and accessible to applications). The programming constructs declared in the package body are private (hidden and inaccessible to applications). The package body hides the definitions of the private constructs so that only the package is affected (not the application or any calling program) if the definitions change. This enables a user to change the implementation without having to recompile calling programs. Also, hiding the implementation details from users protects the integrity of the package.
  • Added Functionality: Packaged public variables and cursors persist for the duration of a session. In this way, they can be shared by all subprograms that execute in the calling environment. They also enable a user to maintain data across transactions without having to store it in the database. Private constructs also persist for the duration of the session, but can only be accessed within the package.
  • Better Performance: When a packaged subprogram is called for the first time, the entire package is loaded into the memory. As a result, later calls to related subprograms in the package do not require any further disk I/O. Packaged subprograms also stop cascading dependencies and thereby avoid unnecessary compilations.
  • Overloading: Procedures and functions, when used within a package, can be overloaded, i.e., multiple subprograms can be created with the same name in the same package, each taking different number of parameters or different types of parameters.
User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Packages serve one major purpose: they make code cleaner.

By that, I mean that packages allow for easy associations of similar-purpose code to be placed together, and avoid problems with name-space collisions between similarly-named objects and methods in completely different contexts.

Packages are analogous to libraries in C - it's a convenient way to describe a set of related objects and methods, and make it simple to use those objects and methods in the proper context.

Java could survive without packages, but it would be much messier.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the benefit of using package in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is it possible to draw in java without using applet?

Yes it is possible to draw in java by using AWT package. or by using javax package.


Supermost package of java?

The supermost package of Java is the "java" package.


How do you import an entire package of class in java?

import package_name.*;where package_name is your package name.by using this syntax you can import an entire package.


What is a collection of related classes called in java?

a package


What are the feature's of the Java 'this' installation package?

The Java 'this' installation package allows one to create installation programs for their Java based applications. One can download the program from Java.


Why we are not explicitly importing java.lang package?

Because, the java.lang package contains some of the most commonly used classes and utility functions of Java. As a result, almost all classes will be using some or all of those features. So, the creators of Java automatically imported this package in every class that you create to avoid the explicit import action for java developers


What is a default package in Java?

A default package is a package with no name. You can create a Java class without putting package name on top of the code. This class is included in the "default package". Be careful not to be confused with java.lang, which is a package that contains Java's fundamental classes and get's imported by default.


Which package is inbuilt in java API?

The java.lang package is automatically imported for you.


What is the library in java which does not need to be imported?

The java.lang package in Java is automatically imported for you.


What is user define package?

A user defined package is a package outside of the standard Java libraries.


Import a package second time in Java?

You can import a package as many times as you want in Java. The compiler will just ignore any duplicates.


How do you complie package in java?

You use javac <filename> to compile a class or package.