Iterators can be designed so that they are fail fast or fail safe. Depending on the underlying implementation of the Iterator, a ConcurrentModificationException is thrown if the Collection is modified while Iterating over the data structure. It pays to understand how an Iterator will behave under both conditions. Lets try to implement fail fast Vs fail safe iterators of our own.
Our data structure for this example is pretty simple. It defines an interface that abstracts set and get operations on a structure. How the underlying classes handle invalid set operations or the size of the structure is implementation dependent
A data structure interface:
1
2
3
4
5
6
| public interface Data<T> extends Iterable<T>
{
int size();
T getElement(int position);
void setElement(int position, T t);
} |
An underlying implementation of such an Interface, could be say an array of Integers whose size is fixed. Invalid indexes on bounds are not allowed and the internal structure will not grow or shrink. An implementation is given below
I came across a post on the Adam Bien blog recently about using the prefix ‘Abstract‘ to define Abstract classes. The argument was that using the ‘Abstract‘ prefix is superfluous. I do not fully agree with the post. As I read the points he had mentioned on the post, here are some that came to mind
Abstract classes are already distinguishable by the keyword abstract. There is no need to further emphasize it.
A prefix “Abstract” doesn’t provide any additional value to the user – in contrary it blurs the actual intention
The Abstract in the class name helps a developer know that a class is Abstract even before they open it. Of course if some one bucks the convention and names a Concrete class abstract, it creates confusion but that scenario is rare.
Modern IDEs don’t let you instantiate an abstract class, even before saving / compiling.
If you are a web developer, you would have encountered one of the following challenges.
- Ensure that your web page contents are not cached by the browser.
- Check if your clear text componenets are gzipped by the web server.
- Add additional request parameters / headers for testing.
- Determine if a stolen cookie can be used to login to the site.
- Analyze request / response times.
- Verify web server response status / headers.
Well, I could go on and on and the list is certainly large. Do you see anything common in the list mentioned above ? They all require a tcp monitor / web debugging proxy to solve. There are several that are available out there. If you have never used one before, its never too late. I was able to save several minutes of time when programming java web apps after marrying them with a debugging proxy / monitor.
The RSS cloud and the pubsubhubbub (PuSH) way of notifying RSS feeds has gained some interest of late, thanks to wordpress supporting the former format. If you have never heard of these protocols, heres the low down. The RSS feed works by having a client ‘pull’ data from a feed. That is, clients keep nagging at the server every X minutes saying ‘Hey do you have something new for me ?’. The server responds with a no about 99% of the time. This leads to a lot of inefficiencies. Instead if the clients were to use a push model, the data is actually ‘pushed’ to a client automatically without the client asking for it. This is great since the client no longer makes unnecessary calls to the server. The diagrams below illustrate this.
Classic update:

Rss Cloud update:

I have been researching captchas recently . The goal being, to understand how to make captchas better. I spent some time trying to determine the various forms of catcha available out there. There were quite a few and some were innovative (innovative does not necessarily mean easy to use
). Here are some that will interest you

Recaptcha:
The most common form of captcha is recaptcha. Recaptcha does a good job of displaying some sort of cryptic letters and numbers to its users. But it is far from the captcha solution that an end user might want. An image based approach promoted by captcha.net is also available, but some images are thoroughly confusing. I am currently researching better ways to categorize and display images. There are more problems to be discussed in image based captchas, which I would rather cover in a seprate post with an implementation.