File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What is a callback method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What is a callback method? " Watch "What is a callback method? " New topic

What is a callback method?

Rahul Jadaun
Ranch Hand

Joined: Oct 05, 2006
Posts: 36
What is a callback method?
Rohitt Vermaa
Ranch Hand

Joined: Oct 12, 2006
Posts: 232
Callback method is a method intended to be passed as a parameter. The callee can then call the passed method. Callbacks are often used in event handling code. This has nothing to do with SCWCD.

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
This has nothing to do with SCWCD

in fact, see the first question of the filters mock test in HFSJ,
it has a question on it !

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Tim Lawrence

Joined: Aug 30, 2004
Posts: 1
Hi, I am also interested in understanding more about callback methods. Could someone please explain what a "container callback method" is as opposed to an "inline method"? (As Niranjan points out) both of these concepts appear in the answer to the first test question of HFSJ Chapter 13 on filters (pg.700).

"doFilter() is both a callback and an inline method" - what does that mean?


Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Rohitt's answer is interesting, but methods cannot be passed as a parameter in Java. That is a feature of some other languages like JavaScript and Ruby.

Searching this forum with the keyword "callback" returns many, many results.

One of my previous answers was here .

A good workman is known by his tools.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

Method passed as a parameter?? The first time I'm hearing this!

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Method passed as a parameter?? The first time I'm hearing this!

Don't feel bad about it

As Marc says, Java doesn't have this, but other languages do, e.g. C has had this for a long time.

It is of course possible in Java to define an interface that has only a single method, and use that as the callback, which would be pretty close.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

The good old days with pointers to functions
Something similar could also be done with Reflection.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: What is a callback method?
It's not a secret anymore!