SlideShare a Scribd company logo
1 of 15
JAVA UNIT 2 (PART 2) BY:SURBHI SAROHA
SYLLABUS
• Java.util.package
•The collections framework(Interfaces in the collections framework).
•Traversing collections with iterators
•General purpose implementations
•Arrays as collections
JAVA.UTIL.PACKAGE
 Java.util package contains the collections framework, legacy
collection classes, event model, date and time facilities,
internationalization, and miscellaneous utility classes.
Following are the Important Classes in Java.util package :
AbstractCollection: This class provides a skeletal implementation of
the Collection interface, to minimize the effort required to implement
this interface.
AbstractList: This class provides a skeletal implementation of the List
interface to minimize the effort required to implement this interface
backed by a “random access” data store (such as an array).
AbstractMap<K,V>: This class provides a skeletal implementation of
the Map interface, to minimize the effort required to implement this
CONT…
AbstractMap.SimpleEntry<K,V>: An Entry maintaining a key and a value.
AbstractMap.SimpleImmutableEntry<K,V>: An Entry maintaining an
immutable key and value.
AbstractQueue: This class provides skeletal implementations of some Queue
operations.
AbstractSequentialList: This class provides a skeletal implementation of the
List interface to minimize the effort required to implement this interface
backed by a “sequential access” data store (such as a linked list).
AbstractSet: This class provides a skeletal implementation of the Set
interface to minimize the effort required to implement this interface.
ArrayDeque: Resizable-array implementation of the Deque interface.
ArrayList: Resizable-array implementation of the List interface.
Arrays: This class contains various methods for manipulating arrays (such as
sorting and searching).
CONT…
BitSet: This class implements a vector of bits that grows as needed.
Calendar: The Calendar class is an abstract class that provides methods for
converting between a specific instant in time and a set of calendar fields
such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for
manipulating the calendar fields, such as getting the date of the next week.
Collections: This class consists exclusively of static methods that operate on
or return collections.
Currency: Represents a currency.
Date: The class Date represents a specific instant in time, with millisecond
precision.
Dictionary<K,V>: The Dictionary class is the abstract parent of any class,
such as Hashtable, which maps keys to values.
EnumMap,V>: A specialized Map implementation for use with enum type
keys.
EnumSet: A specialized Set implementation for use with enum types.
THE COLLECTIONS
FRAMEWORK(INTERFACES IN THE
COLLECTIONS FRAMEWORK)
The Collection in Java is a framework that provides an architecture to store
and manipulate the group of objects.
Java Collections can achieve all the operations that you perform on a data
such as searching, sorting, insertion, manipulation, and deletion.
Java Collection means a single unit of objects.
Java Collection framework provides many interfaces (Set, List, Queue, Deque)
and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet,
LinkedHashSet, TreeSet).
A Collection represents a single unit of objects, i.e., a group.
The Collection framework represents a unified architecture for storing and
manipulating a group of objects. It has:
Interfaces and its implementations, i.e., classes
Algorithm
INTERFACES OF COLLECTIONS
FRAMEWORK
TRAVERSING COLLECTIONS WITH
ITERATORS
Iterator enables you to cycle through a collection, obtaining or removing
elements. ListIterator extends Iterator to allow bidirectional traversal of a
list, and the modification of elements.
Before you can access a collection through an iterator, you must obtain one.
Each of the collection classes provides an iterator( ) method that returns an
iterator to the start of the collection. By using this iterator object, you can
access each element in the collection, one element at a time.
In general, to use an iterator to cycle through the contents of a collection,
follow these steps −
Obtain an iterator to the start of the collection by calling the collection's
iterator( ) method.
Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as
hasNext( ) returns true.
Within the loop, obtain each element by calling next( ).
For collections that implement List, you can also obtain an iterator by calling
ListIterator.
THE METHODS DECLARED BY
ITERATOR
Sr.No. Method & Description
1 boolean hasNext( )
Returns true if there are more elements. Otherwise, returns false.
2 Object next( )
Returns the next element. Throws NoSuchElementException if there is not a next
element.
3 void remove( )
Removes the current element. Throws IllegalStateException if an attempt is made to
call remove( ) that is not preceded by a call to next( ).
GENERAL PURPOSE
IMPLEMENTATIONS
Implementations are the data objects used to store collections, which
implement the interfaces described in the Interfaces lesson.
The Java Collections Framework provides several general-purpose
implementations of the core interfaces:
For the Set interface, HashSet is the most commonly used implementation.
For the List interface, ArrayList is the most commonly used implementation.
For the Map interface, HashMap is the most commonly used implementation.
For the Queue interface, LinkedList is the most commonly used
implementation.
For the Deque interface, ArrayDeque is the most commonly used
implementation.
Each of the general-purpose implementations provides all optional
operations contained in its interface.
ARRAYS AS COLLECTIONS
Arrays Collections
1. Size is fixed 1. Size is not fixed, size is growable
2. Can hold both primitive
types(boolean, byte, short, int, long
…etc) and object types.
2. Can hold only object types
3. There is no underlying data
structures in arrays. The array itself
used as data structure in java.
3. Every Collection class there is
underlying data structure.
4. There is no utility methods in
arrays
4. Every Collection provides utility
methods
WHY COLLECTIONS ?
Arrays are fixed in size, in development always it’s not possible to
define size of an array. We need to increase size based on
requirement. Collections are not fixed in size, they are growable (size
will be increased when it’s reached max size).
Arrays can only holds one type of elements. Collections can hold
different type of elements.
There is no default method support from arrays for sorting,
searching, retrieving etc… but collections have default utility method
support, it’s handy for for developer. It will reduce the coding time.
WHAT IS AN ARRAY IN JAVA ?
An Array is collection of indexed and fixed number of homogeneous (same
type) elements.
Indexed : Arrays are stored elements in index based. The stored element
position starts from ‘zero’ and second element position ‘1′ and so on.
For example if we take String array to represent Student names [“Satish”,
”Sunil”, ”Suresh”, ”Ravi”] position of “Satish” element is ‘0‘ , position of “Sunil”
is 1, position of “Ravi” is 3.
Fixed : When we are defining array we have to specify the size of array.
Example : String[] students = new String[10]; . Once we created an Array we
can’t increase the size, size is fixed in arrays.
Homogeneous : Arrays elements are homogeneous, it means once we
created array we can store same type of elements. For example in point 4
student array allow to store only String type elements, because the array
type is String.
WHAT IS THE DIFFERENCE BETWEEN
ARRAY AND COLLECTIONS IN JAVA?
Collections are dynamically growable nature,if we add extra element over its size, JVM will not raise
any exception, where as array size is fixed, so it raises ArrayIndexOutofBound exception when you try
to add more than the size.
Collection allows heterogeneous elements where as array allows homogeneous, so when we try to add
different type, it raises error as incompatible type .
Collection are having predefined library to perform operations like sorting or so, where as array
doesn't so developer has to provide own logic.
Array can hold both primitive as well as objects where as collection stores and manages objects alone.
Collections are more flexible than arrays.
Collections are more API dependant (testing and debugging is difficult) where as arrays are less API
dependant
Collections are said to be heavy weight and arrays are lightweight.
When we know the number and data type of elements before hand we can opt arrays where as
collections can be used at any time.
Collections reduces the typedness (due to different type of data) where as arrays improve typedness (
similar type of data).
THANK YOU 

More Related Content

What's hot

Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IOJussi Pohjolainen
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objectskjkleindorfer
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanZeeshan Khan
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threadsDevaKumari Vijay
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IEduardo Bergavera
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic classifis
 
Java collections notes
Java collections notesJava collections notes
Java collections notesSurendar Meesala
 
C++ training
C++ training C++ training
C++ training PL Sharma
 

What's hot (20)

Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
 
Python3
Python3Python3
Python3
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Generics
GenericsGenerics
Generics
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
C++ training
C++ training C++ training
C++ training
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 

Similar to Java Unit 2 (Part 2)

Java collections
Java collectionsJava collections
Java collectionspadmad2291
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxeyemitra1
 
5 collection framework
5 collection framework5 collection framework
5 collection frameworkMinal Maniar
 
Lecture 9
Lecture 9Lecture 9
Lecture 9talha ijaz
 
Week_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdfWeek_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdfPrabhaK22
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java NotesShalabh Chaudhary
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections frameworkRavi Chythanya
 
Collections framework
Collections frameworkCollections framework
Collections frameworkAnand Buddarapu
 
Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]SoniaMathias2
 
11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.pptNaitikChatterjee
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections TutorialsProf. Erwin Globio
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_FrameworkKrishna Sujeer
 

Similar to Java Unit 2 (Part 2) (20)

Java collections
Java collectionsJava collections
Java collections
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Week_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdfWeek_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdf
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Ch03
Ch03Ch03
Ch03
 
Java.util
Java.utilJava.util
Java.util
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
Java util
Java utilJava util
Java util
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]
 
11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 
Collections
CollectionsCollections
Collections
 

More from SURBHI SAROHA

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxSURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3SURBHI SAROHA
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 

More from SURBHI SAROHA (20)

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 

