What is Java object equals contract?

The object equals contract indicates that when two objects are equal, their hash codes must also be the same. It’s a general agreement for all Java objects used in hash-based collections. Its main purpose is to optimize performance when working e.g. with HashMap or HashSet.

You may hear that when you implement the equals() method for your class, you should also implement the hashCode() method. That’s the practical approach for fulfilling the equals contract.

If you want to know more details why the contract is so important, keep on reading.
Continue reading “What is Java object equals contract?”

HTTP cache with Spring examples

Caching is a powerful feature of the HTTP protocol but for some reason, it’s mainly considered for static resources like images, CSS stylesheets, or JavaScript files. However, HTTP caching isn’t limited to application’s assets as you can also use it for dynamically computed resources.

With a small amount of work, you can speed up your application and improve the overall user experience. In this article, you will learn how to use the built-in HTTP response cache mechanism for Spring controller’s results.

Continue reading “HTTP cache with Spring examples”