Java Reflection class get package name

Description

Java Reflection class get package name

public class Main {  
  public static void main(String args[]) throws Exception {      
    Class<?> c = Class.forName("java.lang.String");  
    Package p = c.getPackage();  
    System.out.println("Package name: "+p.getName());       
    /*from w w w.  ja v  a  2  s.  c  o m*/
    c = String.class;
    p = c.getPackage();  
    System.out.println("Package name: "+p.getName());       
    
    c = Thread.class;
    p = c.getPackage();  
    System.out.println("Package name: "+p.getName());     
    
    c = java.util.Date.class;
    p = c.getPackage();  
    System.out.println("Package name: "+p.getName());     
    
    c = java.sql.Date.class;
    p = c.getPackage();  
    System.out.println("Package name: "+p.getName());     
  }  
} 



PreviousNext

Related