This set of Java Multiple Choice Questions & Answers focuses on “Data Structures-Queue”.
1. Which of the below is not a subinterface of Queue?
a) BlockingQueue
b) BlockingEnque
c) TransferQueue
d) BlockingQueue
View Answer
Explanation: BlockingQueue, TransferQueue and BlockingQueue are subinterfaces of Queue.
2. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined?
a) Integer.MAX_VALUE
b) BigDecimal.MAX_VALUE
c) 99999999
d) Integer.INFINITY
View Answer
Explanation: A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE.
3. PriorityQueue is thread safe.
a) True
b) False
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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?
a) Stack
b) Queue
c) Array
d) Tree
View Answer
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
View Answer
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?
a) rear=(rear%1)+MAX_SIZE
b) rear=(rear+1)%MAX_SIZE
c) rear=rear+(1%MAX_SIZE)
d) rear=rear%(MAX_SIZE+1)
View Answer
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.
- Apply for Computer Science Internship
- Check Java Books
- Check Programming Books
- Practice Information Technology MCQs
- Practice Programming MCQs