Java Package 类

2025年2月22日 | 阅读 1 分钟

Package 类提供了有关包的规范和实现的信息。它提供了诸如 getName()、getImplementationTitle()、getImplementationVendor()、getImplementationVersion() 等方法。

Package 类的示例

在此示例中,我们通过调用 Package 类的相关方法来打印 java.lang 包的详细信息。

class PackageInfo{
public static void main(String args[]){
 
Package p=Package.getPackage("java.lang");

System.out.println("package name: "+p.getName());

System.out.println("Specification Title: "+p.getSpecificationTitle());
System.out.println("Specification Vendor: "+p.getSpecificationVendor());
System.out.println("Specification Version: "+p.getSpecificationVersion());

System.out.println("Implementaion Title: "+p.getImplementationTitle());
System.out.println("Implementation Vendor: "+p.getImplementationVendor());
System.out.println("Implementation Version: "+p.getImplementationVersion());
System.out.println("Is sealed: "+p.isSealed());


 }
}

Output:package name: java.lang
       Specification Title: Java Plateform API Specification
       Specification Vendor: Sun Microsystems, Inc.
       Specification Version: 1.6
       Implemenation Title: Java Runtime Environment
       Implemenation Vendor: Sun Microsystems, Inc.
       Implemenation Version: 1.6.0_30
       IS sealed: false