File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callback Function

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Thanks much Kondal, It does help me understand.
Regards,
Vijay
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Great link Shiva.. Thanks.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic