Java Reference
In-Depth Information
pkg.getSpecificationVersion());
System.out.println("Sealed: "+pkg.isSealed());
if (args.length > 1)
System.out.println("Compatible with "+args[1]+":
"+
pkg.isCompatibleWith(args[1]));
}
}
packagenameonthecommandlinewhenyourunthisapplication.Forexample,
java
PackageInfo java.lang
returns the following output under Java 7:
Name: java.lang
Implementation title: Java Runtime Environment
Implementation vendor: Oracle Corporation
Implementation version: 1.7.0
Specification title: Java Platform API Specification
Specification vendor: Oracle Corporation
Specification version: 1.7
Sealed: false
PackageInfo
also lets you determine if the package's specification is compatible
with a specific version number. A package is compatible with its predecessors.
For example,
java PackageInfo java.lang 1.7
outputs
Compatible
with 1.7: true
, whereas
java PackageInfo java.lang 1.8
outputs
Compatible with 1.8: false
.
Youcanalsouse
PackageInfo
withyourownpackages,whichyoulearnedtocre-
Copy
PackageInfo.class
intothedirectorycontainingthe
logging
package
directory(whichcontainsthecompiledclassfiles),andexecute
java PackageInfo
logging
.
PackageInfo
responds by displaying the following output:
logging not found
This error message is presented because
getPackage()
requires at least one
classfiletobeloadedfromthepackagebeforeitreturnsa
Package
objectdescribing
that package.