Find All Paths from Root to Leaf Nodes in Binary Tree using Java

In this example I am going to show you how to find all paths from root to leaf nodes in binary tree. So I am going to find each path from root to leaf node using Java program. A binary tree is a non-linear data structure type tree with at most two children for each parent. Every node in a…

Java To Find Common, Uncommon, Unique Elements In ArrayLists

Elements in ArrayList Here I am going to show you how to find common, uncommon, unique elements in two Lists or ArrayLists using Java program. In this program I will show you how to find common, uncommon, unique string elements as well as object elements in two ArrayLists. For identifying the unique string elements is very straight forward but for…

How To Create Custom Immutable Class In Java

Immutable Class in Java In this tutorial I am going to show you how to create custom immutable class in Java programming language. Immutable objects are those objects whose states cannot be changed. For example, you can change the state of an object by changing its attribute’s or field’s value. String is an example of an immutable class in Java….

Difference Between Parallel Stream And CompletableFuture In Java

Parallel Stream Vs CompletableFuture I am going to discuss here CompletableFuture vs Parallel Stream in Java programming language. CompletableFuture extends Future with added advantage to allow the tasks finish in an ad hoc manner, whereas, in Parallel Stream task is divided into sub-tasks and run on separate threads to be completed faster. Both CompletableFuture and Parallel Stream were added in…

Check a Given Date is Past, Today or Future’s Date in Java

Past, Present Or Future’s Date In this example I am going to show you how to check if an input date is past date or today’s date or future date. For this example you should use at least Java version 8. Java 8 or higher version provides thread safe version of date time API classes that can be used safely…

How to mask a Field or an Attribute in Java

Here I am going to show you how to mask a field or an attribute in Java programming language. This kind of situation occurs when you are dealing with mainly debit or credit cards. So you have a POJO or model class for your card (debit or credit) but for security reason you do not want to display the card…

Junit 5 Mockito Verify Example

In this example I am going to show you how to verify a method has been executed at least. Why do you need to verify method execution? Consider the void method, in your Java class, which you want to perform Junit test case on it and you don’t have any way to tell whether your method successfully tested or not….

Junit 5 Expected Exception using Assertions.assertThrows()

This example will show you how to work with expected exception using Junit 5 Assertions.assetThrows(). Junit 4 (at least 4.7 version) provides expected attribute with @Test annotation, where you can mention what exception you are expecting from your test method but Junit 5 does not provide such thing. Junit 5 provides assertThrows() that can be used to check the expected…

Mock an Autowired Value Field in Spring with Junit 5

Mock @Value In this example I am going to show you how to mock an autowired field in Spring boot framework with Junit 5. When you use @Value annotation in Spring beans to read the value from properties file and later when you want to perform Junit test then you also need to pass value for this autowired field value…

Parallelism Example in Java Stream API

I am going to show you how to work with parallel stream in Java 8 or higher version of Java. In parallel computing a task is divided into sub-tasks and these sub-tasks are computed parallelly in each separate threads and finally the result of the solution for each sub-tasks is combined. One of the features for computing parallelism is to…