Tag: J2SE interview quetion
[vc_row][vc_column][vc_column_text] 1. Magic Number The first four bytes of the class file is the magic number. This is a predefined value used by JVM to identify a .class file is generated by the valid compiler or not. The value should be “OXCAFEBABE”. Note:- Whenever we are executing a java class . . . Read more
What is Arrays class in Java? Arrays in Java Arrays class is a utility class to define several utility methods for array object. We can sort primitive array only based on default natural sorting order whereas we can sort object array either based on default natural sorting order or based . . . Read more
What is a Collection class in Java? Collections class defines several utility methods for collection objects like sorting, searching, reversing, etc. Sorting elements of List Collections class defines the following two methods for sorting. 1 Public static void sort(List l) To sort based on default natural sorting order In this . . . Read more
What is Hashtable in Java with Example? What is Hashtable in Java with Example? The underlying data-structure for Hashtable is Hashtable. Insertion order is not preserved and it is based on Hashcode of keys. Duplicate keys are not allowed and values can be duplicated. Heterogeneous objects are allowed for both keys . . . Read more
What is TreeMap in Java with example? The underlying data-structure is Red-black-Tree. Insertion order is not preserved and it is based on some sorting order of keys. Duplicate key is not allowed but values can be duplicated. If we are depending on default natural sorting order then keys should be . . . Read more
What is WeakHashMap in Java? It is exactly same as HashMap except for the following difference:- In the case of HashMap even though object doesn’t have any reference it is not eligible for GC. If it is associated with HashMap that is HashMap dominates Garbage collector. But in the . . . Read more
What is IdentityHashMap? In journal == operator meant for reference comparison (address comparison) and equals() method meant for content comparison. It is exactly same as HashMap(including methods and constructors) except the following difference. In the case of normal HashMap, JVM will use .equals() method to identify duplicates keys, which is meant for content . . . Read more
Difference between HashMap and LinkedHashMap? It is the child class of HashMap. The LinkedHashMap class is very similar to HashMap in most aspects. However, the linked hash map is based on both hash table and the linked list to enhance the functionality of hash map. It maintains a doubly-linked list running through all its . . . Read more
Difference between HashMap & Hashtable in Java? The underlying data-structure is HashTable. Insertion order is not preserved and it is based on HashCode is keys. Duplicate keys are not allowed but values can be duplicated. Heterogeneous objects are allowed for both Key and value. Null is allowed for Key(only once). . . . Read more
Java Set is a collection of elements (Or objects) that contains no duplicate elements. Java Set is an interface that extends Collection interface. Unlike List, Java Set is NOT an ordered collection, it’s elements does NOT have a particular order. Java Set does NOT provide a control over the position where you . . . Read more