yes!!! both are same ,see the value numOfHits++ what it means is we add or increment numOfHits by 1(ie to the previous or original value of numOfHits 1 is added),it is more efficient in use. Now in the second statement numOfHits=numOfHits+1; Here also to the previous value of numOfHits 1 is added but it is stored in it.
Joined: May 21, 2007
thanks for your reply that means numOfHitts = numOfHitts + 1 takes more operations first it adds the 1 to numOfHitts and then stores it in numOfHitts
At least with Java 6, the compiler actually compiles all of these three statements
to the same bytecode:
IINC i 1
So it seems as if the statement from the book is at least outdated, if not plain wrong.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
At least with Java 6, the compiler actually compiles ... to the same bytecode
Hooray! It's about time somebody woke up and did the compiler-writer's job. A language that exposes things about hardware and compiler implementation is offensive to me. The ++ operator originally corresponded to a particular instruction on a particular machine. I want my legions of business coders to think about insurance and customer service, not machine instructions.
Another silly example was a mainframe system that used signed dates because unsigned fields generated one more single-cycle machine instruction to force them to positive. Back then the mainframe ran 33mhz and we were charged $0.10 a CPU second, so every 33 million date assignments saved a dime. And explaining to every person who touched the data why they really didn't have to worry about negative dates cost how much?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi