Do you ever test your code after it has been deployed to production ? During my first few years programming, I thought this was a bad idea and was told repeatedly told not to test anything in Prod.
After being bitten time and again by environment related problems, I decided to make it a point to perform a smoke test in Prod before handing it to users. Even if it meant a transaction with real money was involved.
Let me take a few moments to recite some of the follies that befell me when I did not test in Prod.
- Code moves to production. We find out that the SSL certificates in QA are installed in a different configuration when compared to Prod. The isSecure() flag on the HttpServletRequest returned a different value because of this and the code bombed.

Here are a few more tips / tricks with which you can save time when you use the eclipse IDE.
Assign Key bindings:

Navigate to Window -> Preferences -> General -> Keys
You will find that there are many key bindings that are not assigned to actions that you might do on a daily basis. For example, when I start up on a new project, it is highly likely that I will introduce a lot of Value Objects (or Transfer / Data object, whatever you like to call them). A slick feature is to generate the ‘Getters and Setters’ for them using the ‘Source -> Generate getter and setter’ command from the Main menu.
You can either do that or you can assign a shortcut key to this action and get it done quickly. I use Alt+Shift+Q, +G (Yeah not the easiest combination. I know
). To restart eclipse I use Ctrl + F12. You might want to look at other bindings like
Ever visit sites like topcoder.com and solve a problem or two ? No ? You should and do so regularly. It will help find tune your programming / design skills. This is because solving the problems requires going though the following thought process
- Understanding the problem.
- Thinking up a solution that covers all use cases.
- Executing your thought process through code.
- Testing.
Now as simple as that sounds, it is not so easy to get right. Especially when you are competing with thousands of fellow coders for time. And when time is a constrain you usually select the first solution that comes to your head, which might not necessarily be the best. So there is that risk of your code timing out even if it is following the right logic. I would love to delve into a problem right about now and throw in some examples and illustration, but you get the point.

I ran into another sweet little bug that I thought I would share with you. This one cropped up after it passed a few tests. See if you can spot the problem. Without further delay here it is
Problem:
A record needs to be inserted with a new identity number. This number is obtained as the next maximum ID value from a set of elements in a XML file. The following code is supposed to obtain the next ID from the XML. Lets skip the XML related code since that just adds clutter.
Code:
int max = 0;
for( DataType data : someListFromTheXml )
{
if(max < data.getId())
{
max = data.getId()+1;
}
}
s_logger.info(" Max id: " + max);
return max;
See anything wrong with it ? Its got a pretty big flaw. The logic works only for odd number of elements. When the number of elements is even, it fails. Here’s an illustration
Test cases:
public class Test
{
public static void main(String... args)
{
int [] input1 = new int[]{1};
int [] input2 = new int[]{1,2};
int [] input3 = new int[]{1,2,3};
int [] input4 = new int[]{1,2,3,4};
Test test = new Test();
test.go(input1);
test.go(input2);
test.go(input3);
test.go(input4);
test.go(input5);
}
public void go(int [] input)
{
int max=0;
for(int id:input)
{
if(max < id)
{
max = id+1;
}
}
System.out.println(" Max id: " + max);
}
}
Here’s the output: