Java BiFunction Tutorial

Overview In Java, A BiFunction represents a function that accepts two arguments and returns a result. The interface has one abstract method apply and one default method andThen. The apply method is defined as follows: That means it accepts two arguments (t of type T and u of type U) and returns an object of … Read more

Java BiConsumer Functional Interface Tutorial

Overview The BiConsumer is a part of the java.util.function package. As the name suggest, this interface is a Consumer. That means it takes input arguments and returns void. Practical use cases This interface can be useful in various cases, for example, it can be used to create side effects like modifying state, printing, or logging. … Read more

Java Fork/Join Framework File Downloading Examples

Overview of the Fork/Join Framework in Java The Fork/Join framework in Java is an example of the divide and conquer strategy. It is best used for scenarios where you have multiple tasks that can be executed individually. There are two important classes: RecursiveTask<T> and RecursiveAction. While RecursiveTask returns a value, RecursiveAction doesn’t (Similar to Callable … Read more

4 Key differences between a HashMap and a Hashtable in Java

4 Key differences between a HashMap and a Hashtable in Java

Overview Hashtable and HashMap are common data structures to store key-value data in your Java application. While having similarities, there are some crucial differences you need to know as a Java developer. Let’s discuss the differences between these two data structures in this post. Hashtable is thread-safe, HashMap is not Consider the following code using … Read more

Java Exception Handling Cheat Sheet

Java Exception Handling Cheat Sheet

Overview While preparing for the OCP 17 exam, I created some notes to aid my learning. This is the first of many posts in this series. I hope you find it helpful. Java Exception Handling Cheat Sheet The Throwable family Checked vs. unchecked exceptions Overriding methods with declared exceptions Example RuntimeException Checked exceptions Error Exception … Read more

Understand Hibernate @ManyToOne, @OneToMany With Examples

Understand Hibernate @ManyToOne, @OneToMany

Overview @ManyToOne and @OneToMany are standard mappings in Hibernate. Understanding how to use them correctly is the key to mapping entities efficiently in Hibernate. In this post, I will show you how to use these annotations and give examples to demonstrate use cases. The analogy I use is schools and students. In real life, schools … Read more