We all know the basic statement that finalize() method is called by garbage collector thread before reclaiming the memory allocated to the object. In this post, we will drill down more deeply into this method. Sections in this post: finalize() execution is not guaranteed at all (with example) Other reasons for not using it finalize() […]
Abstract factory pattern is yet another creational design pattern and is considered as another layer of abstraction over factory pattern. In this post, i will expand the problem statement discussed in previous post and will see, how abstract factory pattern solve the problem. In my previous post, “Implementing factory design pattern in java“, we discussed […]
An immutable class is one whose state can not be changed once created. There are certain guidelines to create an class immutable. In this post, we will revisit these guidelines. Sections: Benefits of making a class immutable Guidelines to make a class immutable Benefits of making a class immutable Lets first identify benefits of making […]
All of us must have gone though interview questions related to String class in java. These questions range from immutability to memory leak issues. I will try to cover such questions in this post. String Interview Questions discussed below: Why strings are immutable? String pool concept Keyword ‘intern’ usage Matching Regular expressions? Strings comparison? Memory […]
What is the most usual method of creating an instance of a class in java? Most people will answer this question: “using new keyword“. Well, it is considered old fashioned now. Lets see how?? If object creation code is spread in whole application, and if you need to change the process of object creation then […]
Singleton pattern is a design solution where an application wants to have one and only one instance of any class, in all possible scenarios without any exceptional condition. It has been debated long enough in java community regarding possible approaches to make any class singleton. Still, you will find people not satisfied with any solution […]
Easy to follow examples of sorting a collection of objects in any order using Comparable or Comparator Interfaces.
Life has become very easy for java programmers working on multi-threaded applications after release of JDK 5. JDK 5 brought many features related to multi-threaded processing which were kind of nightmare for application developers, and even worse for those who had to debug this code in future for bug fixing. Sometimes, this resulted in deadlock […]
This article solves a very common problem of configuration reloading on run time, which is usually required in most of the today’s applications. In auto reload configuration using WatchService, we saw the use of JDK 7’s new API WatchService. In this post, i will use a rather easy approach i.e. apache commons configuration. .Using commons […]
In this tutorial, I will explain the encapsulation in java and its relation with abstraction. Also learn about information hiding and implementation hiding.