Month: April 2013

So, Singleton or Monostate?

So, Singleton or Monostate?

Continuing with the design pattern fun, lets talk about one of the most commonly used pattern, Singleton and an alternative called Monostate. I too wrote about singleton pattern relative to Joshua Bloch’s Effective Java a few days back. The Basic Difference in Two Well what is this monostate we talk about? Monostate is very similar …

+ Read More

HttpClient and Web Sniffers

HttpClient and Web Sniffers

Introduction When I say HttpClient, I talk about a package i.e. org.apache.commons.httpclient in commons-httpclient. HttpClient is used for making post and get request to particular URIs. And one can all kinds of things with the response and response headers. A simple example of sending a: What’s strange with HttpClient? By default, a http request sent …

+ Read More

Generics And Parameter Type Hiding

Generics And Parameter Type Hiding

Generics is an essential ingredient for a extensible and crafty design. When used wisely, generics make a programming language look good. Spiderman has reminded us repeatedly that with great power comes great responsibility. With all the extensibility we might toss the whole point type safety if generics are not used carefully. The following is a discussion …

+ Read More

Validation API for Complex and Multiple Validations

Validation API for Complex and Multiple Validations

I designed a very simple validation API when I was learning about Builder Pattern. Now, I have improved the code and used it in a small project. The code is now- Generic Can return return objects Has support for compound validators Other improvements have been made; like readability and updating comments Please find the code …

+ Read More

Kth maximum element in unsorted collection

Kth maximum element in unsorted collection

Finding the Kth maximum element in an unsorted array doesn’t seem to be a big deal. Because, we know that finding the maximum and if we keep on eliminating the largest element from the array. And this we will take us to the Kth maximum element in an array. But this solution is of order …

+ Read More

Item 15: Minimize Mutability

Item 15: Minimize Mutability

Confused what Item 15 is? Well, as I have already mentioned in my previous posts, ‘Items’ are 78 items mentioned in Joshua Bloch’s book ‘Effective Java’. Those, well versed with the items in Effective Java may read them as a reminder, rest can have fun getting to know things. Moving to the next item, minimizing …

+ Read More

String Intern

String Intern

  String#intern Probably you already know what it is, in case you don’t, please don’t stop unless you read and understand the whole thing.   String Interning String interning is a method where each distinct and immutable value of string is stored in a data structure. The data structure is called a string pool. The …

+ Read More