Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
What is a Java package?


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Advertisement
XyzWs Java FAQ: What is a Java package?

What is a Java package?


A Java package is a mechanism for organizing a set of related classes and interfaces into namespaces. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes and interfaces, it makes sense to keep things organized by placing related classes and interfaces into packages.

Java source files belonging to the same category or providing similar functionality can include a package statement at the top of the file to designate the package for the classes the source file defines.

Java packages can be stored in compressed files called JAR files. A JAR file can maintain its own directory structure, and Java follows exactly the same rules as for searching in ordinary directories. Specifically, `directory name = package name'.

  • A package provides a unique namespace for the types it contains.
  • A package facilitates access protection.
  • A package can contain the following kinds of types:
    • Classes
    • Interfaces
    • Enumerated types
    • Annotations

The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", or "API" for short. Its packages represent the tasks most commonly associated with general-purpose programming. For example, a String object contains state and behavior for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify a file on the file system; a Socket object allows for the creation and use of network sockets; various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. There are literally thousands of classes to choose from. This allows developers to focus on the design of their particular application, rather than the infrastructure required to make it work.


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help