This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The last time I checked the actual byte code was different ...
The first had the byte code for entering the monitor, the second set the ACC_SYNCHRONIZED flag on the method, the effect may be the same but literally they are different, I wouldn't look at the byte code for that reason as it could confuse the issue. You could argue synchronized method is more efficient but I wouldn't get obsessed about it but if your intent is to synchronize the whole method I would definitely do that as its clearer.
Krishna Chhabra wrote:Not able to understand exactly that what does (this) means in below code
It's telling us which lock we're going to obtain. The only thing that the synchronized keyword does¹ is to obtain the lock for the indicated object, blocking at that point in its execution until the lock is released if some other thread currently hodls it. That's all. When we do synchronized (this) that just means we're obtaining the lock for the "current" object.
¹Actually that's all it does in terms of mutual exclusion. It also provides some memory barrier effects for consistency and predictability of the values of shared variables, but that part isn't pertinent to your question.