Java Interview Question And Answer. Java interview question and answer java collection framework. . .
Questions:
What is collection and collection framework?
In Java there are some inbuilt classes which deal (stores) with multiple
objects. This classes are called collection classes. Example of such
clases are ArrayList, HashSet, HashMap.
A collections framework is a unified architecture for representing and
manipulating collection classes.
Collection Class Hierarchy:
Key Collection Classes & Interfaces. Which commonly asked in interview
In the above diagram, we haven't added the java.util.concurrent package
to keep the things simple. java.util.concurrent has been added from
java8 version. We will discuss about it later.
Key Classes and Interfaces Of Collection Framework:
Interfaces:
- List - List is an ordered collection. Main implemented classes
are ArrayList, LinkedList and Vector . Practical Use of List Classes:
- List we used to store the couple of java objects of same
class.
Example: Suppose there is a STUDENT table in
database. We write SQL query to fectch the student records in for of
Student java object. In this case we store the Studen java objects
in ArrayList.
- Linked List: -
- Set - It maintain the uniqueness in the collection. Does not
allow duplicate.
- Map - It allows to store Key-Value pairs.
- Comparable - Allow to compare two objects.
- Comparator - Compare two objects.
Classes:
List Classes
set Classes
Map Classes
It's just instance of a class. Object belongings to same class will have
similar properties and will support same operations. Example: Here col1
and col2 are two objects of Column class. Both will have same properties
e.g. size, name, dataType
public class Table {
Column col1 = new Column();
Column col2 = new Column();
}
Please provide your feedback here