Transwiki:Packages in Java
From Wikibooks, the open-content textbooks collection
In the Java programming language, a package is a group of related classes and interfaces. Packages in Java have a close correspondence to packages in the UML; they are less closely related to namespaces in C++.
Although it is conventional to name Java packages hierarchically, this hierarchy has no semantics in the language. For example, packages that begin with "java" are part of the Java language specification, and the package java.lang and other packages that begin with "java.lang" contain classes that are core to the language. However, it is not possible to import all of the Java classes (for example, classes in java.lang, java.util, java.io, etc.) with the statement
import java.*;
and the statement
import java.lang.*;
will import all of the classes in the package java.lang, but not the packages java.lang.ref or java.lang.reflect. This is in contrast to the hierarchical namespaces of C++.
Like class names, package names in Java specify the location of class files. Classes in the package org.xml.sax must be located in a directory org/xml/sax/. This rule has been criticized (primarily by the designers of C#) as unduly restrictive on the programmer. However, this restriction does simplify the design of the class loader.
Java packages that begin with "java" are part of the Java language specification. Packages that begin with "javax" are extensions to the specification, sometimes refining or replacing functionality in "java" packages. The java.*, javax.* and org.* packages make up the Java platform's official API - all implementions of J2SE that are "100% pure Java" should support these packages out of the box. Other packages are external to the platform.
Java packages other than those in the language specification follow a naming convention that ensures there are no naming conflicts. A package name should start with the domain name reversed, for example "com.sun" for packages from www.sun.com. Within a given company or educational institution, the rest of the package name follows a standard set by that company or institution, but a common organization is to have the next part of the package name indicate the department (so, for example "edu.mit.cs").
[edit] Packages in the language specification
As of version 5:
java.applet- Interface for appletsjava.awt- Abstract Windowing Toolkitjava.awt.color- AWT color supportjava.awt.datatransferjava.awt.dnd- AWT drag and drop supportjava.awt.event- AWT event modeljava.awt.font- AWT fontjava.awt.geom- AWT geometry specificationjava.awt.im- AWT general input method supportjava.awt.im.spijava.awt.image- AWT image supportjava.awt.image.renderablejava.awt.print- AWT printing supportjava.beans- Java Beans specification for J2EEjava.beans.beancontextjava.io- Standard input/output APIjava.langjava.lang.annotationjava.lang.instrumentjava.lang.managementjava.lang.refjava.lang.reflectjava.math- Big integer and big decimal classesjava.net- Basic internet APIjava.nio- Non-blocking IOjava.nio.channelsjava.nio.channels.spijava.nio.charsetjava.nio.charset.spijava.rmi- Java remote method invocation APIjava.rmi.activationjava.rmi.dgcjava.rmi.registryjava.rmi.serverjava.security- Securityjava.security.acljava.security.certjava.security.interfacesjava.security.specjava.sql- SQL supportjava.text- Advanced formatting for dates, numbers, etc.java.util- Utility classes, including the Java collections frameworkjava.util.concurrent- Concurrency supportjava.util.concurrent.atomic- Atomic operation supportjava.util.concurrent.locks- Locksjava.util.jar- .jar file supportjava.util.logging- Loggingjava.util.prefs- System preference and configuration datajava.util.regex- Regular expression APIjava.util.zip- .zip file supportjavax.accessibility- Extensions for accessibility supportjavax.activity- Activity service exceptions thrown by the ORBjavax.crypto- Cryptographic operationsjavax.crypto.interfacesjavax.crypto.specjavax.imageio- Image I/Ojavax.imageio.eventjavax.imageio.metadatajavax.imageio.plugins.bmpjavax.imageio.plugins.jpegjavax.imageio.spijavax.imageio.streamjavax.management- Extensions for VM managementjavax.management.loadingjavax.management.modelmbeanjavax.management.monitorjavax.management.openmbeanjavax.management.relationjavax.management.remotejavax.management.remote.rmijavax.management.timerjavax.naming- Naming service supportjavax.naming.directoryjavax.naming.eventjavax.naming.ldapjavax.naming.spijavax.net- Extensions for Internetjavax.net.ssljavax.print- Extensions for printingjavax.print.attributejavax.print.attribute.standardjavax.print.eventjavax.rmi- Extensions for RMIjavax.rmi.CORBA- RMI using CORBAjavax.rmi.ssljavax.security.auth- Authentication and authorizationjavax.security.auth.callbackjavax.security.auth.kerberos- Kerberos supportjavax.security.auth.loginjavax.security.auth.spijavax.security.auth.x500- X.500 supportjavax.security.certjavax.security.sasljavax.security.sasljavax.servletjavax.sound.midi- Java sound API for MIDIjavax.sound.midi.spijavax.sound.sampled- Java sound API for sampled soundjavax.sound.sampled.spijavax.sql- Extensions for SQLjavax.sql.rowsetjavax.sql.rowset.serialjavax.sql.rowset.spijavax.swing- Swing APIjavax.swing.borderjavax.swing.colorchooserjavax.swing.eventjavax.swing.filechooserjavax.swing.plaf- Plugable look and feel support for Swingjavax.swing.plaf.basicjavax.swing.plaf.metaljavax.swing.plaf.multijavax.swing.plaf.synthjavax.swing.tablejavax.swing.textjavax.swing.text.htmljavax.swing.text.html.parserjavax.swing.text.rtfjavax.swing.treejavax.swing.undo- Undo support for Swingjavax.transactionjavax.transaction.xajavax.xml- General XML APIjavax.xml.datatypejavax.xml.namespacejavax.xml.parsersjavax.xml.transformjavax.xml.transform.domjavax.xml.transform.saxjavax.xml.transform.streamjavax.xml.validationjavax.xml.xpath
[edit] Java Package Count
| JDK version (year) | Package count | Class count |
|---|---|---|
| 1.0 (1996) | 8 | 212 |
| 1.1 (1997) | 25 | 504 |
| 1.2 (1998) | 59 | 1520 |
| 1.3 (2000) | same | same |
| 1.4 (2002) | 135 | 2991 |
| 5.0 (2004) | 166 | 3562 |