public class

Package

extends Object
implements AnnotatedElement
java.lang.Object
   ↳ java.lang.Package

Class Overview

Contains information about a Java package. This includes implementation and specification versions. Typically this information is retrieved from the manifest.

Packages are managed by class loaders. All classes loaded by the same loader from the same package share a Package instance.

See Also

Summary

Public Methods
<T extends Annotation> T getAnnotation(Class<T> annotationType)
Gets the annotation associated with the specified annotation type and this package, if present.
Annotation[] getAnnotations()
Gets all annotations associated with this package, if any.
Annotation[] getDeclaredAnnotations()
Gets all annotations directly declared on this package, if any.
String getImplementationTitle()
Returns the title of the implementation of this package, or null if this is unknown.
String getImplementationVendor()
Returns the name of the vendor or organization that provides this implementation of the package, or null if this is unknown.
String getImplementationVersion()
Returns the version of the implementation of this package, or null if this is unknown.
String getName()
Returns the name of this package in the standard dot notation; for example: "java.lang".
static Package getPackage(String packageName)
Attempts to locate the requested package in the caller's class loader.
static Package[] getPackages()
Returns all the packages known to the caller's class loader.
String getSpecificationTitle()
Returns the title of the specification this package implements, or null if this is unknown.
String getSpecificationVendor()
Returns the name of the vendor or organization that owns and maintains the specification this package implements, or null if this is unknown.
String getSpecificationVersion()
Returns the version of the specification this package implements, or null if this is unknown.
int hashCode()
Returns an integer hash code for this object.
boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
Indicates whether the specified annotation is present.
boolean isCompatibleWith(String version)
Indicates whether this package's specification version is compatible with the specified version string.
boolean isSealed()
Indicates whether this package is sealed.
boolean isSealed(URL url)
Indicates whether this package is sealed with respect to the specified URL.
String toString()
Returns a string containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.reflect.AnnotatedElement

Public Methods

public T getAnnotation (Class<T> annotationType)

Since: API Level

Gets the annotation associated with the specified annotation type and this package, if present.

Parameters
annotationType the annotation type to look for.
Returns

public Annotation[] getAnnotations ()

Since: API Level 1

Gets all annotations associated with this package, if any.

Returns
  • an array of Annotation instances, which may be empty.
See Also

public Annotation[] getDeclaredAnnotations ()

Since: API Level 1

Gets all annotations directly declared on this package, if any.

Returns
  • an array of Annotation instances, which may be empty.

public String getImplementationTitle ()

Since: API Level 1

Returns the title of the implementation of this package, or null if this is unknown. The format of this string is unspecified.

Returns
  • the implementation title, may be null.

public String getImplementationVendor ()

Since: API Level 1

Returns the name of the vendor or organization that provides this implementation of the package, or null if this is unknown. The format of this string is unspecified.

Returns
  • the implementation vendor name, may be null.

public String getImplementationVersion ()

Since: API Level 1

Returns the version of the implementation of this package, or null if this is unknown. The format of this string is unspecified.

Returns
  • the implementation version, may be null.

public String getName ()

Since: API Level 1

Returns the name of this package in the standard dot notation; for example: "java.lang".

Returns
  • the name of this package.

public static Package getPackage (String packageName)

Since: API Level 1

Attempts to locate the requested package in the caller's class loader. If no package information can be located, null is returned.

Parameters
packageName the name of the package to find.
Returns
  • the requested package, or null.

public static Package[] getPackages ()

Since: API Level 1

Returns all the packages known to the caller's class loader.

Returns
  • all the packages known to the caller's class loader.
See Also

public String getSpecificationTitle ()

Since: API Level 1

Returns the title of the specification this package implements, or null if this is unknown.

Returns
  • the specification title, may be null.

public String getSpecificationVendor ()

Since: API Level 1

Returns the name of the vendor or organization that owns and maintains the specification this package implements, or null if this is unknown.

Returns
  • the specification vendor name, may be null.

public String getSpecificationVersion ()

Since: API Level 1

Returns the version of the specification this package implements, or null if this is unknown. The version string is a sequence of non-negative integers separated by dots; for example: "1.2.3".

Returns
  • the specification version string, may be null.

public int hashCode ()

Since: API Level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Returns
  • this object's hash code.

public boolean isAnnotationPresent (Class<? extends Annotation> annotationType)

Since: API Level 1

Indicates whether the specified annotation is present.

Parameters
annotationType the annotation type to look for.
Returns
  • true if the annotation is present; false otherwise.

public boolean isCompatibleWith (String version)

Since: API Level 1

Indicates whether this package's specification version is compatible with the specified version string. Version strings are compared by comparing each dot separated part of the version as an integer.

Parameters
version the version string to compare against.
Returns
  • true if the package versions are compatible; false otherwise.
Throws
NumberFormatException if this package's version string or the one provided are not in the correct format.

public boolean isSealed ()

Since: API Level 1

Indicates whether this package is sealed.

Returns
  • true if this package is sealed; false otherwise.

public boolean isSealed (URL url)

Since: API Level 1

Indicates whether this package is sealed with respect to the specified URL.

Parameters
url the URL to check.
Returns
  • true if this package is sealed with url; false otherwise

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a printable representation of this object.