Monday, May 21, 2012

how to call a method from command prompt in java

package com.jnet.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, SecurityException, NoSuchMethodException, InstantiationException {
        Test t=new Test();
        Method m = t.getClass().getMethod(args[0], new Class[] {});
        Object ret = m.invoke(t, new Object[] {});
        System.out.println((String)ret);
            }

    public static String m1(){
        return "sudheer";
    }
}

No comments:

Post a Comment