devxlogo

Java

Image

Finding the Mime Type of a File

Finding the MIME type of a file is useful when you want to perform certain actions. PS: I have placed a file named nature.jpg in the folder /home/sridhar before executing

Image

How to Annotate Class with Lombok

The first approach consists of annotating the class as below: @ToString@EqualsAndHashCode@Getter@Setter@RequiredArgsConstructorpublic class Foo { …} A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields, and

Image

Understanding the Unary Operator in Java

Java uses the symbol tilde (~) to represent the operator. The following examples are clearly illustrative of the use and outcome of this operator. Code sample: public class JavaUnary{public static

Image

Validate Field Length

See how to validate the length of a field in Java via javax.validation.constraints.Size. We can do it as follows: @NotNull@Size(min=3, message=”Name must be at least 3 characters long”)private String name;

Image

Using the FileTime Class in Java

FileTime is a class in Java that helps you retrieve time-related information regarding files. One such method that we will see below is to get the modified time of a

Image

Working with Long Integer Literals

Literals of type long are expressed by adding an L suffix. For example: 0L // The decimal number zero (type ‘long’)1L // The decimal number one (type ‘long’)2147483648L // The value

Image

Set Hibernate Batching Size

Setting the Hibernate batching size can be accomplished via hibernate.jdbc.batch_size. In Spring, we need to add in application properties per the following setting (the recommended batch size is between 5

Image

Creating an Immutable List via JDK 9

Starting with JDK 9, we can create an immutable list via the suite of List#of(…) methods. For example, an immutable list of 3 elements can be created as follows: import java.util.List;…List