7/1/2023 0 Comments Java interview questions![]() ![]() ![]() If you can further improve the algorithm, you will more impress your interviewer. When the Interviewer will ask you to improve, you can say that check until the square root of the number. One more minor difference is that HashMap allows a null key but Hashtable doesn't. HashMap is non-synchronized while Hashtable is synchronized and because of that HashMap is faster than Hashtable, as there is no cost of synchronization associated with it. Though both HashMap and Hashtable are based upon hash table data structure, there are subtle differences between them. synchronized method or block.Ħ) Difference between HashMap and Hashtable in Java? ( detailed answer) Both must be called from synchronized context e.g. On other hand, adding and removing an element from the middle is efficient in LinkedList as compared to ArrayList because it only requires modifying links, and no other element is rearranged.ĥ) What is the difference between wait and notify in Java? ( detailed answer)īoth wait and notify methods are used for inter-thread communication, where the wait is used to pause the thread on a condition, and notify is used to send a notification to waiting threads. ![]() ArrayList also provides a random search if you know the index, while LinkedList only allows a sequential search. In short, ArrayList is backed by an array in Java, while LinkedList is just a collection of nodes, similar to a linked list data structure. Just like Runnable, Callable also defines a single call() method but unlike run() it can return values and throw exceptions.Ĥ) Difference between ArrayList and LinkedList in Java? ( detailed answer) Runnable was the only way to implement a task in Java that can be executed in parallel before JDK 1.5 adds Callable. The difference comes from the fact that you can only extend one class in Java, which means if you extend the Thread class you lose your opportunity to extend another class, on the other hand, if you implement Runnable, you can still extend another class.ģ) Difference between Runnable and Callable interface in Java? ( detailed answer) In later two, StringBuffer is synchronized while StringBuilder is not, in fact, it's a ditto replacement of StringBuffer added in Java 1.5.Ģ) Difference between extending Thread vs implementing Runnable in Java? ( detailed answer) converting String to upper case or trimming white space will produce another instance rather than changing the same instance. String is immutable while both StringBuffer and StringBuilder are mutable, which means any change e.g. 1) Difference between String, StringBuffer, and StringBuilder in Java? ( detailed answer) ![]()
0 Comments
Leave a Reply. |