Aug 24
As per Joshua Bloch Effective Java Second Edition, Item 9 Always override hashCode when you override equals.
“You must override hashCode in every class that overrides equals. Failure to do so
will result in a violation of the general contract for Object.hashCode, which will
prevent your class from functioning properly in conjunction with all hash-based
collections, including HashMap, HashSet, and Hashtable.”
Another Important Line from the Effective Java “In hashCode method you must exclude any fields that are not used in equals comparisons,
or you risk violating the second provision of the hashCode contract”(To refer to contract look into Object.java (javadoc))
I want to add to this and say :
Always compareTo method should reflect same logic as you have in equals. Continue reading »
Mar 18
Simple Approaches for achieving Sync between two Databases of an application.
Introduction
Since the title of the article is quite vague, let me try to make it more specific. The main purpose of this article is to put down few of the simple approaches which can be chosen to build an offline version of an application. The article does not cover all areas for creating an offline application. Main idea here is to explain few of the approaches I came across or worked on, to sync two databases, where the tables between the two DBs are same and data needs to be transferred. The use case for such applications is when people want to create an offline version of their applications, which can run without internet for a while. Later they want to push and pull change to and from the server respectively. There are already off the shelf tools available to achieve DB sync, but mostly the issue with them is on customization effort. Therefore I wanted to put forward few of the simple things one can achieve programmatically with little effort to achieve the basic purpose. Remember cost of simplicity is mostly the complex scenario’s handling. Here also the approaches listed can help you achieve sync but may not work for every boundary case. Hence based on your requirements you might need to customize the given approaches further during your specific implementation.
The approaches listed down are neither exhaustive nor by any standards the best possible ways. But they can help achieve the purpose with least number of changes being made to the existing DB and will work in a practical scenario. Continue reading »
Dec 15
Ok, the post topic is a bit grandiose, it should have been “Development time swap of spring beans using a custom classloader”, so a few disclaimers, I am only talking about development, I am not aiming for the most optimal solution and yes I am still working on it. The blog is about an approach that comes with some code snippets. Is more of an idea implemented for a very particular problem which can be applied in a more generic way rather than an actual generic solution. Continue reading »
Sep 01
Introduction
Java XML APIs have been one of the most used APIs in Java world. Still I think most of you would agree with me that there are so many mysteries in it, that even for developers who have been working on them for ages, it is a bit scary. The cumbersome implementations have only multiplied the horrors. But fact of the matter is whether you love or hate them, you need to live with them and use them in the most effective manner to solve the problem at hand while spending minimum of your effort in figuring out ways to parse the XML. In this article I would like to mention few small idiosyncrasies which I had to face while working with XML APIs. I have worked with Xerces and Xalan implementations and therefore my experience is based on these implementations. Continue reading »
Aug 25
Anyone who has done some serious development knows about debugging. There is a lot of stuff that goes under the hood for debugging, this blog takes a look at some of these. After reading this blog the reader may have a better understanding of the reason behind rare but weird errors about the “line number information not being present” when we try setting a break point. To keep things simple I am going to cover only the basics and will oversimplify and generalize without much discretion.
There are two parties in debugging Continue reading »
Recent Comments