java core

Your blog category

Implementing custom collection classes.

Creating custom collection classes in Java involves defining classes that implement the core collection interfaces (List, Set, Map, etc.) or extending existing collection classes to add custom behavior or constraints. Let’s create custom implementations for a List and a Set that store student names, focusing on simplicity and basic functionality. Here’s a simple custom implementation […]

Implementing custom collection classes. Read More »

Choosing the right data structure based on requirements

1. Understand Your Requirements Criteria Description Data Operations Identify primary operations: insert, delete, search, traversal, etc. Concurrency Will multiple threads access/modify the structure concurrently? Order Is ordering important (sorted, FIFO, LIFO)? Memory Efficiency Is minimal memory usage critical, especially for large datasets? Performance How frequent and large are the operations? Optimize for speed if needed.

Choosing the right data structure based on requirements Read More »

CopyOnWriteArrayList

CopyOnWriteArrayList in Java is a thread-safe variant of ArrayList that allows concurrent access for reading while maintaining thread safety for modifications. It achieves this by creating a fresh copy of the underlying array whenever an element is added, modified, or removed, hence the name “copy-on-write.” This makes it suitable for scenarios where reads are more

CopyOnWriteArrayList Read More »

ConcurrentLinkedQueue

ConcurrentLinkedQueue in Java is a concurrent, unbounded queue implementation that provides thread-safe operations for high-performance, scalable handling of elements in a FIFO (First-In-First-Out) manner. It is part of the java.util.concurrent package and is designed for scenarios where multiple threads need to access a queue concurrently without explicit synchronization. The syntax for creating a ConcurrentLinkedQueue is

ConcurrentLinkedQueue Read More »

ConcurrentHashMap

java.util.concurrent.ConcurrentHashMap is a part of the Java Concurrency package and is designed for highly concurrent applications. It is an advanced version of HashMap that allows safe access and modification by multiple threads without the need for external synchronization. Let’s consider a ConcurrentHashMap<String, Integer> that stores the marks of 5 students: Paani, Mahesh, Datta, Ganesh, and

ConcurrentHashMap Read More »

Scroll to Top