tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Reflection > Package Info

Package Info 

The following example shows how to access package information of a given class.

File Name  :  
com/bethecoder/tutorials/reflection/PackageInfo.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.reflection;

import java.util.List;

public class PackageInfo {

  /**
   @param args
   */
  public static void main(String[] args) {

    printPackageInfo(String.class);
    System.out.println();
    printPackageInfo(List.class);
  }
  
  public static void printPackageInfo(Class clazz) {
    Package pack = clazz.getPackage();
      System.out.println(pack);
      System.out.println(pack.getImplementationTitle());
      System.out.println(pack.getImplementationVersion());
      System.out.println(pack.getImplementationVendor());
      System.out.println(pack.getName());
      System.out.println(pack.getSpecificationTitle());
      System.out.println(pack.getSpecificationVendor());
      System.out.println(pack.getSpecificationVersion());
  }

}
   

It gives the following output,
package java.lang, Java Platform API Specification, version 1.6
Java Runtime Environment
1.6.0_07
Sun Microsystems, Inc.
java.lang
Java Platform API Specification
Sun Microsystems, Inc.
1.6

package java.util, Java Platform API Specification, version 1.6
Java Runtime Environment
1.6.0_07
Sun Microsystems, Inc.
java.util
Java Platform API Specification
Sun Microsystems, Inc.
1.6


                    Print

   



Books Recommendation

 
 
bl  br