SlideShare a Scribd company logo
QUEUE ( COLLECTION
FRAME WORK)
Name:B.Bhavani
Roll no:23h51a6272
Collection framework:
The Java collections framework is a set of classes and
interfaces that implement commonly reusable
collection of data structures.
Queue Interface:
■ A queue is an object that represents a data structure
designed to have the element inserted at the end of the
queue, and the element removed from the beginning
of the queue. The order of elements of the queue in
Java is FIFO (first-in-first-out).
■ The Queue Interface is present in java.util package
and extends the Collection interface.
Syntax for creating queue objects:
Queue<Obj> queue = new PriorityQueue<Obj> ();
 Methods of queue:
■ add(E e): Adds an element to the rear of the
queue. If the queue is full, it throws an
exception.
■ offer(E e): Adds an element to the rear of the
queue. If the queue is full, it returns false
 remove():Removes the object at the front of the queue. If the queue is
empty, it throws a NoSuchElementException.
 poll(): Retrieves and removes the
element at the front of the queue. If the
queue is empty, this method returns
null instead of throwing an exception
 Element: Retrieves, but does not remove, the element at the front of the
queue. If the queue is empty, this method throws a NoSuchElementException.
 Peek: Retrieves, but does not remove, the
element at the front of the queue. If the queue is
empty, this method returns null instead of
throwing an exception.
Operations on Queue Interface:
■ Inserting Elements:In order to add an element in a
queue, we can use the add() method. The insertion order
is not retained in the PriorityQueue. The elements are
stored based on the priority order which is ascending by
default.
■ Deleting Elements:In order to remove an element
from a queue, we can use the remove() method. If there
are multiple such objects, then the first occurrence of
the object is removed. Apart from that, poll() method is
also used to remove the head and return it.
■ Iterating the Queue:There are multiple ways to
iterate through the Queue. The most famous way is
converting the queue to the array and traversing using
the for loop. However, the queue also has an inbuilt
iterator which can be used to iterate through the queue.
Classes that implement the Queue
Interface:
1. PriorityQueue: PriorityQueue class which is implemented in the collection
framework provides us a way to process the objects based on the priority.
2. Linkedlist:LinkedList is a class which is implemented in the collection framework
which inherently implements the linked list data structure. It is a linear data structure
where the elements are not stored in contiguous locations and every element is a
separate object with a data part and address part.
3. PriorityBlockingQueue:It is to be noted that both the implementations, the
PriorityQueue and LinkedList are not thread-safe. PriorityBlockingQueue is one
alternative implementation if thread-safe implementation is needed.
Advantages:
• Order preservation: The Queue interface provides a way to store and retrieve elements
in a specific order, following the first-in, first-out (FIFO) principle.
• Flexibility: The Queue interface is a subtype of the Collection interface, which means that it
can be used with many different data structures and algorithms, depending on the requirements
of the application.
• Thread–safety: Some implementations of the Queue interface, such as the
java.util.concurrent.Concurrent LinkedQueue class, are thread-safe, which means that they can
be accessed by multiple threads simultaneously without causing conflicts.
• Performance: The Queue interface provides efficient implementations for adding,
removing, and inspecting elements, making it a useful tool for managing collections of elements
in performance-critical applications.
Disadvantages:
• Limited functionality: The Queue interface is designed specifically for managing
collections of elements in a specific order, which means that it may not be suitable for more
complex data structures or algorithms.
• Size restrictions: Some implementations of the Queue interface, such as the ArrayDeque
class, have a fixed size, which means that they cannot grow beyond a certain number of elements.
• Memory usage: Depending on the implementation, the Queue interface may require more
memory than other data structures, especially if it needs to store additional information about the
order of the elements.
• Complexity: The Queue interface can be difficult to use and understand for novice
programmers, especially if they are not familiar with the principles of data structures and
algorithms.
Applications:
•Job Scheduling: Manages tasks for processing in FIFO order (e.g., print jobs).
•Breadth-First Search (BFS):Used in graph or tree traversal to explore nodes level by
level.
•Producer-Consumer Problem: Implements thread-safe task management where producers
add tasks and consumers process them.
•Real-time Event Handling: Manages events/messages in GUI or event-driven systems.
•Task Scheduling in Thread Pools: Holds and manages tasks submitted to
ExecutorService for processing.
The Queue interface in Java is a crucial part of the Java Collections
Framework, designed to manage a collection of elements in a first-in,
first-out (FIFO) manner. It provides a systematic way to add elements at
one end and remove them from the other, which is particularly useful in
scenarios like task scheduling, resource management, and various
algorithms that require ordered processing.
Conclusion:
Queue collection of Frame work in oops through java

