In this post under Spring Core, I will show with example how to use “@Value” annotation. In previous post I showed how to access system properties, environment properties, custom properties using “Environment” interface. In all these case we had to explicitly retrieve the value as shown below and are not injected into the bean automatically…… Continue reading Spring @Value annotation
Month: August 2024
Iterating a list in both direction
In this post under Java, I will show with example how to iterate a list in both directions. For iterating in both direction, we will take the help of “ListIterator” class. We get an instance of “ListIterator” by calling “listIterator” method on a list. Below is the code snippet, where “integerList” is a list of…… Continue reading Iterating a list in both direction
Sorting a list
In this post under Java, I will show with example how to sort a list. Below is the complete main class for your reference Main class 1 package core.collection; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.List; 6 7 public class SortingList { 8 public static void main(String []args) { 9 List<Integer> integerList…… Continue reading Sorting a list
assertThrows vs assertThrowsExactly example
In this post under JUnit, I will show with example the purpose of “assertThrowsExactly” method and how it is different with “assertThrows” method. I have explained with example, the purpose of “assertThrows” static method in previous posts. For recap, “assertThrows” method asserts that the test method throws the expected exception. If the test method doesn’t…… Continue reading assertThrows vs assertThrowsExactly example
IllegalRegexRule example
In this post under Passay, I will explain with example the purpose of “IllegalRegexRule” class. In one of my previous post, I have explained with example the purpose of “AllowedRegexRule” class. We will have recap of it here. When validating password, we mainly check whether the password follows a particular pattern. If the password follows…… Continue reading IllegalRegexRule example
beforeAll and afterAll annotation
In this post under JUnit, I will explain with example the purpose of “beforeAll” and “afterAll” annotations. In the previous post under JUnit, I covered about “beforeEach” and “afterEach” annotation. Similarly to “beforeEach” and “afterEach”, “beforeAll” and “afterAll” is applied to methods. But methods annotated with “beforeEach” and “afterEach” annotations are executed before and after…… Continue reading beforeAll and afterAll annotation
Custom Canonical constructor in Record
In the previous post under Java Record, I mentioned how the compiler creates a long (canonical) constructor automatically. In this post, I will explain how to create a custom canonical constructor. Now why we need to provide a custom canonical constructor when it is already provided by compiler. The canonical constructor created by compiler will…… Continue reading Custom Canonical constructor in Record
Collections checkedCollection example
In this post under Java, I will explain with example the purpose of Collections “checkedCollection” method. From Java 5 onwards, we started using Generics to ensure compile time type safety. As a result of which we were unable to add element of one data type to collections of elements of another data type. At compile…… Continue reading Collections checkedCollection example
Collections indexOfSubList method
In this post under Java Core, I will explain with example the pupose of Collections’ “indexOfSubList” method. Lets say they are two lists list1 and list2. “indexOfSubList” will search in list1 for position from where the elements of “list2” are repeated in “list1”. Once the position is found it is returned as index. In other…… Continue reading Collections indexOfSubList method
Skipping mapping of particular attribute
In this post under MapStruct, I will show with example how to configure MapStruct to skip particular attribute mapping from source to destination. For our example I will use the below pojo classes as shown below Student package package3; public class Student { private int id; private String name; private String className; public int getId()…… Continue reading Skipping mapping of particular attribute