|
A Java package is a Java programming language mechanism for organizing classes into namespaces. 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. Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ...
In object-oriented programming, classes are used to group related variables and functions. ...
Many modern computer languages provide support for namespaces. ...
Source code (commonly just source or code) is any series of statements written in some human-readable computer programming language. ...
In computing, a Jar file (short for Java ARchive) is a ZIP file used to distribute a set of Java classes. ...
- 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.
On computer science, a datatype (often simply type) is a name or label for a set of values and some operations which can be performed on that set of values. ...
In object-oriented programming, classes are used to group related variables and functions. ...
An interface defines the communication boundary between separate computer components. ...
In computer programming, an enumerated type is a data type whose set of values is a finite list of identifiers chosen by the programmer. ...
Annotation is extra information associated with a particular point in a document or other piece of information. ...
Using packages To use a package inside a Java source file, it is convenient to import the classes from the package with an import statement. The statement import java.awt.event.*; imports all classes from the java.awt.event package, while import java.awt.event.ActionEvent; imports only the ActionEvent class from the package. After either of these import statements, the ActionEvent class can be referenced using its simple class name: ActionEvent myEvent = new ActionEvent(); Classes can also be used directly without an import statement by using the fully-qualified name of the class. For example, java.awt.event.ActionEvent myEvent = new java.awt.event.ActionEvent(); doesn't require a preceding import statement.
Package access protection Classes within a package can access classes and members declared with default access and class members declared with the protected access modifier. Default access is enforced when neither the public, protected nor private access modifier is specified in the declaration. By contrast, classes in other packages cannot access classes and members declared with default access. Class members declared as protected can only be accessed from within classes in other packages that are subclasses of the declaring class.
Creation of JAR files In Java source files the package the file belongs to is specified with the package keyword. In computer science, a keyword is an identifier which indicates a specific command. ...
package java.awt.event; JAR Files are created with the jar command-line utility. The command jar cf myPackage.jar *.class compresses all *.class files into the JAR file myPackage.jar.
Package naming conventions Packages are usually defined using a hierarchical naming pattern, with levels in the hierarchy separated by periods (.) (pronounced "dot"). Although packages lower in the naming hierarchy are often referred to a "subpackages" of the corresponding packages higher in the hierarchy, there is no semantic relationship between packages. The Java Language Specification establishes package naming conventions in order to avoid the possibility of two published packages having the same name. The naming conventions describe how to create unique package names, so that packages that are widely distributed will have unique namespaces. This allows packages to be easily and automatically installed and catalogued. A hierarchy (in Greek hieros = sacred, arkho = rule) is a system of ranking and organizing things. ...
A pattern is a form, template, or model (or, more abstractly, a set of rules) which can be used to make or to generate things or parts of a thing, especially if the things that are generated have enough in common for the underlying pattern to be inferred or discerned...
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 package. Package names should be all lowercase characters whenever possible. A top-level domain (TLD) is the last part of which Internet domain names consist of. ...
For example, if an organization in Canada called MySoft creates a package to deal with fractions, naming the package ca.mysoft.fractions 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 com.mysoft.fractions, 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 section 7.7 of the Java Language Specification.
Core packages in J2SE 5.0 - Main article: Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE (formerly known up to version 5. ...
A binary tree, a simple type of branching linked data structure. ...
In computing, New I/O, usually called NIO, is a collection of APIs in Java programming language that offers features for intensive I/O operations. ...
It has been suggested that Domain name be merged into this article or section. ...
Java Database Connectivity, or JDBC, is an API for the Java programming language that defines how a client may access a database. ...
Gui is short for Guilherme or Guilhermo or an iteration of that, in English it translates to Will. ...
See also JAR (file format) In computing, a Jar file (short for Java archive) is a ZIP file used to distribute a set of Java classes. ...
External links |