This set of Java Multiple Choice Questions & Answers focuses on “Data Structures-Queue”.
1. Which of the below is not a subinterface of Queue?
Explanation: BlockingQueue, TransferQueue and BlockingQueue are subinterfaces of Queue.
2. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined?
Explanation: A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE.
3. PriorityQueue is thread safe.
Explanation: PriorityQueue is not synchronized. BlockingPriorityQueue is the thread safe implementation.
4. What is difference between dequeue() and peek() function of java?
a) dequeue() and peek() remove and return the next time in line
b) dequeue() and peek() return the next item in line
c) dequeue() removes and returns the next item in line while peek() returns the next item in line
d) peek() removes and returns the next item in line while dequeue() returns the next item in line
Explanation: dequeue() removes the item next in line. peek() returns the item without removing it from the queue.
5. What is the difference between Queue and Stack?
a) Stack is LIFO; Queue is FIFO
b) Queue is LIFO; Stack is FIFO
c) Stack and Queue is FIFO
d) Stack and Queue is LIFO
Explanation: Stack is Last in First out (LIFO) and Queue is First in First out(FIFO).
6. What are the use of front and rear pointers in CircularQueue implementation?
a) Front pointer points to first element; rear pointer points to the last element
b) Rear pointer points to first element; front pointer points to the last element
c) Front and read pointers point to the first element
d) Front pointer points to the first element; rear pointer points to null object
Explanation: CircularQueue implementation is an abstract class where first and rear pointer point to the same object.
7. What is the correct method used to insert and delete items from the queue?
a) push and pop
b) enqueue and dequeue
c) enqueue and peek
d) add and remove
Explanation: enqueue is pushing item into queue; dequeue is removing item from queue; peek returns object without removing it from queue.
Stack uses push and pop methods. add and remove are used in the list.
8. Which data structure is used in Breadth First Traversal of a graph?
Explanation: In Breadth First Traversal of graph the nodes at the same level are accessed in the order of retrieval (i.e FIFO).
9. Where does a new element be inserted in linked list implementation of a queue?
a) Head of list
b) Tail of list
c) At the centre of list
d) All the old entries are pushed and then the new element is inserted
Explanation: To maintain FIFO, newer elements are inserted to the tail of the list.
10. If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder to insert an element in the queue?
Explanation: The front and rear pointer od circular queue point to the first element.
Sanfoundry Global Education & Learning Series – Java Programming Language.
To practice all areas of Java, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.