This is my blog on Java and related technologies and tools that I have worked on. I started this blog just to keep my Java knowledge updated which can also be a place for quick reference. The source of most of the articles are a mixture of my views and the place where i read it. Comments are most welcome and please rectify me wherever i have gone wrong.
Thursday, November 4, 2010
Difference between Alias and Synonym
Tuesday, November 2, 2010
Difference between NoClassDefFoundError & ClassNotFoundException
SQL Basics - 2
Monday, November 1, 2010
SQL Basics - 1
Insert into new_table select * from old table
Sunday, October 31, 2010
Atomicity
public class UnsafeCountingFactorizer implements Servlet {
private long count = 0;
public long getCount() {
return count;
}
BigInteger i = extractFromRequest(req);
BigInteger[] factors = factor(i);
++count;
encodeIntoResponse(resp, factors);
}
}
public class LazyInitRace {
private ExpensiveObject instance = null;
public ExpensiveObject getInstance() {
if (instance ==null){
instance = new ExpensiveObject();
} return instance;
}
}
public class CountingFactorizer implements Servlet { private final AtomicLong count = new AtomicLong(0); public long getCount() { return count.get(); } public void service(ServletRequest req, ServletResponse resp) { BigInteger i = extractFromRequest(req); BigInteger[] factors = factor(i); count.incrementAndGet(); encodeIntoResponse(resp, factors); } } Friday, October 29, 2010
Difference between Encapsulation & Abstraction
Thursday, October 28, 2010
Loopy Problem - IV
Provide declarations for i and j that turn this loop into an infinite loop:
while (i <= j && j <= i && i != j) { }
The <= operator is still antisymmetric on the set of primitive numeric values, but now it applies to operands of boxed numeric types as well. (The boxed numeric types are Byte, Character, Short, Integer, Long, Float, and Double.) The <= operator is not antisymmetric on operands of these types, because Java's equality operators (== and !=) perform reference identity comparison rather than value comparison when applied to object references.
To make this concrete, the following declarations give the expression (i <= j && j <= i && i != j) the value true, turning the loop into an infinite loop:
Integer i = new Integer(0);
Integer j = new Integer(0);
The first two subexpressions (i <= j and j <= i) perform unboxing conversions [JLS 5.1.8] on i and j and compare the resulting int values numerically. Both i and j represent 0, so both of these subexpressions evaluate to TRue. The third subexpression (i != j) performs an identity comparison on the object references i and j. The two variables refer to distinct objects, as each was initialized to a new Integer instance. Therefore, the third subexpression also evaluates to true, and the loop spins forever.