Saturday, April 24, 2010

Determine what package from a class object ???  

0 comments

Source code below will print name for package that belong to it's own class object. It should print null because class object that create from java file below not belong to any package.

************************************************************************************
COMPLETE SOURCE CODE FOR : DeterminePackageForClassObject.java
************************************************************************************

  1. public class DeterminePackageForClassObject
  2. {
  3. public static void main(String[]args)
  4. {
  5. try
  6. {
  7. Class temp=Class.forName("DeterminePackageForClassObject");
  8. System.out.println("PACKAGE FOR THIS CLASS OBJECT IS :"+temp.getPackage());
  9. }
  10. catch(Exception exception)
  11. {
  12. exception.printStackTrace();
  13. }
  14. }
  15. }


************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



Extension Factory Builder