Program to find the number of methods in a java program -


I used the following code to identify the number of tasks in the class. Similarly, anyone can help me identify the number of functions in a Java program. In my program I gave the input file as a class. Guide me with the code to give input as Java program and find the number of functions declared in it.

  import java.lang.reflect *; Import java.io * *; Import java.lang.String *; Public class method 1 {Personal integer F1 (object P, int X) throws the null pointer exception (if throw (P == Rick) new nullioner exposure (return); return x;} public static zero main (string rule []) exception Throws {int Mcount = 0, MthdLen = 0; {class cls = Class.forName ("honey"); try an int method; method mathist [] = cls.getDeclaredMethods (); for (int i = 0; I & lt; methlist.length; i ++) {method m = methylist [i]; macant = macontoon + 1; mthdLen = mthdLen + (m.getName () length (.);}} Grip (throbable e) {System.err.println (e);} System.out.prin Tln ("length =" + MthdLen); System.out.println ("maqunt =" + mount);}}    

First of all,

  square cls = class.fornam ("honey");   

Full name is required. For example class. ForName ("java.lang.Thread") '.

Second, < Pre> method mathist [] = cls.getDeclaredMethods ();

returns public , protected , private and only the default method of that particular category (this legacy Does not include not methods).

Third,

  MthdLen = MthdLen + (m.getName (). Length ());   

The method shows the length of the string named the name above. What do you need for it? You can only calculate one such way:

  int MCount = cls.getDeclaredMethods (). Length; / / If "Gridclairred Methods ()" does not return a blank. Finally, if you need all inherited public and amp; protected methods, then you   
 Get all the methods using the  class  ?? class2 = cls.getSuperClass (); // method} Repeat through methods2 = class2.getDeclaredMethods (); // methods and all public, secure Retrieve ways and add it to the MCount.   

Hope this helps

Comments