Java Package: From Wikipedia, The Free Encyclopedia
Java Package: From Wikipedia, The Free Encyclopedia
http://en.wikipedia.org/wiki/Java_package
Java package
From Wikipedia, the free encyclopedia
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed les called JAR les, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality. A package provides a unique namespace for the types it contains. Classes in the same package can access each other's package-access members.
Contents
1 2 3 4 5 6 7 8 Overview Using packages Package access protection Creation of JAR les Package naming conventions Core packages in Java SE 6 References External links
Overview
In general, a package can contain the following kinds of types. Classes Interfaces Enumerated types
Using packages
In a Java source le, the package that this le's class or classes belong to is specied with the package keyword. This keyword is usually the rst keyword in source le.
[1]
package java.awt.event;
1 de 5
12/08/11 18:53
http://en.wikipedia.org/wiki/Java_package
To use a package's classes inside a Java source le, it is convenient to import the classes from the package with an import declaration. The following declaration import java.awt.event.*; imports all classes from the
java.awt.event
import java.awt.event.ActionEvent; imports only the ActionEvent class from the package. After either of these import declarations, the ActionEvent class can be referenced using its simple class name: ActionEvent myEvent = new ActionEvent(); Classes can also be used directly without an import declaration by using the fully qualied name of the class. For example, java.awt.event.ActionEvent myEvent = new java.awt.event.ActionEvent does not require a preceding import declaration. Note that if you do not use a package declaration, your class ends up in an [2][3] unnamed package.
2 de 5
12/08/11 18:53
http://en.wikipedia.org/wiki/Java_package
compresses all .class les into the JAR le myPackage.jar. The ' c ' option on the command line tells the jar command to "create new archive." The ' f ' option tells it to create a le. The le's name comes next before the contents of the JAR le.
basic language functionality and fundamental types collection data structure classes
3 de 5
12/08/11 18:53
http://en.wikipedia.org/wiki/Java_package
java.io (http://download.oracle.com/javase/6/docs /api/java/io/package-summary.html) java.math (http://download.oracle.com/javase/6/docs /api//java/math/package-summary.html) java.nio (http://download.oracle.com/javase/6/docs /api/java/nio/package-summary.html) java.net (http://download.oracle.com/javase/6/docs /api/java/net/package-summary.html) java.security (http://download.oracle.com/javase /6/docs/api/java/security/package-summary.html) java.sql (http://download.oracle.com/javase/6/docs /api/java/sql/package-summary.html) java.awt (http://download.oracle.com/javase/6/docs /api/java/awt/package-summary.html) javax.swing (http://download.oracle.com/javase /6/docs/api/javax/swing/package-summary.html) java.applet (http://download.oracle.com/javase /6/docs/api/java/applet/package-summary.html)
le operations multiprecision arithmetics the New I/O framework for Java networking operations, sockets, DNS lookups, ... key generation, encryption and decryption Java Database Connectivity (JDBC) to access databases basic hierarchy of packages for native GUI components hierarchy of packages for platform-independent rich GUI components classes for creating an applet
The java.lang (http://download.oracle.com/javase/6/docs/api/java/lang/package-summary.html) package is available without the use of an import statement.
References
1. ^ http://java.sun.com/docs/books/tutorial/java/package/managingles.html 2. ^ http://java.sun.com/docs/books/tutorial/java/package/createpkgs.html 3. ^ http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#26639
External links
Java SE 6 API Javadocs (http://download.oracle.com/javase/6/docs/api/) Java Language Specication, 3rd Edition, Chapter 7: Packages (http://java.sun.com/docs/books/jls/third_edition/html/packages.html) Code Conventions for the Java Programming Language, Chapter 9: Naming conventions (http://java.sun.com/docs/codeconv /html/CodeConventions.doc8.html) (mentions packages) Sun's "Java Tutorials" Lesson: Packages (http://java.sun.com/docs/books /tutorial/java/package/index.html) Retrieved from "http://en.wikipedia.org/wiki/Java_package" Categories: Java programming language This page was last modied on 28 June 2011 at 15:29.
4 de 5 12/08/11 18:53
http://en.wikipedia.org/wiki/Java_package
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. See Terms of use for details. Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-prot organization.
5 de 5
12/08/11 18:53