More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.
Help us improve. Please let us know the company, where you were asked this question :
Ans. HashTable has been deprecated. As an alternative, ConcurrentHashMap has been provided. It uses multiple buckets to store data and hence much better performance than HashTable. Moreover, there is already a raw type HashMap. The only difference between the HashTable and HashMap is that Hashtable is synchronized whereas HashMap is not. Most of the synchronized collections have been deprecated and their raw alternative have been presented as preferred.Synchronization has a cost. Using synchronized collection in places where there is no need of it leads to useless utilization of resources. As these collections are rarely used in a static context or shared among threads, Java might have thought it better to just provide the raw collection and let developers implement synchronization if he feels the need to do so. HashMap is now presented as the default and the preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable. Because of this, Java thought it right to deprecate the use of HashTable.'
Synchronization has a cost. Using synchronized collection at a place where there is hardly any need of it would means useless utilization of resources. As these collections are rarely used in static context or shared among threads, Java might have thought it better to just provide the raw collection and let developer implement synchronization if he feels the need to do so.
As HashMap has been presented as default and preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable, Java thought it right to deprecate the use of HashTable.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap expert
a. HashMap came before HashTable. b. HashMap allows null values whereas Hashtable doesn’t allow null values. c. HashTable and HashMap allow Key-Value pairs. d. Hashtable is synchronized whereas HashMap is not.
Ans. HashMap came before HashTable.
Help us improve. Please let us know the company, where you were asked this question :
Ans. HashTable locks the complete collection to provide synchronization whereas ConcurrentHashMap only locks segments to achieve synchronization and hence better efficient and faster.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, they both aim at providing synchronized access to the Map collection. The only difference is in their implementation. ConcurrentHashMap came after HashTable and hence technically more efficient as it doesn't lock the complete map while accessing it.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Both provide the thread safety but the actual difference come when talk about performance. CHM gives best performance when no of writer threads are less in number.
Help us improve. Please let us know the company, where you were asked this question :