How can we make Hashmap Synchronized

HashMap can be synchronized by Map m = Collections.synchronizedMap(hashMap); In Core Java, you can make a HashMap synchronized by using the Collections.synchronizedMap() method. This method returns a synchronized (thread-safe) map backed by the specified map. Here’s an example: java import java.util.Collections; import java.util.HashMap; import java.util.Map;public class SynchronizedHashMapExample { public static void main(String[] args) { // Creating … Read more

Why doesn’t Collection extend Cloneable and Serializable

From Sun FAQ Page: Many Collection implementations (including all of the ones provided by the JDK) will have a public clone method, but it would be mistake to require it of all Collections. For example, what does it mean to clone a Collection that’s backed by a terabyte SQL database? Should the method call cause … Read more

What is fail-fast Property

At high level – Fail-fast is a property of a system or software with respect to its response to failures. A fail-fast system is designed to immediately report any failure or condition that is likely to lead to failure. Fail-fast systems are usually designed to stop normal operation rather than attempt to continue a possibly-flawed … Read more

What does Synchronized means in Hashtable Context

Synchronized means only one thread can modify a hash table at one point of time. Any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released In the context of Hashtable in Java, the synchronized keyword is used to … Read more

Difference Between HashMap and HashTable? Compare Hashtable vs HashMap

Both Hashtable & HashMap provide key-value access to data. The Hashtable is one of the original collection classes in Java (also called as legacy classes). HashMap is part of the new Collections Framework, added with Java 2, v1.2. There are several differences between HashMap and Hashtable in Java as listed below The HashMap class is … Read more