The N+1 query problem is said to occur when an ORM, like hibernate, executes 1 query to retrieve the parent entity and N queries to retrieve the child entities. As the number of entities in the database increases, the queries being executed separately can easily affect the performance of the application. This article will demonstrate how N+1 queries occur and their solution through an example in spring boot.
Consider a Content Management System that stores a list of articles per publication. A publication can have a category and list of articles associated with it. …
Set is a built-in data type present in both Python and Java but both of these languages handles the elements in a set differently.
Though the underlying implementation of set is the same in both languages, Java lets you add mutable objects, such as a list to a set, whereas Python does not.
In python, when you try to add an entire list to a set, compiler throws an error:
The usual convention to name methods that return boolean is to prefix verbs such as ‘is’ or ‘has’ to the predicate as a question, or use the predicate as an assertion. For example, to check if a user is active, you would say user.isActive() or to check if the user exists, you would say user.exists().
But when the intention is to check if the user is not active, I've come across code that is written as user.isNotActive() or user.isInactive(). …
If you have ever used Streams and Optionals in Java, you must have come across lambda expressions and functional interfaces. But how exactly are lambda expressions tied to functional interfaces?
This article will talk about functional programming in Java and how Streams and Optionals make use of functional interfaces.
What is a functional interface?
An interface that has only one abstract method (unimplemented method) can qualify to be a functional interface. It may or may not have other default and static methods.
How does your room look when you have all your things cluttered on your table/shelf? How long will it take to find things from the heap of dump?
Thats exactly how a codebase written with more than 25 lines of code in a function and methods not at the right place will look like.
The code might run without errors and you might very well understand the code you wrote.
But the quality of code you write should be determined by how well another developer can understand your code.
When it comes to object oriented programming, maintaining a clean codebase…
Often we like to attach abilities to our class but it is mostly done as a delegate and not as a mixin in Java.
We will explore in this blog on implementing mixins in Java using first class collections.
First class collection means a collective object is given domain importance. It has to behave as a collection as well as a domain object.
Rule 4: Object Calisthenics by William Durand
Any class that contains a collection should contain no other member variables. If you have a set of elements and want to manipulate them, create a class that is dedicated…