Banner_Ads

Interview Question-Answers | Tutorial For Beginners


tech4allsa2z:This blog provides you tutorial and most common Interview questions for beginners related to the following technology like java, python.

Java Collection Framework Interview questions for Freshers

 




Q-1: What is framework in Java?   

A framework is a popular and readymade architecture that contains a set of classes and interfaces.

Q-2:  What is the Collection framework in Java?

Collection Framework is a grouping of classes and interfaces that is used to store and manage the objects. It provides various classes like Vector, ArrayList, HashSet, Stack, etc. Java Collection framework can also be used for interfaces like Queue, Set, List, etc.

Q-3:  What are the benefits of the Collection Framework in Java?

The benefits of Collection Framework in Java are:

  • Java collection framework offers highly efficient and effective data structures that enhance the accuracy and speed of the program.
  • The program developed with the Java collection framework is easy to maintain.
  • A developer can mix classes with other types that result in increasing the reusability of code.
  • The Java collection framework enables programmers to modify the primitive collection types the way they like.


Q-4:  Explain Collections Class

java.util.Collections is a class consists of static methods that operate on collections. It contains polymorphic algorithms to operate on collections, “wrappers”. This class contains methods for algorithms, like binary sorting, search, shuffling, etc.


Q-5:  What is ArrayList in Java?

ArrayList is a data structure that can be stretched to accommodate additional elements within itself and shrink back to a smaller size when elements are removed. It is a very important data structure useful in handling the dynamic behavior of elements.


Q-6:  Explain the basic interfaces of the Java collections framework

Java collection framework is a root of the collection hierarchy. It represents a group of objects as its elements. The Java programming language does not provide a direct implementation of such interface.


Set: Set is a collection having no duplicate elements. It uses hashtable for storing elements.

List: List is an ordered collection that can contain duplicate elements. It enables developers to access any elements from its inbox. The list is like an array having a dynamic length.

MAP: It is an object which maps keys to values. It cannot contain duplicate keys. Each key can be mapped to at least one value.


Q-7:  What is a Stack?

A stack is a special area of computer’s memory that stores temporary variables created by a function. In stack, variables are declared, stored, and initialized during runtime.


Q-8:  What is linked list?

A linked list is a data structure that can store a collection of items. In other words, linked lists can be utilized to store several objects of the same type. Each unit or element of the list is referred as a node. A node in the Linked list has its data and the address of the next node. It is like a chain. Linked Lists are used to create graphs and trees.

Q-9: Differentiate between List and Set.

ListSet
An ordered collection of elementsAn unordered collection of elements
Preserves the insertion orderDoesn’t preserves the insertion order
Duplicate values are allowedDuplicate values are not allowed
Any number of null values can be storedOnly one null values can be stored
ListIterator can be used to traverse the List in any directionListIterator cannot be used to traverse a Set
Contains a legacy class called vectorDoesn’t contains any legacy class

Q-10:  Differentiate between ArrayList and LinkedList

The difference between ArrayList and LinkedList is:

ArrayListLinkedList
It uses a dynamic array.It uses a doubly-linked list.
ArrayList is not preferable for manipulation.LinkedList is preferable for manipulation.
ArrayList provides random access.LinkedList does not provide random access.
ArrayList s stores only objects hence it takes less overhead of memoryLinkedList stores object as well as address object; hence, it takes more overhead of memory.

Q-11: Differentiate between Collection and Collections

The difference between Collection and Collections are:

CollectionCollections
The collection is an interface.Collections is a class.
It represents a group of objects as a single entity.It defines various utility methods for collection objects.
The collection is the root interface of the Java Collection framework.Collections is a general utility class.
This interface is used to derive the collection data structures.This class contains static methods to manipulate data structure.


Q-12:  What is the difference between Set and Map?

SetMap
Set belongs to package-java.util.The map belongs package- java.util.
It can extend the collection interface.It does not extend the collection interface.
It does not allow duplicate values.It allows duplicate values.
Set can sort only one null value.The map can sort multiple null values.

Q-13:  What is the difference between Hashmap and Hashtable?

HashmapHashtable
It is not synchronized.It is synchronized.
HashMap allows one key as a null value.HashTable does not allow null values.
Iterator is used to traverse HashMap.Either Iterator or Enumerator is used for traversing a HashTable.
It can be used for both HashTable, HashMap and is fail-fast.It can be used with HashTable and is fail-safe.
HashMap perform faster than the HashTable.Hashtable is not much faster as compared to HashMap.

Q-14: Define Iterator()

The Iterator() is an interface that provides methods to iterate Collection. Iterator can take the place of Enumeration in Java. It allows the caller to remove elements from the collection. The method provides a generic way for traversal using elements of the collection and implementing iterator design pattern.

Q-15: What are the various ways to iterate over a list?

Java collection Framework programmer can iterate over a list in two ways: 

1) Using iterator

2) using it for each loop.


👉Core Java Interview Questions and Answers for Freshers 

👉Important Core Java Interview questions and answers

👉Java Exception handling Interview Questions and Answers

👉Oops Interview Questions in Java for Freshers

👉Java9 Interview Questions & Answers for beginners

👉Java8 Interview Questions & Answers for beginners 

Post a Comment

0 Comments