Understanding == and equals() in Java

Overview In Java, the == operator and the equals() method are both used to compare objects, but they serve different purposes and operate in fundamentally different ways. Stack, Heap, and References Before delving into the differences between == and equals, first, you need to understand what are references and how they are stored and used in Java. References and … Read more

DoubleConsumer vs Consumer

Overview One of the biggest questions I have when studying the functional interfaces in java.util.function is why the creators made DoubleConsumer (LongConsumer, IntConsumer) while there is already a Consumer interface that can handle any kind of object. It turned out, they have solid reason to do so. Boxing, unboxing, autoboxing primer As you may already … Read more

Java Consumer Functional Interface Tutorial

Overview In Java functional programming, Consumers are incredibly versatile and valuable, particularly when it comes to performing actions on data without returning values. Why use Consumers? Here are the main reasons using Consumers is beneficial to your code: Simplifying Side Effects You may hear or read somewhere that in functional programming, side effects should be … Read more

Java Predicate & BiPredicate Tutorial

Overview The predicate interfaces in the java.util.function package return a boolean given one or some arguments. The primary purpose of the Predicate interface is to simplify the task of evaluating conditions or tests within your Java applications. It abstracts the process of writing conditional statements and allows you to represent complex conditions as reusable, composable … 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