Fading Coder

One Final Commit for the Last Sprint

Understanding Java's Class Object and Its Role in Reflection

In Java, the Class<T> type is a foundational component of the runtime system. Located in the java.lang package, it serves as the entry point for introspecting types at runtime. Every class, interface, array, primitive type, and even void has a corresponding Class object managed by the JVM. The...

Understanding the Simple Factory Pattern

The Simple Factory Pattern is a creational design approach that provides a centralized mechanism for creating objects. Although it is not formally included in the Gang of Four's 23 design patterns, it is widely practiced and often referred to as the Static Factory Method pattern. Its primary objecti...

Using ResolvableTypeProvider to Handle Generic Events in Spring

Spring's event listener mechanism is useful for decoupling code. Consider a scenario where you need to synchronize data changes for different entities like Person or Order to an external service after database operations. A straightforward approach couples the synchornization logic directly with the...

Understanding Java's Historical Timezone Offsets and the 1900 Shanghai Anomaly

When working with legacy date-time APIs in Java, developers occasionally encounter unexpected timestamp shifts when processing dates near the turn of the 20th century. A particularly notable anomaly occurs when parsing and formatting timestamps around January 1, 1900, in the Asia/Shanghai timezone....

Efficiently Counting Inversion Pairs in Stock Records Using Merge Sort

Problem Definition Given an array of stock prices representing daily records, an inversion pair is defined as a tuple $(i, j)$ where $i < j$ and $record[i] > record[j]$. The objective is to calculate the total count of such pairs within the input array. For instance, given the input [9, 7, 5, 4, 6],...

Using Kafka and Flink for Real-Time Data Processing

Implementing a Kafka Producer Below is a Java-based Kafka producer implementation that sends data to a Kafka topic on a scheduled basis: @Configuration @Slf4j public class ScheduledDataProducer extends Thread { public static final String BROKER_URL = "your_broker_ip:9092"; public static fi...

Java Collections: Generics, Data Structures, and Set Implementations

Generics in Java CollectionsGenerics enable type-safe operations on collections during compilation. A generic class is defined using the syntax:access_modifier class ClassName<GenericType> { }The generic type parameter accepts reference types exclusively; primitive types are not permitted. For...

Transposing Rows and Columns in Two-Dimensional Arrays

Implementing a Java program to transpose rows and columns in a two-dimnesional array: Original matrix: 1 2 3 4 5 6 7 8 9 Transposed matrix: 1 4 7 2 5 8 3 6 9 public class MatrixTransposer { public static void main(String[] args) { int[][] matrixData = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; System.out.pr...

Integrating MyBatis with Spring Boot Applications

Database Schema Setup Create the user table with the following SQL definition: CREATE TABLE `tb_user` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `username` varchar(50) NOT NULL COMMENT 'User Name', `age` int(11) NOT NULL COMMENT 'User Age', `ctm` datetime NOT NULL COMMENT 'Creatio...

Java Development: RocketMQ Consumer Message Idempotent Deduplication

A production-ready generic utility class for RocketMQ consumer message idempotent deduplication, with no additional configuration overhead beyond basic setup. Core Capabilities Supports using Redis or MySQL as the idempotent record storage layer Flexible deduplication key options: use business prima...