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)
Using @Profile on @Component annotated beans
In the previous post under Spring Core, I showed how to use “@Profile” annotation with “@Configuration” and “@Bean” annotation. In this post under Spring Core, I will show with example how to use “@Profile” annotation with “@Component” annotation. In previous post I also mentioned that “@Profile” annotation can be used with “@Configuration”, “@Bean”, and “@Component”…… Continue reading Using @Profile on @Component annotated beans
CollectionUtils containsAll method
In this post under Apache Collections, I will show with example the purpose of “CollectionUtils.containsAll” method. While developing applications we come around situations where we have to check whether elements of one collection is also present in another collection also or not. To do this, Apache Collections framework provides “CollectionUtils” utility class “containsAll” method. This…… Continue reading CollectionUtils containsAll method
Adding and accessing static members to Java Record
In this post under Java, I will show with example how to add and access static members in Java Record. Below is the structure of “Student” Record with static members Student 1 package core.record;2 3 public record Student(int id, String name, int age) {4 public static int noOfStudents;5 public static void display() {6 System.out.println(“Number of…… Continue reading Adding and accessing static members to Java Record
Simple Java Record Example
In this post under Java, I will introduce you with example to Java’s Record classes. Introduced in Java 16, is a immutable data class, whose main purpose is hold read only data. Below shows how to create Record class. Person Record package core.record;public record Person(int id, String name, int age) {} We save the file…… Continue reading Simple Java Record Example
Using @Profile on @Beans annotated beans
In the previous post under Spring Core, I showed how to use “@Profile” annotation with “@Configuration” annotation. In this post under Spring Core, I will show with example how to use “@Profile” annotation with “@Bean” annotation. In previous post I also mentioned that “@Profile” annotation can be used with “@Configuration”, “@Bean”, and “@Component” annotation. The…… Continue reading Using @Profile on @Beans annotated beans
Creating a custom serializer or deserializer
In this post under GSon, I will explain with example how to create custom serializer and deserializer and configure Gson object to use it. For our example lets take the below JavaBean Class structure. Student package defaultPackage;import java.util.Date;public class Student { private int id; private String name; private Integer rollnum; private Date date; public int…… Continue reading Creating a custom serializer or deserializer
Serialize and DeSerialize Generic classes
In this post under Gson, I will show with example how to serialize and deserialize generic classes. Below is the complete code for your reference Main class 1 package defaultPackage;2 3 import com.google.gson.Gson;4 import com.google.gson.reflect.TypeToken;5 6 import java.lang.reflect.Type;7 import java.util.ArrayList;8 import java.util.List;9 10 public class GsonDemo16 {11 public static void main(String[] args) {12 List<String> actors…… Continue reading Serialize and DeSerialize Generic classes
Using @Profile with @Configuration classes
In this post under Spring Core, I will show with example how to use “@Profile” annotation for “@Configuration” annotated classes. In the real world scenario, whenever we develop an application, we develop with a goal that it should perform according to agreed functional requirements, regardless of whether the application is running in production or testing…… Continue reading Using @Profile with @Configuration classes
Verifying password is of specified length
In this post under Passay, I will show with example how to verify that the password is of specified length. Below is the complete code for your reference Main class 1 package defaultPackage;2 3 import org.passay.LengthRule;4 import org.passay.PasswordData;5 import org.passay.PasswordValidator;6 import org.passay.Rule;7 import org.passay.RuleResult;8 9 public class Example3 {10 public static void main(String[] args) {11…… Continue reading Verifying password is of specified length