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. 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 | ||||
| ||||
Ans. A weak reference is a reference that gets removed on the next garbage collection cycle. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  weak reference  garbage collection Asked in 1 Companies   rare | ||||
| ||||
Ans. We are averaging elements of a collection by element1 grouped by element1 * list is the reference of collection * element1 is the member element returned by getElement1 method of ClassA * element2 is the member element returned by getElement2 method of ClassA | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 8  collections  java 8 streams  collectors | ||||
| ||||
Ans. Map<DataType1,DataType2> where DataType1 is the data type of element1 ( returned by getelement1 method ) and DataType2 is the data type of element2 ( returned by getElement2 method ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 8  collections  java 8 streams | ||||
| ||||
Ans. TreeSet contains only values as elements whereas TreeMap contains Key value pairs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  reeMap  TreeSet  Collections  sorted collection Asked in 1 Companies   rare | ||||
| ||||
Ans. Using comparable and comparator and sorted collections like TreeSet or TreeMap. or use stream api from java 8 onwards which internally refers to comparable and comparator through lambda expressions | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  sort  sorting  comprator  comparable  treeset  treemap  sorting collections Asked in 1 Companies Basic   frequent | ||||
| ||||
Ans. Heap as objects are stored ink heap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  memory management   stack  heap  garbage collection | ||||
| ||||
Ans. Synchronization, Concurrent classes, Volatile keyword, Implementing concurrent Lock interface, Immutable classes | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  multithreading  threads  ways to avoid thread related problems  synchronization  volatile  concurrent collections Intermediate | ||||
| ||||
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  concurrent collection classes   fail fast   fail-fast  collections  collection classes expert | ||||
| ||||
Ans. Yes wef from Java 9 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 9  java9  immutable  immutability collections | ||||
| ||||
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 | ||||