File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes PostFix operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "PostFix operator" Watch "PostFix operator" New topic

PostFix operator

Prabhat Kumar

Joined: Jan 25, 2007
Posts: 27
Dear all,
I am confused due to the output of the sollowing program.

public class PostFix
public static void main(String args[])
int i=0;


The output is coming 0 .
Can any one explain why?

Thanks in advance,

outpu is
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Perhaps have a look at

By the way, is "Pr" your real name?

The Java Ranch follows a policy regarding user names.
The main reasons why and a link how to change yours you'll find here:

So, would you please change your user name before your next posting?
It will not affect anything you've already posted here. Just your user name will update.


all events occur in real time
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
A hint.

You're assigning and then the postfix operator will run.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Clinton Magro

Joined: May 16, 2007
Posts: 9
int i=0;

What Goes Around .. Comes Around
Prabhat Kumar

Joined: Jan 25, 2007
Posts: 27
I could not get it!!
what do you mean when you say "too late"
i think the whole line will be executed before java goes to next that case it should be 1 at the end of second line and then 2 at the end of 3rd line.
please explain
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Originally posted by Prabhat Kr:
what do you mean when you say "too late"
The sequence is crucial.

i=i++ is equivalent to:

int temp = i;
i = i + 1;
i = temp;
I agree. Here's the link:
subject: PostFix operator
It's not a secret anymore!