Spring

Spring Dependency Injection

Introduction: In a well-designed Java application, the classes should be as independent as possible. Such a design promotes reusability of components. It also makes it easier to unit test the various components. The concept of dependency injection promotes loose coupling among Java objects. In this tutorial, we’ll talk about the dependency injection in Spring framework. […]

Be the First to comment. Read More
Core Java

Java ArrayDeque

Introduction: ArrayDeque in Java is a class that implements a Deque interface. It’s an array-based implementation of a double-ended queue. As the name suggests, a double-ended queue is a queue that allows us to add or remove items from both front and rear ends. Before we dive in, let’s quickly look at a few noteworthy […]

Be the First to comment. Read More
Core Java

PriorityBlockingQueue In Java

Introduction: A PriorityBlockingQueue in Java implements the BlockingQueue interface and supports the features of a PriorityQueue. So, what’s a BlockingQueue? Following holds true for any implementation of a BlockingQueue: While attempting to retrieve an element, a thread waits if the queue is empty In case of a bounded BlockingQueue implementation, the thread waits till it […]

Be the First to comment. Read More
Core Java

LinkedHashMap In Java

Introduction: LinkedHashMap is a Map implementation which maintains the insertion order of its elements. It extends the HashMap class:

Just like a HashMap, it allows storing one null key and many null values. Instantiating LinkedHashMap: We can use one of the following constructors to create a LinkedHashMap:

The very last constructor also accepts a […]

Be the First to comment. Read More
Spring

Spring @Value Annotation

Introduction: Spring @Value annotation is used to inject values into variables and method arguments. We can either read spring environment variables or system variables. It also supports SpEL. In this quick tutorial, we’ll explore how to work with Spring @Value annotation. Setup: Let’s start by first defining a few properties in our app.properties file:

[…]

Be the First to comment. Read More
Core Java

Java equals() and hashCode()

Introduction: Java Object class provides basic implementation of methods – hashCode() and equals(). These methods are extremely useful especially when working with the Collection framework. The hash table implementations rely on these methods for storing and retrieving data. In this tutorial, we’ll learn about the contract between hashCode() and equals(), their default implementations. We’ll also […]

One comment Read More
Core Java

WeakHashMap In Java

Introduction: A WeakHashMap in Java is a pretty popular data-structure among mid to senior-level Java developers. The WeakHashMap class is present in the java.util package. It’s a Map implementation which stores weak references to its keys. An entry in a WeakHashMap gets automatically removed when the associated key loses all of its active strong and soft […]

Be the First to comment. Read More
Core Java

HashSet In Java

Introduction: HashSet in Java implements Set interface i.e. it doesn’t allow duplicates. It is internally backed by a HashMap which works on the principle of hashing.  We can store a null value in a HashSet. Its default capacity is 16 with a load factor of 0.75, where:

A Java HashSet is non-synchronized. Also, there’s no guarantee […]

Be the First to comment. Read More
Core Java

Sorting a HashMap In Java

Introduction: In this tutorial, we’ll learn how to sort a Java HashMap. We can sort a HashMap either by keys or by values. We’ll discuss both of these strategies. Sorting a Java HashMap: To follow along with the rest of the article, let’s first construct a HashMap:

where Student is a POJO with id and […]

Be the First to comment. Read More
Core Java

Java Convert a List to Array And Vice-Versa

Introduction: In this article, we’ll quickly learn how to convert a Java List (say an ArrayList) to an array and vice-versa. If you wish to learn more about an ArrayList in general, feel free to read our article on Java ArrayLists. Meanwhile, let’s get going! Convert Java List to Array: Converting a Java List to an array is […]

Be the First to comment. Read More