Recently uploaded

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Java Unit 2 (Part 2)

  • 1. JAVA UNIT 2 (PART 2) BY:SURBHI SAROHA
  • 2. SYLLABUS • Java.util.package •The collections framework(Interfaces in the collections framework). •Traversing collections with iterators •General purpose implementations •Arrays as collections
  • 3. JAVA.UTIL.PACKAGE  Java.util package contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes. Following are the Important Classes in Java.util package : AbstractCollection: This class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface. AbstractList: This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a “random access” data store (such as an array). AbstractMap<K,V>: This class provides a skeletal implementation of the Map interface, to minimize the effort required to implement this
  • 4. CONT… AbstractMap.SimpleEntry<K,V>: An Entry maintaining a key and a value. AbstractMap.SimpleImmutableEntry<K,V>: An Entry maintaining an immutable key and value. AbstractQueue: This class provides skeletal implementations of some Queue operations. AbstractSequentialList: This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a “sequential access” data store (such as a linked list). AbstractSet: This class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface. ArrayDeque: Resizable-array implementation of the Deque interface. ArrayList: Resizable-array implementation of the List interface. Arrays: This class contains various methods for manipulating arrays (such as sorting and searching).
  • 5. CONT… BitSet: This class implements a vector of bits that grows as needed. Calendar: The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. Collections: This class consists exclusively of static methods that operate on or return collections. Currency: Represents a currency. Date: The class Date represents a specific instant in time, with millisecond precision. Dictionary<K,V>: The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to values. EnumMap,V>: A specialized Map implementation for use with enum type keys. EnumSet: A specialized Set implementation for use with enum types.
  • 6. THE COLLECTIONS FRAMEWORK(INTERFACES IN THE COLLECTIONS FRAMEWORK) The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion. Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet). A Collection represents a single unit of objects, i.e., a group. The Collection framework represents a unified architecture for storing and manipulating a group of objects. It has: Interfaces and its implementations, i.e., classes Algorithm
  • 8. TRAVERSING COLLECTIONS WITH ITERATORS Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements. Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time. In general, to use an iterator to cycle through the contents of a collection, follow these steps − Obtain an iterator to the start of the collection by calling the collection's iterator( ) method. Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true. Within the loop, obtain each element by calling next( ). For collections that implement List, you can also obtain an iterator by calling ListIterator.
  • 9. THE METHODS DECLARED BY ITERATOR Sr.No. Method & Description 1 boolean hasNext( ) Returns true if there are more elements. Otherwise, returns false. 2 Object next( ) Returns the next element. Throws NoSuchElementException if there is not a next element. 3 void remove( ) Removes the current element. Throws IllegalStateException if an attempt is made to call remove( ) that is not preceded by a call to next( ).
  • 10. GENERAL PURPOSE IMPLEMENTATIONS Implementations are the data objects used to store collections, which implement the interfaces described in the Interfaces lesson. The Java Collections Framework provides several general-purpose implementations of the core interfaces: For the Set interface, HashSet is the most commonly used implementation. For the List interface, ArrayList is the most commonly used implementation. For the Map interface, HashMap is the most commonly used implementation. For the Queue interface, LinkedList is the most commonly used implementation. For the Deque interface, ArrayDeque is the most commonly used implementation. Each of the general-purpose implementations provides all optional operations contained in its interface.
  • 11. ARRAYS AS COLLECTIONS Arrays Collections 1. Size is fixed 1. Size is not fixed, size is growable 2. Can hold both primitive types(boolean, byte, short, int, long …etc) and object types. 2. Can hold only object types 3. There is no underlying data structures in arrays. The array itself used as data structure in java. 3. Every Collection class there is underlying data structure. 4. There is no utility methods in arrays 4. Every Collection provides utility methods
  • 12. WHY COLLECTIONS ? Arrays are fixed in size, in development always it’s not possible to define size of an array. We need to increase size based on requirement. Collections are not fixed in size, they are growable (size will be increased when it’s reached max size). Arrays can only holds one type of elements. Collections can hold different type of elements. There is no default method support from arrays for sorting, searching, retrieving etc… but collections have default utility method support, it’s handy for for developer. It will reduce the coding time.
  • 13. WHAT IS AN ARRAY IN JAVA ? An Array is collection of indexed and fixed number of homogeneous (same type) elements. Indexed : Arrays are stored elements in index based. The stored element position starts from ‘zero’ and second element position ‘1′ and so on. For example if we take String array to represent Student names [“Satish”, ”Sunil”, ”Suresh”, ”Ravi”] position of “Satish” element is ‘0‘ , position of “Sunil” is 1, position of “Ravi” is 3. Fixed : When we are defining array we have to specify the size of array. Example : String[] students = new String[10]; . Once we created an Array we can’t increase the size, size is fixed in arrays. Homogeneous : Arrays elements are homogeneous, it means once we created array we can store same type of elements. For example in point 4 student array allow to store only String type elements, because the array type is String.
  • 14. WHAT IS THE DIFFERENCE BETWEEN ARRAY AND COLLECTIONS IN JAVA? Collections are dynamically growable nature,if we add extra element over its size, JVM will not raise any exception, where as array size is fixed, so it raises ArrayIndexOutofBound exception when you try to add more than the size. Collection allows heterogeneous elements where as array allows homogeneous, so when we try to add different type, it raises error as incompatible type . Collection are having predefined library to perform operations like sorting or so, where as array doesn't so developer has to provide own logic. Array can hold both primitive as well as objects where as collection stores and manages objects alone. Collections are more flexible than arrays. Collections are more API dependant (testing and debugging is difficult) where as arrays are less API dependant Collections are said to be heavy weight and arrays are lightweight. When we know the number and data type of elements before hand we can opt arrays where as collections can be used at any time. Collections reduces the typedness (due to different type of data) where as arrays improve typedness ( similar type of data).