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 Newest | ||||
| ||||
Ans. Daemon thread | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  garbage collection intermediate | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Yes its useless if we are not going to use its objects within Hash collection, For example - HashSet , HashMap. HashCode is used internally by these collections for Search. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hashcode  hash collections  search | ||||
| ||||
Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it. Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  memory leak  garbage collection intermediate   frequent | ||||
| ||||
Ans. https://qr.ae/TWK2Ok | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  circular queue  priority queue  queue  data structures  collections | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. Java manages memory using built-in garbage collector | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  destructor  garbage collection | ||||
| ||||
Ans. Garbage collection mechanism frees up the memory that is no longer needed. In languages like C / C++ the deallocation needs to be done explicitly by the programmer and hence any leniency may result in memory leak. Garbage collection in java ensures that all unused memory is reclaimed and hence there are no memory leaks.Moreover it relieves the programmer from the hassle of carefully releasing all memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Garbage Collection  memory management Asked in 2 Companies | ||||
| ||||
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  memory management  garbage collection | ||||
| ||||
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections. Enumeration is less safer than Iterator Enumeration is fail safe whereas Iterator is fail fast Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method. Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2 Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  enumeration vs iterator  collections Basic   frequent | ||||
| ||||
Ans. Synchronized List locks the whole list to provide synchronization and thread safety during the read or write operation, while, CopyOnWriteArrayList doesn’t lock the whole list during these operations. The CopyOnWriteArrayList class works according to its name i.e. copy-on-write which performs different actions for reading and write operations. For every write operation (add, set, remove, etc), it makes a new copy of the elements in the list. and for the read operations (get, iterator, listIterator, etc), it works on a different copy. So there is no additional overhead during a read operation and its read operation is faster than Collections.SynchronizedList(). Thus, COWAL is better for reading operation than Synchronized List. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Collections.synchronizedList()  CopyOnWriteArrayList | ||||
| ||||
Ans. We cannot explicitly initiate destruction of an object as no destroy method is available in java. Only Garbage collection can destroy an object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Garbage collection  object destruction Asked in 1 Companies | ||||
| ||||
Ans. When it is no longer referenced or it looses all references which were earlier pointing to it. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  garbage collection  object destruction Asked in 1 Companies | ||||
| ||||
Ans. Now the reference points to a new object in memory. If that was the only reference for the previous object , it will be marked for garbage collection. Foe example - Object obj = new Object(); obj = new Object(); object created in first line will be eligible for garbage collection after line 2 as it looses all it's handlers. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  references  objects  garbage collection Asked in 1 Companies | ||||
| ||||
Ans. Java Programs are collection of objects that communicates with each other to get a task accomplished. To add to those objects, there are common spaces ( static i.e common for objects belonging to a class ) that are used too. We can visualize objects as departments of an organization in real world. Just like Task gets initiated in one department and then files are moved across different departments to get work done. In a similar fashion, a task is initiated in one object ( having main method ) and then information ( through POJOs / DTOs ) is moved across objects to accomplish a task. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  objects  Java Programs are collection of objects  real life example of object communication | ||||
| ||||
Ans. Because it's access isn't synchronized and hence access / modification by multiple threads may lead to inconsistent state. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  fail fast  arraylist  collections | ||||
| ||||
Ans. ArrayLists aren't synchronized and hence doesn't allow synchronized access. As multiple threads can access an arraylist in parallel, it may result in an inconsistent state. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  vector  arraylist  list  collections Basic | ||||
| ||||
Ans. We can copy the elements to a Set and then find the difference of count between ArrayList and Set. As Set don't allow duplicates , they will be removed in the set. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  arraylist  set | ||||
| ||||
Ans. Yes , a gc method to explicitly call garbage collection immediately on the object. It will provide better flexibility over application that require optimal usage of memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  destructor  garbage collection Asked in 1 Companies expert | ||||
| ||||
Ans. Initialize an ArrayList that will hold LinkedLists i.e every element of the arraylist will be a linked list. Such collection could be used in algorithms that require first random access and then sequential traversal. For example - Storing traversal paths for a graph wherein we can start from any vertex. Implementing dictionary with each arraylist element holding staring with character and then linked list holding duplicate words. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  linkedlist  arraylist | ||||
| ||||
Ans. No, As collection classes involve use of Generics, they cannot accept primitive types. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collection classes  collections | ||||
| ||||
Ans. Objects that have lost their reference i.e. they cannot be accessed/used by the program anymore. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  garbage collection Asked in 1 Companies basic | ||||
| ||||
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  queue  collections  data structure | ||||
| ||||
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  queue  blockingqueue  collections | ||||
| ||||
Ans. string and wrapper class objects | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  immutability  immutable  immutability classes   immutable  immutability collections Asked in 3 Companies | ||||
| ||||
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  Arraylist  linkedlist  queue  collections | ||||
| ||||
Ans. The Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures. Although referred to as a framework, it works in a manner of a library. The JCF provides both interfaces that define various collections and classes that implement them. | ||||
Sample Code for Map Sample Code for HashMap Sample Code for Treemap Sample Code for set Sample Code for hashset Sample Code for treeset Sample Code for list Sample Code for arraylist Sample Code for linkedlist Sample Code for queue Sample Code for priorityqueue Sample Code for concurrenthashmap Sample Code for vector Sample Code for stack | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections Asked in 9 Companies basic   frequent | ||||
| ||||
This question was recently asked at 'adobe'.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  vector  collections  list Asked in 1 Companies | ||||
| ||||
Ans. No,we cannot.I t will give concurrentModificationExceptin error. It can be resolved by using ConcurrentClasses like ConcurrentHashMap,CopyOnWriteArrayList,BlockingQueue etc which are fail-safe and wont give exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  list  iterator Asked in 1 Companies basic | ||||
| ||||
Ans. Stack Properties Vector BlockingQueue ConcurrentMap ConcurrentNavigableMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  concurrent classes | ||||