Mastering ExecutorService for Concurrency
In the ever-evolving world of software development, the ability to manage concurrent tasks efficiently is paramount. Traditional threading approaches can become cumbersome and error-prone, especially...
View ArticleLombok Constructor Annotations Example
1. Introduction Lombok is an open-source Java library that generates getter, setter, toString, equals, hashCode, and constructors automatically to reduce common boilerplate code. There are three...
View ArticleFilter a Map by Keys and Values using Java Stream
Discover how to filter a Map by keys, values, or both using Java 8’s Stream API with the filter() and collect() methods. These straightforward code snippets demonstrate how to create generic functions...
View ArticleFilter Nested Collections with Stream in Java
The Java Stream API offers powerful filtering capabilities for elements within a Stream. However, when these stream elements include nested collections, we may need to filter the elements within those...
View ArticleUsing Social Login Authentication in Spring Boot with OAuth2
Social login is a mechanism that allows users to sign into an application using their existing credentials from social networking services like Facebook, GitHub and Google. This method is increasingly...
View ArticleHow to Test a Spring AOP Aspect
1. Introduction Aspect-Oriented Programming (AOP) is one of programming paradigms that separates cross-cutting concerns as aspects. It complements Object-Oriented Programming (OOP) by enabling the...
View ArticleEclipse IDE for Modern Languages
The Eclipse IDE is a powerhouse for developers, but did you know it’s not just for Java anymore? While it remains a favorite for Java programmers, Eclipse has evolved into a versatile platform that can...
View ArticleGet First and Last Day of Week, Month or Year in Java
The introduction of the Date and Time API in Java 8 brought a significant improvement to how dates and times are handled in Java. One of the key components of this new API is the TemporalAdjusters...
View ArticleHow to pretty print JSON using Moshi
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. In Java, the Moshi library is a...
View ArticleEffective Debugging Techniques for Java Streams
Java Streams have revolutionized how we process collections in Java. Their concise and declarative syntax makes code cleaner and more readable. However, this very conciseness can sometimes make...
View ArticleHow to write JSON to a file using Moshi
Moshi is a modern JSON library for Android and Java, providing a simple API for parsing and serializing JSON. Let us delve into understanding how to write to a JSON file and read from a JSON file using...
View ArticleJava Stream mapMulti() Example
With the release of Java 16, several new features and enhancements were introduced. One such feature is the mapMulti() method in the Stream API. Let us delve into understanding how to use the Java...
View ArticleMapping Enums and Strings with MapStruct
MapStruct is a Java annotation processor that streamlines the implementation of mappings between Java beans, including complex scenarios such as converting Enums to Strings and vice versa. This article...
View ArticleOptimizing Java Applications with Thread Dump Analysis
Java applications, like any complex software, can suffer from performance degradation. This can manifest as slow response times, application freezes, or even crashes. Identifying the root cause of...
View ArticleMoshi java.time.LocalDate requires explicit JsonAdapter
Let us delve into understanding why Moshi java.time.LocalDate requires an explicit JsonAdapter to be registered. 1. Introduction Moshi is a modern JSON library for Android and Java that makes it easy...
View ArticleChoosing the Right Java ORM for Your Project
Java applications often interact with relational databases to store and retrieve data. This can involve writing tedious and error-prone SQL queries, hindering development speed and maintainability....
View ArticleImplement Elvis Operator in Java 8
In Java 8, the Elvis operator (often written as ?: in Groovy and Kotlin) is not available as a built-in feature. However, we can achieve similar functionality using various techniques. Below are...
View ArticlePreventing IndexOutOfBoundsException with List.subList() in Java
The List.subList() method in Java allows you to create a view of a portion of a list, defined by a starting and ending index. However, improper use of this method can lead to IndexOutOfBoundsException....
View ArticleCasting Maps into Complex Objects in Java
In Java, there is often a need to convert a Map to a complex object (POJO – Plain Old Java Object). This can arise in various scenarios, such as when working with JSON data or other forms of structured...
View ArticleSpring MockMVC Get JSON As Object
1. Introduction Spring MockMVC is the Spring MVC testing framework which performs Spring MVC request handling and response asserting via mocking request and response objects without a running HTTP...
View Article