Thursday, June 21, 2007

Defensive Coding

Defense is a method of protecting. In sports like basketball, defense is an act of protecting your opponent to hit the goal. The same is true with programming. Defensive coding is an act of preventing an error to arise or we can say bug-free. Though I believe that there is no really a bug-free application, defensive coding can minimize or even prevent a much more disaster.

So how do we do this in java? There are many ways to implement this. One for example is declaring the right modifier for the right method or class variable.

public int insertValue(){} and public synchronized int insertValue(){} really is different. Both will compile and run. But things will be different when tested in a real environment. Having a synchronized modifier prevent the method on using resources at the same time.

My team manage to learn this new skill. Hope everyone appreciate this.