title: How to find the package name given a class name?
body: <p>Given a class name as a string, how do I get the package name of it at run time ? I do not have the fully qualified name with package name + class name. Simply only the class name.</p>
  
  <p>I want the package name to be used in <code>Class.forName()</code> method.</p>
  
  <p>I am perfectly fine with finding the first matching package name (if multiple packages have the same class).</p>
  
  <p>Any ideas? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I DO NOT have a Class instance to work on. My requirement is to create a Class using the <code>Class.forName()</code> method. But I simply have ONLY the class name as a string. I need some way to loop though the packages and identify if the class I have belongs to the package.</p>
  
  <p>The stack trace of the exception is</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassNotFoundException: MyAddressBookPage
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
  </code></pre>