Junit @TempDir annotation

In this post under Junit, I will show with example the purpose and how to use @TempDir annotation. Lets say you have written class that zip the input file as shown below FileZip package package20; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class FileZip { public void zip(File inputFile) throws Exception…… Continue reading Junit @TempDir annotation

Calling custom mapping method from another mapper interface code

In this post under MapStruct, I will show with example how to call custom mapping method from another mapper interface code. In previous post, I showed you how to add custom mapping method to a mapper interface. But what if the same custom mapping method is also required by another mapper interface, we cannot copy…… Continue reading Calling custom mapping method from another mapper interface code

Text Block With Indentation

In this post under Java Core, I will show you with example how indentation is calculated in Text Block. Below is the main class with three variety of text block. Example3 package core.string; public class Example3 { public static void main(String[] args) { String textBlock1 = """ <html> <head> <title>TextBlock1<title> </head> <body>Body of TextBlock1</body> </html>…… Continue reading Text Block With Indentation

Using Comparable with multiple fields

In this post under Java Collections, I will show an example of how to use Comparable interface when we need to sort collections on multiple fields For our example, we will sort a collections of employee objects. I need to sort the collections of employee objects in ascending order first using there name and then…… Continue reading Using Comparable with multiple fields

Pattern matching with instanceof

Hi all, in this post under Java pattern matching section, I will introduce you to pattern matching and how to use it with instanceof operator. Please don’t confuse java pattern matching with regex pattern matching Regex pattern matching checks whether a given text matches a text pattern and may optionally extract parts of the text.…… Continue reading Pattern matching with instanceof