Java package: Difference between revisions

Content deleted Content added
Removed {{compu-lang-stub}} as I think the article, while not complete, has grown past the stub phase
Cleaned up intro and other parts--more work still needed, but cleaned up enough that I removed the {{expert}} tag
Line 1:
A '''Java package''' is a [[Java programming language]] mechanism for organizing [[class (computer science)|classes]] into [[namespace]]s. Java [[source file]]s belonging to the same category or providing similar functionality can include a '''<code>package</code>''' 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 file]]s.
{{expert}}
Java [[source file]]s belonging to the same category or provide similar functionality can be packed into a Java package. Java packages are stored in compressed files called [[Jar (file format)|JAR]] files. Inside the package the files can be stored hierachically, therefore it is possible to combine several subdirectories into one package.
 
* A package provides a unique [[namespace|namespace]] for the types it contains.
* A package facilitates access protection.
* A package can contain the following kinds of [[Datatypes|types]].
** [[Class (computer science)|Classes]]
** [[interface (computer science)|Interfaces]]
** [[Enumeration|Enumerated Types]]
** [[Annotation]]s
 
== Using packages ==
Line 44 ⟶ 43:
== Package naming conventions ==
 
OnePackages ofare usually defined using a [[hierarchical]] naming [[pattern]], with levels in the primaryhierarchy separated by periods (<code>.</code>) (pronounced "dot"). Although packages lower in the naming hierarchy are often referred to a purposes"subpackages" of the corresponding packages higher in the hierarchy, there is no semantic relationship between packages. The [http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html Java Language Specification] establishes package naming conventions isin order to avoid the possibility of two published packages having the same name. by choosingThe naming conventions describe how to create unique package names, forso that packages that are widely distributed will have unique namespaces. This allows packages to be easily and automatically installed and catalogued.
 
In general, a package name begins with the [[top level ___domain]] name of the organization and then the organization's ___domain and then any subdomains listed in reverse order. The organization can then choose a specific name for their pacakge. Package names should be all lowercase characters whenever possible.
 
For example, if an organization in Canada called MySoft creates a package to deal with fractions, theynaming mightthe namepackage their<tt>ca.mysoft.fractions</tt> distinguishes the fractions package from another similar package created by another company. If a US company named MySoft also creates a fractions package, but names it <tt>cacom.mysoft.fractions</tt>, then the classes in these two packages are defined in a unique and separate namespace.
 
Complete conventions for disambiguating package names and rules for naming packages when the Internet ___domain name cannot be directly used as a package name are described in [http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.7 section 7.7] of the [http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html Java Language Specification].
 
== Core packages in J2SE 5.0 ==
{{main|Java Platform, Standard Edition}}
 
* {{Javadoc:SE|package=java.lang|java/lang}}, {{Javadoc:SE|package=java.util|java/util}}: These package hierarchies provide basic language functionality likeand fundamental types, [[regular expression]]s, the Reflection API
* {{Javadoc:SE|package=java.util|java/util}}: collection [[data structure]] classes
* {{Javadoc:SE|package=java.math|java/math}}: provides mathematical functions
* {{Javadoc:SE|package=java.io|java/io}}: file operations