Whenever a class in my model contains a collection which requires that particular care be taken with its items, there’s an internal debate regarding how to expose it to other classes. And with this, there are two major schools: one, the paranoia-based approach which doesn’t allow external code to touch the collection’s internal items and two, the trusting approach which just returns the collection for everyone to deal with.
Continue reading »
The Garbage Collection set of posts (Generations, Parallel and Concurrent, Tips and Memory Leaks) are ones that I am personally very proud of. First, they were very interesting to write, as the material is extremely interesting; second, a lot of people seemed to enjoy them, and found interest in reading them; and third, it seems that the first post was the most read post in the blog since November ‘07, and that’s even more remarkable when considering that the post was published on December!
Because of the last reason, which showed me how much people love the garbage collection subject, I’ve asked my sister to draw a little comic panel discussing the issue. I find it amusing; my sister’s partner found it tragic. I wonder what you think of it!
Continue reading »
Time for some refreshing the memory with a Java language feature probably few use, and maybe for a good reason. Suppose you’re running code on elements of an array up until a certain element is found. When your code finds that element, it stops the iteration. Therefore, your code might look like the following:
for (int i = 0; i < array.length && condition(array[i]); i++) {
// your code here
}
Or, if you’d like to use the new foreach feature, like this:
Continue reading »
