Speculate, but don’t guess, measure to see

How synchronized keyword behaves in methods. I’ve heard speculation that doFoo1() would result into more compact byte code, but I don’t buy that. Assumption: Byte code in both cases, is same. So we have this sample, [code lang=”java”] class SyncMe { synchronized void doFoo1() { int x = 0; } void doFoo2() { synchronized (this)…

Read more

Eeny, weeny, nitpicking, peeny

Todays lesson is: What javac does with following methods, when compiled. Assumptions: Iterating over ArrayList vs. List generates optimized code, not creating Iterator (i.e. would optimize memory usage using RandomAccessList API), but using int index Itearating over Object[] is faster than List/ArrayList foreach loop for Object[] is as tight code as manual iteration [code lang=”java”]…

Read more