Sunday 12 April 2015

Package class


The package class provides methods to get information about the specification and implementation of a package. It provides methods such as getName(), getImplementationTitle(), getImplementationVendor(), getImplementationVersion() etc.

Example of Package class

In this example, we are printing the details of java.lang package by invoking the methods of package class.




  1. class PackageInfo{  
  2. public static void main(String args[]){  
  3.    
  4. Package p=Package.getPackage("java.lang");  
  5.   
  6. System.out.println("package name: "+p.getName());  
  7.   
  8. System.out.println("Specification Title: "+p.getSpecificationTitle());  
  9. System.out.println("Specification Vendor: "+p.getSpecificationVendor());  
  10. System.out.println("Specification Version: "+p.getSpecificationVersion());  
  11.   
  12. System.out.println("Implementaion Title: "+p.getImplementationTitle());  
  13. System.out.println("Implementation Vendor: "+p.getImplementationVendor());  
  14. System.out.println("Implementation Version: "+p.getImplementationVersion());  
  15. System.out.println("Is sealed: "+p.isSealed());  
  16.   
  17.   
  18.  }  
  19. }  
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

No comments:

Post a Comment