What is the better approach to implement Singleton pattern?

Singleton is one of the frequently used and easily understandable design pattern. Most of the tutorials and books give example of making the constructor as private and exposing a static method which will provide single instance. The common example they use is Runtime class of JRE.

Is making constructor as private is the only way to implement singleton pattern? Is that the best way to implement singleton pattern?

Read more of this post

Java: How to stop a thread?

Sun deprecated Thread.stop() because it is unsafe. They didn’t provide any direct alternative for this operation; instead they are making us to reinvent the wheel. Here I am sharing my style of safe thread stop implementation. Read more of this post

Volatile and doubled checked locking in Java

During my Java training, I read about volatile keyword, but didn’t get clear understanding. Recently when I wrote a singleton class using double checked locking, PMD code reviewer gave a warning not to use volatile. Later I started exploring on double checked locking issue, here is my observation.

Read more of this post

Importance of specifying initial capacity while instantiating ArrayList and HashMap

ArrayList and HashMap are a few of the most frequently used data structures in Java development. So I would like to talk about the importance of instantiating these classes with initial capacity. Let me explain how the ArrayList works internally, so that you get a good insight. HashMap works almost the same way an ArrayList works, so I haven’t covered the details of that separately. But all the tips given below are applicable for HashMap as well.

Read more of this post

Java serializable interface

I was trying to understand the concept behind the java serialization.

I know java serialization is required when you want to save state of an object outside JVM. My thinking was why don’t Sun make all classes as Serializable by default? Why Serializable interface required to persist an object?

Read more of this post

Distributed vs Non-distributed Architecture

Is distributed architecture more scalable than non-distributed architecture?
Many J2EE architects and developers tend to assume distributed architecture offers unmatched scalability. However this assumption is questionable.

Read more of this post

Tool vs. Manual Porting

Many companies are migrating their application from one technology to another technology for various reasons. It is good as a developer; it provides more job security and opportunity for us. For porting generally there are two approaches: Manual and Tool based porting. Lets take an example of porting COM application into Java platform. There are quite a few vendors offering toolkit/engine to run the COM code inside J2EE application server. But most of the developer will be more comfortable to rewrite the code based on the new platform. Lets analysis Pros and Cons of both these approaches. For the discussion I took COM to Java as an example. Read more of this post