More Related Content

PPT
2 b queues
PPTX
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
PPTX
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
PPTX
Collections
PPTX
stacks and queues for public
PPTX
QUEUE in data-structure (classification, working procedure, Applications)
PPTX
Collections Training
PPTX
14. collections
2 b queues
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
Collections
stacks and queues for public
QUEUE in data-structure (classification, working procedure, Applications)
Collections Training
14. collections

Similar to Queue collection of Frame work in oops through java (20)

PPTX
DS UNIT2QUEUES.pptx
PPTX
Understanding the Concepts and Applications of Stack and Queue
PPT
Object Oriented Programming Concepts using Java
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PDF
Introduction data structure
PPT
Data structure and problem solving ch01.ppt
PPTX
Collections in java in detail for easy understanding
PPTX
Queues
PPT
02._Object-Oriented_Programming_Concepts.ppt
PPTX
Standard Template Library
PPT
Data structures
PPTX
Queue types of queue and algorithms and queue
PPTX
DS10-QUEUE0000000000000000000000000000000000000.pptx
PPTX
stack_presentaton_HUSNAIN[2].pojklklklptx
PPT
Chapter 7 ds
PPTX
stack.pptx
PPTX
Standard template library
DS UNIT2QUEUES.pptx
Understanding the Concepts and Applications of Stack and Queue
Object Oriented Programming Concepts using Java
Stack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptx
Introduction data structure
Data structure and problem solving ch01.ppt
Collections in java in detail for easy understanding
Queues
02._Object-Oriented_Programming_Concepts.ppt
Standard Template Library
Data structures
Queue types of queue and algorithms and queue
DS10-QUEUE0000000000000000000000000000000000000.pptx
stack_presentaton_HUSNAIN[2].pojklklklptx
Chapter 7 ds
stack.pptx
Standard template library
Ad

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
master seminar digital applications in india
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Lesson notes of climatology university.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Cell Structure & Organelles in detailed.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
Basic Mud Logging Guide for educational purpose
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
master seminar digital applications in india
human mycosis Human fungal infections are called human mycosis..pptx
Lesson notes of climatology university.
PPH.pptx obstetrics and gynecology in nursing
Cell Structure & Organelles in detailed.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Sports Quiz easy sports quiz sports quiz
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
VCE English Exam - Section C Student Revision Booklet
Computing-Curriculum for Schools in Ghana
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
Anesthesia in Laparoscopic Surgery in India
Cell Types and Its function , kingdom of life
Ad

