Core Java - Interview Questions and Answers for 'AshTabl' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 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.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'AshTabl' - 16 question(s) found - Order By Newest

Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback)
  Q1. What is the use of hashcode in Java ?Core Java
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 :   

   Like         Discuss         Correct / Improve     java   collections   hashcode   advanced  hashtable     Asked in 33 Companies      intermediate        frequent

Try 1 Question(s) Test


Very frequently asked across all types of companies.
  Q2. Difference between HashMap and Hashtable?Core Java
Ans. Hashtable is synchronized whereas HashMap is not.HashMap allows null values whereas Hashtable doesnt allow null values.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashmap   map   hashtable   hashmap vs hashtable     Asked in 14 Companies      basic        frequent

Try 2 Question(s) Test


 Q3. Why HashTable has been deprecated ?Core Java
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 :   

   Like         Discuss         Correct / Improve     hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap      expert

Try 3 Question(s) Test


 Q4. Can we use null as a key for a map collection ?Core Java
Ans. Yes , for HashMap. HashMap implements Map interface. HashMap allows one null key and any number of null values.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashmap   map   hashtable   yes-no     Asked in 1 Companies


 Q5. What is a Property class ?Core Java
Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream.

  Sample Code for Load Properties using Property Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashtable   map   synchronization   synchronized


 Q6. Can we add duplicate keys in a HashMap ? What will happen if we attempt to add duplicate values ?
Ans. No, We cannot have duplicate keys in HashMap. If we attempt to do so , the previous value for the key is overwritten.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashmap   map   hashtable

Try 1 Question(s) Test


 Q7. Which interface does java.util.Hashtable implement?Core Java
Ans. Java.util.Map

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashtable   map      basic        rare


  Q8. What is the use of HashCode in objects ?Core Java
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string   hashcode   hash code   string comparison  hashtable     Asked in 17 Companies      basic        frequent


 Q9. Which interface does java.util.Hashtable implement ?

a. List
b. Set
c. Collection
d. Map
Core Java
Ans. Map

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hashtable   java   collections


 Q10. Which of the following is false ?

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 :   

   Like         Discuss         Correct / Improve     map   hashmap   hashtable   collection   java

Try 2 Question(s) Test


 Q11. Which of the collections allows null as the key ?

a. HashTable
b. HashMap
c. TreeMap
d. LinkedHashMap
Core Java
Ans. HashMap

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   map  hashtable     Asked in 2 Companies      basic        frequent


 Q12. Difference between concurrentHashMap and HashTable ?Core Java
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 :   

   Like         Discuss         Correct / Improve     concurrentHashMap  HashTable  Map  Collections     Asked in 2 Companies


 Q13. isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ?Core Java
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 :   

   Like         Discuss         Correct / Improve     HashTable  ConcurrentHashMap  map  Collections


 Q14. How to implement a hashtable ?Data Structure
 This question was recently asked at 'MarkMonitor'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hashtable     Asked in 1 Companies


 Q15. How ConcurrentHashMap provides better performance compared to HashTable ?Core Java
Ans. ConcurrentHashMap uses multiple buckets to store Data and hence avoid read locks which facilitates better performance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ashTabl      expert        rare


 Q16. Isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ?Core Java
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 :   

   Like         Discuss         Correct / Improve     synchronized collections  hashtable  ConcurrentHashMap     Asked in 1 Companies



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: