wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Callback Function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Callback Function" Watch "Callback Function" New topic
Author

Callback Function

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Can someone explain what is a callback function in context of inner classes/interfaces ? Whats the physical meaning of this in Java ?
I have read this term at many places but just can't visualize it.
Thank you very much in advance..
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
the only thought came to my mind is *69 or *89 as per "physical meaning"
and its not function it should be a method
are you referring to the example given in "the complete ref" by patrick naughton?
interface can define any methods and you must implement them in your class when you implement particular interface

------------------
Kondal Rao
Greenhorn

Joined: Apr 05, 2000
Posts: 18

I came across this term, When I was reading books titled like "Java for C++ programmers". I am not a C++ guru. But as far as my understanding goes, "callback function" is a C++ terminology. An example for this callback function could be as follows:
You have called some function to Transfer a file to remote host using FTP. These FTP functions may provide some callback functions, using which you can find about the status and number of bytes transferred to remote host. In C++, these callback functions expect the pointer to functions.
In Java, as we all know there are no pointers. The same concept is implemented in Java in Event handling. Here when you add a listener to an object, you pass the instance of the object, which handles that event. Through this, if that event occurs for that component, that component will invoke that particular method in that event hander. Let us discuss with an example.
The following is the init() method of an applet.
Button mybutton = new Button("Test");
mybutton.addActionListener(evtHandler);
add(mybutton);
//where evtHandler implements Actionlistener by overriding actionPermoned(ActionEvent evt);
In the above example, if the user presses the pushbutton, then the mybutton can invoke the actionPerformed method of the evtHandler, which handles this event. This concept is very similar to callback function in C++. One of the common usage for inner classes is to implement interfaces in event handling.
Hope this helps.
Reagrds,
Kondal.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks much Kondal, It does help me understand.
Regards,
Vijay
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Vijay,
came across this topic, which will give you some more info
http://www.javaworld.com/javaworld/javatips/jw-javatip10_p.html
Regards,
Shiva
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Great link Shiva.. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Callback Function
 
Similar Threads
Callback help in JNI
Call back and inline functions
Servlet can't get the xmlhttp post request
dynamic select box - with ajax
What is a callback function?