Friday, February 4, 2011

What is callback and how it is achieved in the java?

A Callback function is a method that is passed into a method, and
called at some point by the method to which it is passed.

This is very useful for making reusable software. For example, many
operating system APIs (such as the Windows API) use callbacks heavily.


For example, if you wanted to work with files in a folder - you can
call an API function, with your own routine,
and your routine gets run once per file in the specified folder. This
allows the API to be very flexible.


Callback mechanisms are often implemented via function pointers,
functor objects, or callback objects.


Java's support of interfaces provides a mechanism by which we can get
the equivalent of callbacks.
The trick is to define a simple interface that declares the method we
wish to be invoked.


Here is as sample program which :
http://javawithrajul.googlegroups.com/web/CallbackTest.java


Regards
Rajul konkar

No comments:

Post a Comment