title: Program to find the number of methods in a java program
body: <p>I used the following code to identify the number of functions in a class. Similar way can any one help me to identify the number of functions in a java program. In my program i gave input file as a class. Guide me with the code to give input as a java program and to find the number of declared functions in it.</p>
  
  <pre><code>import java.lang.reflect.*;
  import java.io.*;
  import java.lang.String.*;
     public class Method1 {
        private int f1(
         Object p, int x) throws NullPointerException
        {
           if (p == null)
              throw new NullPointerException();
           return x;
        }
  
        public static void main(String args[])throws Exception
        {
           int Mcount=0,MthdLen=0;
           try {
             Class cls = Class.forName("Madhu");
          int a;
              Method methlist[]= cls.getDeclaredMethods();
              for (int i = 0; i &lt; methlist.length;i++)
              {  
                 Method m = methlist[i];
                 Mcount = Mcount + 1;
                 MthdLen=MthdLen+(m.getName().length());
              }
           }
           catch (Throwable e) {
              System.err.println(e);
           }
          System.out.println("Length = " + MthdLen);
          System.out.println("Mcount = " + Mcount);
        }
     }
  </code></pre>