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.
Most Recent java Faqs
- How to uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- What are class variables in Java?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- What are local variables in Java?
- How to Use Updatable ResultSet in JDBC?
- How to Use JDBC Java to Create Table?
- Why final variable in Enhanced for Loop does not act final?