This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
 
subject: Callback Function
 
Similar Threads
Servlet can't get the xmlhttp post request
Callback help in JNI
dynamic select box - with ajax
Call back and inline functions
What is a callback function?