This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding callback method

 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

when to use callback method(s) in java?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A callback is a general principle in programming that's used in a lot of programming languages for many different things. Ofcourse you can use this technique in Java as well.

The question "when to use this technique" is hard to answer in a general way, because there are many possible uses for it - there's not a simple and short list that says "use this for this, that and the other thing".

An example where callbacks are used is in handlers for GUI components in Swing. For example, when you call addActionListener on a JButton you pass it an implementation of ActionListener that contains a method actionPerformed, which is called by Swing when you click the button. The actionPerformed method is an example of a callback method - you pass it to Swing, and it calls the method back later.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic