This is another debated subject, but this time i am searching only for the simple and documented answers. The scenario :
Let\'s assume the following method:
You ask five questions
1. What ways do u suggest on improving this technique of returning some dogs, with some attribute?
Several, actually.
2. rs.next() will return false for a null ResultSet, or will generate an exception
This doesn't seem to be a question, but yes, rs.next() returns false as soon as there's no longer any rows to process.
3. What if, while initializing a dog object from the current row of the ResultSet, something bad happens
If "something bad happens", what you do next is up to you and your design. There's the forgiving approach (return all the rows you can), and the unforgiving (throw an exception). I tend to lean towards the "unforgiving" approach, since with the "forgiving" approach, users won't know that you haven't returned all the rows that exist - just all the ones you'd gotten before the error. But there might be cases for the forgiving approach.
4. I think u will all agree on this one : nothing bad happens, there are no rows on the interrogation, a null value will be return.
This isn't something on which there's an obvious right answer. First, it's not what's happening in the method as written. It's going to return an empty HashTable (this is what was meant by a "null object"). Second, null isn't always the answer in the "no results found" case.
I've seen null, but I've also seen an empty result variable instead. I claim they're both correct approaches, but I prefer the empty result variable. However, it's always best to be consistent, so pick a method of returning "no results" and stick with it.
5. I've noticed people and groups of people saying that one should split the application into layers, or levels of some kind.
This is harder to answer than the others, without seeing the rest of your application.