Queue collection of Frame work in oops through java

  • 1. QUEUE ( COLLECTION FRAME WORK) Name:B.Bhavani Roll no:23h51a6272
  • 2. Collection framework: The Java collections framework is a set of classes and interfaces that implement commonly reusable collection of data structures.
  • 3. Queue Interface: ■ A queue is an object that represents a data structure designed to have the element inserted at the end of the queue, and the element removed from the beginning of the queue. The order of elements of the queue in Java is FIFO (first-in-first-out). ■ The Queue Interface is present in java.util package and extends the Collection interface.
  • 4. Syntax for creating queue objects: Queue<Obj> queue = new PriorityQueue<Obj> ();  Methods of queue: ■ add(E e): Adds an element to the rear of the queue. If the queue is full, it throws an exception. ■ offer(E e): Adds an element to the rear of the queue. If the queue is full, it returns false
  • 5.  remove():Removes the object at the front of the queue. If the queue is empty, it throws a NoSuchElementException.  poll(): Retrieves and removes the element at the front of the queue. If the queue is empty, this method returns null instead of throwing an exception
  • 6.  Element: Retrieves, but does not remove, the element at the front of the queue. If the queue is empty, this method throws a NoSuchElementException.  Peek: Retrieves, but does not remove, the element at the front of the queue. If the queue is empty, this method returns null instead of throwing an exception.
  • 7. Operations on Queue Interface: ■ Inserting Elements:In order to add an element in a queue, we can use the add() method. The insertion order is not retained in the PriorityQueue. The elements are stored based on the priority order which is ascending by default. ■ Deleting Elements:In order to remove an element from a queue, we can use the remove() method. If there are multiple such objects, then the first occurrence of the object is removed. Apart from that, poll() method is also used to remove the head and return it. ■ Iterating the Queue:There are multiple ways to iterate through the Queue. The most famous way is converting the queue to the array and traversing using the for loop. However, the queue also has an inbuilt iterator which can be used to iterate through the queue.
  • 8. Classes that implement the Queue Interface: 1. PriorityQueue: PriorityQueue class which is implemented in the collection framework provides us a way to process the objects based on the priority. 2. Linkedlist:LinkedList is a class which is implemented in the collection framework which inherently implements the linked list data structure. It is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. 3. PriorityBlockingQueue:It is to be noted that both the implementations, the PriorityQueue and LinkedList are not thread-safe. PriorityBlockingQueue is one alternative implementation if thread-safe implementation is needed.
  • 9. Advantages: • Order preservation: The Queue interface provides a way to store and retrieve elements in a specific order, following the first-in, first-out (FIFO) principle. • Flexibility: The Queue interface is a subtype of the Collection interface, which means that it can be used with many different data structures and algorithms, depending on the requirements of the application. • Thread–safety: Some implementations of the Queue interface, such as the java.util.concurrent.Concurrent LinkedQueue class, are thread-safe, which means that they can be accessed by multiple threads simultaneously without causing conflicts. • Performance: The Queue interface provides efficient implementations for adding, removing, and inspecting elements, making it a useful tool for managing collections of elements in performance-critical applications.
  • 10. Disadvantages: • Limited functionality: The Queue interface is designed specifically for managing collections of elements in a specific order, which means that it may not be suitable for more complex data structures or algorithms. • Size restrictions: Some implementations of the Queue interface, such as the ArrayDeque class, have a fixed size, which means that they cannot grow beyond a certain number of elements. • Memory usage: Depending on the implementation, the Queue interface may require more memory than other data structures, especially if it needs to store additional information about the order of the elements. • Complexity: The Queue interface can be difficult to use and understand for novice programmers, especially if they are not familiar with the principles of data structures and algorithms.
  • 11. Applications: •Job Scheduling: Manages tasks for processing in FIFO order (e.g., print jobs). •Breadth-First Search (BFS):Used in graph or tree traversal to explore nodes level by level. •Producer-Consumer Problem: Implements thread-safe task management where producers add tasks and consumers process them. •Real-time Event Handling: Manages events/messages in GUI or event-driven systems. •Task Scheduling in Thread Pools: Holds and manages tasks submitted to ExecutorService for processing.
  • 12. The Queue interface in Java is a crucial part of the Java Collections Framework, designed to manage a collection of elements in a first-in, first-out (FIFO) manner. It provides a systematic way to add elements at one end and remove them from the other, which is particularly useful in scenarios like task scheduling, resource management, and various algorithms that require ordered processing. Conclusion: