0
7.8kviews
Short note on Packages.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 5 M

Year: Dec 2013, Dec 2014

1 Answer
1
284views
  • Package is Java’s way of grouping the classes and interfaces together. That is, a package is called as the collection of classes and interfaces.
  • It can be called as the container for classes that is used to keep the class name space compartmentalized.
  • Packages are stored in a hierarchical manner and are explicitly imported into new class definitions.
  • By organizing the classes and interfaces into packages we can achieve the following goals:
  • Classes contained in packages of other programs can be easily reused.
  • Two classes in two different packages can have same name but they should be referred by their fully qualified name.
  • Packages provide a way of hiding classes. So we can prevent them from accessing outside.
  • Packages provide a way of separating ‘design’ from ‘coding’.
  • To create a package, include a package command as the first statement in a Java source file.
  • This is the general form of the package statement:

    package pkg;

    Here, pkg is the name of the package.

  • Fig. below shows the fundamental packages that are frequently used in a Java program.

enter image description here

  • The classes that are included in these packages are:
  • java.lang – Language support classes such as System, Thread, Exception,etc.
  • java.util – Utility classes such as Vector, Arrays, LinkedList, Stack,etc.
  • java.io – Input output support classes such as BufferedReader,InputStream
  • java.awt – Classes using GUI such as Window, Frame, Panel,etc.
  • java.applet – Classes for creating and implementing applets.
Please log in to add an answer.