import java.lang.reflect.*;

/**
 * An example of static and non-static method invocation using
 * reflection.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class MethodExample
{
    /**
     * The entry point of the application.
     *
     * @param args  The command-line arguments (which are ignored)
     */
    public static void main(String[] args) throws Exception
    {
        Class   s_class;
        Integer i, j;        
        Method  s_method;
        String  s, zip;

        s        = new String("James Madison University");
        s_class  = s.getClass();

        // Using a non-static method
        s_method = s_class.getMethod("indexOf", new Class[]{String.class});
        i = (Integer)s_method.invoke(s, "University");
        System.out.println(i.intValue());

        // Using a static method
        s_method = s_class.getMethod("valueOf", new Class[]{Object.class});
        zip = (String)s_method.invoke(null, new Integer(22801));
        System.out.println(zip);
    }
}
