Welcome to Home.

Tuesday, August 2, 2016

Java Packages: keeping Classes together


Packages: Putting Classes together


Package is of the main features of OOP  (JAVA) is its ability to reuse the code already created. One way of achieving this by extending the classes and implementing the interfaces. This is limited to reusing the classes within a program. What if we need to use classes from other programs without physically copying them into the program under development? This can be accomplished in Java by using what is known as packages, a concept similar to “class libraries” in other languages. Another way of achieving the re-usability in java, therefore, is to use packages.
Packages are java’s way of grouping a variety of classes and interfaces together. The grouping is usually done according to functionality. In fact, packages act as “containers” for classes. By organizing our classes into packages we achieved the following benefits:
The classes contained in the packages of other programs can be easily reused.In packages, classes can be unique compared with classes in other packages. This is, two classes in two different packages can have the same name. they may be referred by their fully qualified name, comprising  the package  name and the class name.Packages provide a way to “hide” classes thus preventing other programs or packages from accessing classes that are meant for internal use only.Packages also provide a way for separating “design” from “coding”. First we can design classes and decide their relationships, and the n we can implement the Java code needed for the methods. It is possible to change the implementation of any method without affecting the  rest of the design.
For most applications, we will need to use to different sets of classes, one for the internal representation of our program’s data, and the other for external presentation purposes. We may have to build our own classes for handling our data and use existing class libraries for designing user interfaces. Java packages are therefore classified into two types. The first category is known as Java API packages and the second is known as user defined packages.




Package name
Contents
Java.lang
Language support classes. These are classes that java compiler itself uses and therefore they are automatically imported. They include classes for primitive types, strings, math functions, threads and exceptions.
Java.util
Language utility classes such as vectors, hash tables, random numbers, date etc.
Java.io
Input/output support classes. They provide facilities for the input and output of data.
Java.awt
Set of classes for implementing graphical user interface. They include classes  for windows, buttons, lists , menus and so on.
Java.net
Classes for networking. They include classes for communicating with local computers as well as with internet servers.
Java.applet
Classes for creating and implementing applets.





No comments:

Post a Comment