Author: Editorial Team
-
Unit Testing JSON Responses with JsonAssert in Spring Boot
In this tutorial, we will explore how to write effective unit tests for REST controllers that return JSON responses. We will dive into using the JsonAssert library, which simplifies asserting JSON content by ignoring irrelevant differences such as spacing and order, and focusing only on the important fields. Prerequisites spring-boot-starter-test brings in dependencies like JUnit, Mockito, Hamcrest, and importantly, JsonAssert—which we’ll use…
-
Unit Testing RESTful Web Services in Spring Boot with MockMvc and Mockito
Testing is a crucial part of developing robust web applications, especially RESTful services built with Spring Boot. This detailed tutorial guides you step by step through the process of unit testing the web, business, and data layers of a Spring Boot application using MockMvc, Mockito, and key Spring testing features. You’ll also learn best practices for test…
-
Class loading process in Java
The class loading process in Java 21, while having evolved significantly from earlier versions (especially with the introduction of modules in Java 9), still fundamentally follows a three-step delegation model: Loading, Linking, and Initialization. However, the context of modules and the removal of the Extension Class Loader in favor of a simpler application class loader…
-
Gossip Protocol for Peer-to-Peer Communication
Overview The Gossip Protocol is a robust, fault-tolerant, and highly scalable approach for disseminating information across distributed systems. Inspired by how rumors spread in social settings, it enables systems to communicate and share state information efficiently with minimal overhead, even in large and dynamic networks. It is especially valuable in decentralized architectures where maintaining a…
-
Data Masking and Tokenization in Microservices
1. Overview With the increasing shift to microservices-based architectures, applications often become responsible for handling sensitive data such as credit card numbers, Social Security Numbers (SSNs), phone numbers, and health records. It becomes imperative to secure this sensitive information to meet compliance requirements such as GDPR, HIPAA, and PCI-DSS. This tutorial explains two common data…
-
Bcrypt: A Tutorial for Secure Password Hashing
1. Introduction In the world of web applications, password security is paramount. Storing user passwords directly in a database is an absolute no-go. If your database is ever compromised, those passwords become immediately available to attackers, leading to widespread account takeovers. This is where password hashing comes in, and among the strongest and most widely…
-
YAGNI – You Aren’t Gonna Need It (in OOP)
1. What is YAGNI? At its core, YAGNI is about minimalism and just-in-time development. It’s the practice of not adding any extra functionality or complexity to your code unless there’s a clear and present need for it. Think of it as resisting the urge to: 2. Why is YAGNI Important in OOP? While speculative generality…
-
What is the difference between javax @Transactional and Spring framework @Transactional
The @Transactional annotations from javax.transaction (part of the Java Transaction API – JTA, now part of Jakarta EE) and org.springframework.transaction.annotation (from the Spring Framework) both serve the same fundamental purpose: to declaratively manage transaction boundaries in Java applications. However, they originate from different ecosystems and have distinct characteristics and ideal use cases. Here’s a breakdown…
-
orElse() vs orElseGet() in Optional
The main difference between orElse and orElseGet in the Java Optional class is when and how the default value is computed: Method Argument Type When is it evaluated? Use Case orElse T (actual value/result) Always, even if Optional is present Use when default value is cheap to create or constant orElseGet Supplier<? extends T> Only if Optional is empty Use…
-
What is the role of schema registry when using kafka with Avro? Explain with an example
When using Apache Kafka with Avro for message serialization, the Schema Registry plays a critical role in managing, validating, evolving, and retrieving schemas for the data being sent and received. Here’s an explanation of its role—along with a practical example. What is a Schema Registry? A schema registry is a centralized service that stores and manages Avro…
