Before writing this post, I am assuming that you know the basics of junit. If you do not have the basic knowledge, first read this link. Further, in this post, I will write the best practices you must consider before writing your test cases. Table of Contents: Unit testing is not about finding bugs Tips […]
Friends, we have been using exception handling in our code for almost every industry standard application. Usual approach is to create some custom Exception classes extending the base Exception class. In this post, I will suggest another approach which might make you more sense. This post is part of series related to best practices and […]
Have you ever tried to reason, why main method in java is public, static and void? I tried to find out and after some analysis, below are my findings. Please feel free to add if i am missing anything, I will update this post. Sections in this post: Why public? Why static? Why void? Why […]
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.
Learn about java abstract classes vs interfaces in details. Also learn about when to use interface and when to use abstract class in solving design issues.
In simple words, abstraction captures only those details about an object that are relevant to the current perspective. Learn more about abstraction in java.
In this post, I will write a piece of code which will create a deadlock situation and then i will discuss that way to resolve this scenario. In my previous post, i written about Auto reload of configuration when any change happen, i discussed about refreshing your application configuration using a thread. As configurations are shared […]
Today, most applications are required to manage their own log files included removing them when they reach at a particular size limit. In this article, i will try to propose a solution for this kind of log file management. I will also suggest the way to capture the output of linux process and log it […]
In my previous posts, i have discussed about HashMap’s internal working and how to correctly override equals() and hashCode() methods. In this post, i am writing about a solution of very common problem. Every application has some configuration which is expected to be refreshed on every change in configuration file. Past approaches to solve this […]
Most of you will agree that HashMap is most favorite topic for discussion in interviews now-a-days. I have gone through several discussions with my colleagues time to time and it really helped. Now, I am continuing this discussion with you all. I am assuming that if you are interested in internal working of HashMap, you […]
In this post, I will point out my understanding about hashCode() and equals() methods. I will talk about their default implementation and how to correctly override them. I will also write about implement these methods using Apache Commons package’s utility classes. hashCode() and equals() methods have been defined in Object class which is parent class […]