In this Engineering With Java newsletter edition, we have hand-picked some interesting Java and Spring articles worth reading. Topics include Mock API, Exception handling with CompletableFuture, NoSQL With Jakarta, Spring
Boot profiling tools, Optimizing UUID primary keys, etc.
🚀 Grokking the Java Interview 🚀
Crack your Java interview by preparing important topics and mastering key concepts in a guided and structured way in a short time.Â
1. Mock APIs with Playwright
This article covers how to use Playwright, a popular end-to-end testing framework, to mock APIs during automated tests.
It explains how mocking APIs can help simulate different server responses, reduce test flakiness, and improve testing speed by bypassing actual network requests.
The guide walks through configuring mock responses, handling request interceptions, and testing various scenarios like error handling and latency. This approach allows for more controlled and reliable tests.
2. Java: Exception Handling in CompletableFuture
This article provides a comprehensive look at managing exceptions in asynchronous operations using
CompletableFuture
, helping developers write more robust and reliable asynchronous code in Java.Key Points:
Exception Handling Strategies: The article discusses different methods for handling exceptions in
CompletableFuture
workflows, including:handle
Method: Allows handling of exceptions as well as results.exceptionally
Method: Provides a way to handle exceptions by returning a default value.
Chaining Futures: It explains how to chain multiple
CompletableFuture
stages and handle exceptions that might occur in any stage of the chain.Combining Futures: It covers combining multiple futures and how to handle exceptions that may arise from any of the combined futures.
Completing Futures with Exceptions: The article also discusses how to manually complete a
CompletableFuture
with an exception and how this affects exception handling in dependent stages.Best Practices: Emphasis is placed on using the appropriate method based on the scenario and maintaining clean and readable code by handling exceptions properly at each stage.
3. Jakarta NoSQL: A Modern Approach
The article provides an in-depth look at Jakarta NoSQL, a framework designed for modern data storage solutions.
It highlights its flexibility, scalability, and performance advantages over traditional relational databases.
The framework supports different data models (document, key-value, column-family, graph), is schema-less, horizontally scalable, and offers high availability and fault tolerance.
Ideal for applications like IoT, gaming, and real-time analytics, Jakarta NoSQL helps businesses handle unstructured data efficiently.
4. Spring Data JPA: Integrating with NoSQL Databases
This article explores integrating NoSQL databases with Spring Data JPA. It highlights how Spring Data JPA, traditionally used with relational databases, can be adapted to work with NoSQL solutions like MongoDB, Cassandra, or Couchbase.
Key approaches include using Spring Data repositories, customizing query methods, and leveraging NoSQL's flexibility while retaining Spring’s familiar development model.
The article also emphasizes the performance and scalability benefits of NoSQL databases for specific use cases.
If you're preparing for interviews, I have some good news! I started a LinkedIn page called "Interview Prep 101," , where I post intriguing interview questions related to DSA, Java, Spring Boot, and SQL. If you're interested, feel free to follow the page!
5. Storing Value Objects in Postgres: A Tactical DDD Pattern Approach
This article discusses how to store value objects in PostgreSQL using a Domain-Driven Design (DDD) approach.
It focuses on leveraging tactical DDD patterns for efficiently handling value objects in database design.
Key techniques include custom types, JSON storage, and type-safe handling of value objects to maintain domain integrity while using Postgres.
The article emphasizes the practical application of these patterns in real-world scenarios, aligning DDD principles with database performance optimization.
6. Optimizing GUID/UUID Primary Keys for Performance
This article discusses strategies for optimizing GUID/UUID primary keys in databases for better performance.
While GUIDs/UUIDs offer benefits like global uniqueness, they can negatively impact performance due to their size and randomness.
The guide suggests ways to improve indexing and storage efficiency, such as using sequential GUIDs and partitioning to minimize index fragmentation and performance bottlenecks in large datasets.
7. How to profile a performance issue using Spring Boot profiling tools
This article discusses using profiling tools to improve Spring Boot application performance.
It discusses what profiling is and the different ways to do it. The article also details several open-source and paid profiling tools. Some of the important points from this article are that profiling is necessary to improve application performance and that there are many tools available to help with this process.
Spring Boot Profiling Tools:
Actuator: The article discusses how Spring Boot Actuator can be used to expose application metrics and health information, which can be useful for basic performance monitoring.
VisualVM: It describes how VisualVM can be used to profile memory usage, CPU usage, and thread activity.
JProfiler: The article introduces JProfiler as a tool for in-depth profiling, including monitoring of CPU and memory usage, as well as tracking method execution and database queries.
8. Execute Synchronous Requests Using WebClient
This article explores how to use the
WebClient
class from the Spring WebFlux project to perform synchronous HTTP requests in Java.
Key Points:
The article introduces
WebClient
as a non-blocking, reactive client for making HTTP requests, part of the Spring WebFlux module.Despite
WebClient
being designed for asynchronous operations, the article demonstrates how to use it to perform synchronous requests by blocking the thread until a response is received.Basic Usage:
Creating a
WebClient
Instance: Instructions are provided on how to instantiateWebClient
usingWebClient.create()
.Performing a Request: The article covers how to make a synchronous GET request using
retrieve().bodyToMono()
and block the result using.block()
.
Error Handling: It includes information on handling errors by using
onStatus()
to check for HTTP errors anddoOnError()
to handle exceptions.while synchronous requests are possible with
WebClient
, it's generally recommended to use its asynchronous capabilities to fully leverage its non-blocking nature.
9 . Using @ClientBasicAuth in Quarkus REST Client
This is an article about using @ClientBasicAuth in Quarkus REST Client. It discusses what @ClientBasicAuth is and how to use it.
It also discusses the steps to take to set up a protected service using Quarkus. Some important points are that @ClientBasicAuth can only be used with static users and that it does not support dynamic input.
10. Rapid Web Application Development With Spring Boot and Jmix
This article discusses using Jmix Studio and Jmix Framework to develop web applications with Spring Boot. It discusses creating a full-stack MVP for an expense-tracking application.
The framework provides rich UIs and other features that accelerate development.
To get started, you need to create a Jmix project in IDE.
The project includes basic entities and views. You can then create new entities and views using the Jmix Studio. You can also add security roles and permissions to control access to the application.