CollectionUtils getCardinalityMap method

In this post under Apache Collections, I will explain with example, the purpose of CollectionUtils “getCardinalityMap” method. This method takes a collection as an argument and returns a map. A map where key is an element from the collection, and value will be the number of times the element is repeated in the collection. So…… Continue reading CollectionUtils getCardinalityMap method

CollectionUtils intersection method

In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “intersection” method. The “intersection” method compares two collections and return a new list containing items that are common in both of them. Below is the complete main code for your reference. Main class 1 package defaultPackage; 2 3 import org.apache.commons.collections4.CollectionUtils;…… Continue reading CollectionUtils intersection method

“required” attribute of @Autowired annotation

In this post under Spring Core, I will explain with example the purpose of “required” attribute of “@Autowired” annotation. When we tell Spring framework to wire two beans say “Bean2” to “Bean1” as shown below package package20;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class Bean1 { @Autowired private Bean2 bean2; public Bean2 getBean2() { return bean2; } public void…… Continue reading “required” attribute of @Autowired annotation

CollectionUtils containsAny method

In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “containsAny” method. This method is used to compare two collections. It returns true if both the collections has atleast one element in common or else false. Below is the main class for your reference Main class 1 package defaultPackage;2 3…… Continue reading CollectionUtils containsAny method

Example of @Autowired (setter injection approach 2)

In this post under Spring Core, I will show another approach of achieving setter injection using “@Autowired” annotation. In my previous posts, I showed with example how to achieve setter injection by applying “@Autowired” annotation at field level. In this post I will show how to achieve setter injection by applying “@Autowired” annotation directly on…… Continue reading Example of @Autowired (setter injection approach 2)

Example of @Autowired (constructor injection)

In this post under Spring Core, I will show with example, how to use “@Autowired” annotation for constructor injection. In previous post, I showed how to use “@Autowired” annotation for setter injection. We call an approach as setter injection, when Spring framework automatically inject dependency to an object by calling the setter method of the…… Continue reading Example of @Autowired (constructor injection)

Generating random password

In this post under Passay, I will show with example how to generate random password. For our example I will generate a random password of length 15 characters containing english lowercase characters, uppercase characters, special characters and digits. Below is the complete code for your reference. Main class 1 package defaultPackage;2 3 import java.util.ArrayList;4 import…… Continue reading Generating random password

Verifying password has alphanumeric and special characters

In this post under Passay, I will show with example how to verify whether a password has alphanumeric and special characters. Below is the Main class for our example Main class 1 package defaultPackage;2 3 import java.util.ArrayList;4 import java.util.List;5 import java.util.Scanner;6 7 import org.passay.CharacterRule;8 import org.passay.EnglishCharacterData;9 import org.passay.PasswordData;10 import org.passay.PasswordValidator;11 import org.passay.Rule;12 import org.passay.RuleResult;13 14…… Continue reading Verifying password has alphanumeric and special characters

CollectionUtils collect method

In this post under Apache Collections, I will explain with example the purpose of “collect” static method in “CollectionUtils” class. The “collect” method takes a list of items, process or transform them and then create a new list containing transformed items. Below is an Main example showing its usage. Main class 1 package defaultPackage;2 3…… Continue reading CollectionUtils collect method

Example of @Autowired (setter injection approach 1)

In this post under Spring Core, I will explain with example the purpose and how to use “@Autowired” annotation. Till now in all my previous posts, you have seen how to create a bean. We can create a bean using either “@Bean” or “@Component” annotation. I have also showed you how to wire one “@Bean”…… Continue reading Example of @Autowired (setter injection approach 1)