The idiom if (null != ... is a specific C/C++ idiom. We are writing Java, so can write if (obj != null) ... But I disagree about the non-null check. I would suggest that in the event of a null getting into your application, you are better off throwing an Exception. If a null does occur, what value are you going to insert into the database?
Joined: Dec 21, 2011
Hi Campbell Ritchie,
Thanks for your comment. yes i agree and it can be obj != null.
However, having a null check would be better is what i think. All the fields might not be mandatory and having a null check would save us there.
I agree you both but could he not Make those required fields i.e.
while(obj == null)
or is this what you suggesting?
Joined: Oct 13, 2005
It all depends on the design of your application. There are some cases where you may permit nulls, eg in middle names. There are some cases where nulls would be dangerous, so an exception is warranted. There are some cases where the user will know the data, and can supply the information from a prompt. There are some instances where the user may not know those data, and there is a risk of their entering wrong data.
All those suggestions are therefore correct, in different circumstances.