How to Create and Order Custom Interceptors and Filters in Spring Boot

In a Spring Boot application, managing HTTP requests and responses is critical for implementing cross-cutting concerns such as logging, security, and authentication. Interceptors and Filters provide two key mechanisms for this purpose. Additionally, you might need to specify the order in which these interceptors and filters are executed to ensure the correct flow of operations. In this post, we’ll walk through how to create both a custom Interceptor and a custom Filter in Spring Boot, and how to define the order in which they should be executed....

September 13, 2024 · 5 min · 910 words · PandaC

Heap Fragmentation: A Guide for Interview

We will cover everything you need to know about heap fragmentation, including why it happens, its impact, how to control it, and how different JVM versions handle it, along with JVM options to manage fragmentation. What is Heap Fragmentation? Heap fragmentation occurs when the free memory in the heap is split into small, scattered blocks. This fragmentation makes it difficult for a program to allocate large chunks of memory, even if the total free memory is adequate....

September 4, 2024 · 6 min · 1172 words · PandaC

Understanding Internal Implementation of HashMap and HashSet in Java

When working with Java, two commonly used data structures are HashMap and HashSet. These collections are highly efficient, but their efficiency relies on how they handle internal operations, especially when it comes to collisions. This blog will explain the internal workings of HashMap and HashSet in simple terms and provide examples to help you understand how they manage collisions. What is a HashMap? A HashMap is a data structure that stores key-value pairs....

August 25, 2024 · 6 min · 1108 words · PandaC

Understanding the Singleton Design Pattern

The Singleton Design Pattern ensures that a class has only one instance and provides a global point of access to it. To achieve thread safety, reflection safety, and serialization safety, you need to handle specific concerns. Let’s explore how to implement a Singleton pattern that addresses these concerns. Key Concepts: Thread Safety: Ensures that the Singleton instance is created in a thread-safe manner, so multiple threads do not create multiple instances....

August 25, 2024 · 3 min · 567 words · PandaC

Understanding the Prototype Design Pattern

The Prototype Design Pattern is a creational pattern that involves creating new objects by copying an existing object, known as the prototype. This pattern is useful when the cost of creating a new object is more expensive than copying an existing one. It allows you to create objects without specifying their exact class and provides a way to clone objects efficiently. Components of the Prototype Design Pattern: Prototype: An interface or abstract class that declares a clone() method for copying itself....

August 24, 2024 · 3 min · 517 words · PandaC

Understanding the Factory Design Pattern

The Factory Design Pattern is a creational pattern that provides a way to create objects without specifying the exact class of the object that will be created. It defines an interface for creating an object, but allows subclasses to alter the type of objects that will be created. Components of the Factory Design Pattern: Product: The interface or abstract class that defines the type of object to be created. ConcreteProduct: Implements the Product interface and defines the specific object to be created....

August 23, 2024 · 3 min · 502 words · PandaC

Understanding the Builder Design Pattern

The Builder Design Pattern is a creational pattern that provides a way to construct complex objects step by step. It separates the construction of a complex object from its representation, allowing the same construction process to create different representations. Components of the Builder Design Pattern: Builder: An abstract class or interface that defines the steps for creating parts of a complex object. ConcreteBuilder: Implements the Builder interface to construct and assemble parts of the product....

August 22, 2024 · 5 min · 908 words · PandaC

Understanding the Abstract Factory Design Pattern

The Abstract Factory Design Pattern is a creational pattern that provides an interface for creating families of related or dependent objects without specifying their concrete classes. It involves creating an abstract factory interface that defines methods for creating abstract products, and concrete factories that implement this interface to create specific families of products. Components of the Abstract Factory Design Pattern: AbstractFactory: Declares methods for creating abstract product objects. ConcreteFactory: Implements the AbstractFactory interface to create specific products....

August 21, 2024 · 3 min · 602 words · PandaC

Understanding the Proxy Design Pattern

The Proxy Design Pattern is a structural pattern that provides a surrogate or placeholder for another object. It allows you to control access to the real object, providing additional functionality such as access control, lazy initialization, or logging. The proxy pattern involves creating a proxy class that implements the same interface as the real object and delegates requests to the real object. Components of the Proxy Design Pattern: Subject: An interface or abstract class that defines the common interface for both the RealSubject and the Proxy....

August 20, 2024 · 3 min · 538 words · PandaC

Understanding the Flyweight Design Pattern

The Flyweight Design Pattern is a structural pattern that optimizes memory usage by sharing common parts of objects to support a large number of similar objects efficiently. This pattern is used when you have a large number of objects with shared states and you want to minimize memory usage. Components of the Flyweight Design Pattern: Flyweight: An interface or abstract class that declares methods for managing and accessing extrinsic state. ConcreteFlyweight: Implements the Flyweight interface and defines the intrinsic state of the object....

August 19, 2024 · 3 min · 479 words · PandaC