![]() ![]() The former is known as max-heap and the latter is min-heap. HeapSort is a sorting technique based on the binary heap data structure.Ī binary heap is a binary tree where items are stored such that the values in the parent node are either greater (max-heap) or smaller (min-heap) than the values in a child node. The code below creates two threads that are in a deadlock. Other threads have to wait for the current thread to complete. This means that only one thread can lock and use the synchronized method. Multi Threaded programs suffer from deadlocks because the synchronized keyword is used to make the methods thread-safe. However, since both threads wait for the other to execute they block each other causing a deadlock. These scenarios occur when both threads have obtained one lock and are waiting to obtain the other lock. ![]() Note: Commonly asked Java interview questionĪ deadlock scenario is caused when two threads require the same locks to execute. Set> entrySet = studentPerformanceMap.entrySet() ĪrrayList> listOfEntry = new ArrayList>(entrySet) ("-") Ĭollection values = studentPerformanceMap.values() ĪrrayList listOfValues = new ArrayList(values) Set keySet = studentPerformanceMap.keySet() ĪrrayList listOfKeys = new ArrayList(keySet) The security codes need to be refreshed say every 30 minutes. Q01.Scenario: You need to load stock exchange security codes from a database and cache them for performance. StudentPerformanceMap.put("Anjali N", "Bad") Full list of Java scenarios based interview questions are covered at Judging your Java experience via scenarios based interview Q&As. StudentPerformanceMap.put("Smith Jacob", "Very Good") StudentPerformanceMap.put("Ivan Jose", "Very Bad") StudentPerformanceMap.put("Prachi D", "Very Good") StudentPerformanceMap.put("Rakesh Sharma", "Good") StudentPerformanceMap.put("John Kevin", "Average") HashMap studentPerformanceMap = new HashMap() The code below is used to convert a HashMap into an ArrayList. Scanner commandReader = new Scanner(System.in) Iterate and compare each value with the keyĬode snippet implementation binary search: import.Next, based on the result check for the key in the upper or lower half respectively.If false, check if the key is larger or smaller than the middle value.If the key is equal to the middle value, return true.Find the middle value of the array, and compare it with the key.This search method is significantly faster than linear search methods.īinary search splits the array into smaller sets and then applies rules to check for the input key. The binary search algorithm is used to search for a value in a sorted array or collection type. Private static Map x.getValue().compareTo(y.getValue())) The code below is the implementation of the same. HashMaps are not ordered collections, and sorting them would not make sense but since sorting hashmaps can be quite tricky they are a common Java interview question. They allow users to store key-value pairs, however, the keys must be unique. HashMaps are used to implement map interfaces. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |