• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Callback methods

 
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Whats the difference between callback methods and methods?

Regards
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Callback methods are methods. So, it makes no sense to speak of a difference between them.

A callback method is an ordinary Java method. The only thing special about them is how you intend them to be used. You can't enforce that a method is only used for callbacks.
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but what exactly does it mean when someone writes..

"callback methods such as .."

They could as well write it as

methods...

Whats the special significance.....?
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Callback is comman mechanism in C.

It is used to pass a object to a method as an argument. Method inturn can invoke other methods associated with the Object passed to it as an argument.

Callback technique is essentialy used in scenarios where user wants to
invoke different methods without leeting client know which method of which class is being invoked.

Java use interfaces for callbacks mechanism. In this case, a method holds an interface reference in its argument list and then invokes a method in the interface.

java.io.Serializable Interface is one such example from Java API.


Now the million dollar Question - Why on this Planet do we want a callback?
When we pass a parameter, method being invoked gets the information (ie parameter value etc). What is returned is a result primitive or Object which provides only meager flow of info. Callback mechanism however allows a two-way communication channel between caller and callee.

Visitor Pattern is a classic example to demonstrate how Callback technique should ideally be used

HTH
[ September 28, 2006: Message edited by: Pratibha Malhotra ]
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pratibha!!!
 
My cellmate was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic