How to call a method dynamically in Java

Posted by
		 // Get the Class object of the class that contains the method
		    Class<?> loginAction = LoginAction.class;
		 // Get the Method object of the method you want to call
		    Method actionMethod = loginAction.getMethod(key, String.class);
		    System.out.print("actionMethod" + actionMethod);
	        // Call the method dynamically
		    LoginAction object = new LoginAction();
	        Object result = actionMethod.invoke(object,val);