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. |
|
| ||||
Interview Questions and Answers - Order By Rating | ||||
| ||||
Ans. Since String is immutable, its hashcode is cached at the time of creation and it doesnt need to be calculated again. This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   immutable  immutability   hashmap   immutable  immutability   hashcode   hash code   advanced Asked in 2 Companies expert   frequent | ||||
Advanced level question frequently asked in US based companies. Recently asked in EMC and Intuit. | ||||
| ||||
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search. Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList. Further level up, we can have linked Hashmaps like , hashmap { a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value) b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value) .................................................................................... z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value) } upto n levels ( where n is the average size of the word in dictionary. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure Asked in 6 Companies   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. LinkedHashMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   linkedhashmap | ||||
| ||||
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 | ||||
| ||||
Ans. The purpose of comparator interface is to compare objects of the same class to identify the sorting order. Sorted Collection Classes ( TreeSet, TreeMap ) have been designed such to look for this method to identify the sorting order, that is why class need to implement Comparator interface to qualify its objects to be part of Sorted Collections. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   treeset   comparator Asked in 2 Companies Intermediate | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. TreeSet and TreeMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   treeset   basic interview question basic   frequent | ||||
| ||||
Ans. Using Collections.reverseOrder() Map | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map   treemap | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Keys | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map   treemap | ||||
| ||||
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   comparable interface   treemap   compareto | ||||
| ||||
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   comparable interface   treemap | ||||
| ||||
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   comparable interface | ||||
| ||||
Ans. No, results in exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap Asked in 6 Companies Basic   frequent | ||||
| ||||
Ans. Yes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   yes-no | ||||
| ||||
Ans. TreeMap implements NavigableMap, SortedMap, Serializable and Clonable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap | ||||
| ||||
Ans. ConcurrentHashMap is a hashMap that allows concurrent modifications from multiple threads as there can be multiple locks on the same hashmap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   concurrenthashmap   concurrenthashmap  concurrency   general electric   ge Asked in 32 Companies   rare | ||||
| ||||
Ans. hibernate.cfg.xml ( Main Configuration File ) and *.hbm.xml files ( Mapping Files ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   configuration   mapping files | ||||
| ||||
Ans. HashSet is maintained as HashMap by Java with values of the HashSet as Keys of the HashMap and value of the HashMap as the constant PRESENT. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ebay  java   collections   hashset   hashmap expert | ||||
Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews. | ||||
| ||||
Ans. Composition - has-a relationship between objects. Inheritance - is-a relationship between classes. Composition - Composing object holds a reference to composed objects and hence relationship is loosely bound. Inheritance - Derived object carries the base class definition in itself and hence its tightly bound. Composition - Used in Dependency Injection Inheritance - Used in Runtime Polymorphism Composition - Single class objects can be composed within multiple classes. Inheritance - Single class can only inherit 1 Class. Composition - Its the relationship between objects. Inheritance - Its the relationship between classes. | ||||
Sample Code for inheritance Sample Code for composition | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java concepts   inheritance  object oriented programming (oops)  oops concepts   composition  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  inheritance vs composition  object oriented programming (oops)  oops concepts Asked in 29 Companies basic   frequent | ||||
Try 5 Question(s) Test | ||||
| ||||
Ans. AbstractMap ConcurrentHashMap ConcurrentSkipListMap EnumMap HashMap IdentityHashMap LinkedHashMap SystemFlavorMap TreeMap WeakHashMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map | ||||
| ||||
Ans. The following code returns the list of Employee objects having employee name starting with A and Dept Name ( Department , Employee Mapped ). session.createCriteria(Employee.class,"emp") .createAlias("emp.department", "dept",Criteria.INNER_JOIN) .add( Restrictions.like("name", "A%") ) .add(Restrictions.eq("dept.name","Finance") .list(); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   hibernate table mapping | ||||
| ||||
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_82.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map | ||||
| ||||
Ans. WeakHashMap uses weak reference for keys, which means if the key object doesn't have any reference then both key/value mapping will become eligible for garbage collection. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   weakhashmap   difference between   garbage collection   ebay | ||||
| ||||
Ans. Red Black Tree | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   map expert | ||||
| ||||
Ans. TreeMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  treemap   collections   java   sorted collections   map | ||||
| ||||
Ans. LinkedHashMap | ||||
Sample Code for LinkedHashMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  linkedhashmap   collections   java   map | ||||
Ans. Order in which constants are declared. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  enum   collections   sorted collections   treemap   treeset   compareto   comparable   java | ||||
Ans. The new element will replace the existing element. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hashmap   map   collections   java | ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. SortedMap Interface | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map | ||||