Tag: J2SE interview quetion
Difference between Comparator and Comparable in Java? Comparator[I] It is present in java.lang package and it contains only one method. [highlight]compareTo()[/highlight];  If we are depending on default natural sorting order then while adding the object into the TreeSet JVM will call compareTo() method. If default natural sorting order not available or . . . Read more
TreeSet in Java and null acceptance in TreeSet? The underlying data structure is the balanced tree. Duplicate objects are not allowed. Insertion order not preserved. Heterogeneous objects are not allowed otherwise we will get runtime exception saying ClassCastException. Null insertion possible (only once). TreeSet Implement Serializable and Cloneable but not . . . Read more
Difference between HashSet and LinkedHashSet? It is the child class of HashSet. A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. Contains unique elements only like HashSet. Provides all optional set operations, and permits null elements. Maintains insertion order. LinkedHashSet doesn’t have its . . . Read more
HashSet in Java and what is FillRatio or LoadFactor? The underlying data-structure is Hashtable. Duplicate objects are not allowed. Insertion order is not preserved and it is based on HashCode of objects. Null insertion is possible (only once). Heterogeneous objects are allowed. Implements serializable and cloneable but not the RandomAccess interface. . . . Read more
Cursors in Java and difference between them? If you want to get object one by one from the collection then we should go for the cursor. There are three types of cursors available in Java. Enumeration Iterator ListIterator Enumeration We can use the enumeration to get objects one by one . . . Read more
Explain ArrayList and difference between ArrayList and Vector? ArrayList is a class, that uses a dynamic array for storing the elements. It extends AbstractList class and implements List interface. The underlying data structure is a Resizable array or growable array. Duplicates are allowed. Insertion order is preserved. Heterogeneous objects are . . . Read more
What is an Array and difference between array and collection? An array is an index collection of fixed no of homogeneous data elements. The main advantage of arrays is we can represent multiple values by using a single variable so that readability of the code will be improved. Java array is . . . Read more
What is serialVersionUID? In Serialization, both sender and receiver need not be the same person, need not use the same machine and need not be from the same location. That person may be different, machines may be different and location may be different. In Serialization, both sender and receiver have . . . Read more
What is Serialization and Deserialization in Java? Serialization The process of writing state of an object to a file is called Serialization but strictly speaking, it is a process of converting an object from JAVA supported form into either file supported form or network supported form. Serialization in Java allows . . . Read more
[vc_row][vc_column][vc_column_text] What is the importance of SCP(String constant pool)? There are two ways to create a String object in Java: Using the new operator. For example, String str = new String(“Java4us”);. Using a string literal or constant expression). For example, String str=”Java4us”; (string literal) or String str=”Java” + “4us”; (string constant expression). In our program, if a . . . Read more