skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, September 15, 2012

Verifying in Runtime that dose the class exists within a program

Posted by Admin at 4:43 AM – 0 comments
 

public class Main 
{
  public static boolean doesClassExist(String name) 
  {
    try 
    {
      Class c = Class.forName(name);
      if (c != null)
        return true;
    } 
    catch (ClassNotFoundException e) 
    {
      // Class not found
    } 
    catch (Exception e) 
    {
      e.printStackTrace();
    }
    return false;
  }
}

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger