SlideShare a Scribd company logo
1 of 23
Download to read offline
Java : Collection and
Introduction to
Generics
Developer Students Club - LNCT
What is collection ?
The image shows a collection of watches.
1. Intro
A collection is an object that represents a group of
objects (such as the classic Vector class). A
collections framework is a unified architecture for
representing and manipulating collections,
enabling collections to be manipulated
independently of implementation details.
Advantages of using
collection ?
Tip
In this question,
Think of real world
example
Try to think the
benefits of handling
things as a group.
Few advantages are
● Reduces programming effort by providing data structures and algorithms so
you don't have to write them yourself.
● Increases performance by providing high-performance implementations of data
structures and algorithms. Because the various implementations of each
interface are interchangeable, programs can be tuned by switching
implementations.
● Reduces the effort required to learn APIs by requiring you to learn multiple ad
hoc collection APIs.
● Reduces the effort required to design and implement APIs by not requiring
you to produce ad hoc collections APIs.
● Fosters software reuse by providing a standard interface for collections and
algorithms with which to manipulate them.
The collection framework
internally uses generics.
Let’s code to
understand the basics.
Tip
Open up a text editor
( gedit, Notepad )
and start typing hello
world program in
java
2. Examples
Hit the url :
https://github.com/Pradhan10/Java-Collections-and-Generics
➔ The difference between storing data in array vs arraylist ?
Start with drawing analogies to array in C.
➔ How are we printing all elements in arraylist ?
Did we write the for loop to iterate all elements in list
anywhere ?
Meet Joshua Bloch
He wrote most of the java Collection
framework and was chief architect in
development of language.
Story for illustration purposes only
The main interfaces of the Java Collections Framework
Why do you think
the map interface
was implemented
seperately ?
Tip
Look at the
mathematical
difference between
a set, a sequence
and a mapping.
Code example two
Hit the url :
https://github.com/Pradhan10/Java-Collections-a
nd-Generics/blob/master/QueueClass.java
Code example three
Hit url :
https://goo.gl/Md1
QAi
Generics
The main reasons for using
generics :
1 : Type safety
2 : Cast iron guarantee
Hit url :
https://goo.gl/a15ush
Cast-iron guarantee
The implicit casts added by
the compilation of generics
never fail. (applies only when no unchecked warnings have been issued
by the compiler.)
Generics in action
The 3 most used type parameters
1 : <E>, <T>, <K, V> (Used in Map interface)
2 : ? extends E (Used in iterator class)
3 : ? super T (Used in Comparator method)
Wildcard capture (?), add members of collection that
are subtype of E
Wildcard capture (?), destination may have elements
of any subtype of T
Feedback please :
https://goo.gl/cjJoJN
DSC Mail :
appliedcs.lnct@gmail.com
LinkedIn :
https://www.linkedin.com
/in/pradhan-rishi-sharma1
0
Thank you !

More Related Content

Similar to JAVA Collection and generics

Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Frameworkguestd8c458
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfTobiasGoeschel
 
Oops design pattern intro
Oops design pattern intro Oops design pattern intro
Oops design pattern intro anshu_atri
 
Java%20 collections%20framework
Java%20 collections%20frameworkJava%20 collections%20framework
Java%20 collections%20frameworkIlakkian
 
Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]SoniaMathias2
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentGabriel Walt
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
React.js alternatives modern web frameworks and lightweight java script libr...
React.js alternatives  modern web frameworks and lightweight java script libr...React.js alternatives  modern web frameworks and lightweight java script libr...
React.js alternatives modern web frameworks and lightweight java script libr...Katy Slemon
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortalscgack
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernizationdevObjective
 

Similar to JAVA Collection and generics (20)

Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Oops design pattern intro
Oops design pattern intro Oops design pattern intro
Oops design pattern intro
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
Java%20 collections%20framework
Java%20 collections%20frameworkJava%20 collections%20framework
Java%20 collections%20framework
 
Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Dtacs
DtacsDtacs
Dtacs
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Shuzworld Analysis
Shuzworld AnalysisShuzworld Analysis
Shuzworld Analysis
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
React.js alternatives modern web frameworks and lightweight java script libr...
React.js alternatives  modern web frameworks and lightweight java script libr...React.js alternatives  modern web frameworks and lightweight java script libr...
React.js alternatives modern web frameworks and lightweight java script libr...
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 

More from Pradhan Rishi Sharma (20)

JAVA Threads explained
JAVA Threads explained JAVA Threads explained
JAVA Threads explained
 
Plasma TFT
Plasma TFTPlasma TFT
Plasma TFT
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
0/1Knapsack
0/1Knapsack0/1Knapsack
0/1Knapsack
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Aids Awareness , Nss , Healthcare !
Aids Awareness , Nss , Healthcare !Aids Awareness , Nss , Healthcare !
Aids Awareness , Nss , Healthcare !
 
D Flip Flop
D Flip Flop D Flip Flop
D Flip Flop
 
Optical fiber
Optical fiberOptical fiber
Optical fiber
 
Optical Fiber
Optical Fiber Optical Fiber
Optical Fiber
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Lasers
Lasers Lasers
Lasers
 
Solar Energy
Solar Energy Solar Energy
Solar Energy
 
Solar Energy
Solar EnergySolar Energy
Solar Energy
 
Solar Energy
Solar Energy Solar Energy
Solar Energy
 
Beam , support and reaction
Beam , support and reaction Beam , support and reaction
Beam , support and reaction
 
Beam , support and reaction
Beam , support and reaction Beam , support and reaction
Beam , support and reaction
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

JAVA Collection and generics

  • 1. Java : Collection and Introduction to Generics Developer Students Club - LNCT
  • 2. What is collection ? The image shows a collection of watches.
  • 3. 1. Intro A collection is an object that represents a group of objects (such as the classic Vector class). A collections framework is a unified architecture for representing and manipulating collections, enabling collections to be manipulated independently of implementation details.
  • 4. Advantages of using collection ? Tip In this question, Think of real world example Try to think the benefits of handling things as a group.
  • 5. Few advantages are ● Reduces programming effort by providing data structures and algorithms so you don't have to write them yourself. ● Increases performance by providing high-performance implementations of data structures and algorithms. Because the various implementations of each interface are interchangeable, programs can be tuned by switching implementations. ● Reduces the effort required to learn APIs by requiring you to learn multiple ad hoc collection APIs. ● Reduces the effort required to design and implement APIs by not requiring you to produce ad hoc collections APIs. ● Fosters software reuse by providing a standard interface for collections and algorithms with which to manipulate them.
  • 6. The collection framework internally uses generics. Let’s code to understand the basics. Tip Open up a text editor ( gedit, Notepad ) and start typing hello world program in java
  • 7. 2. Examples Hit the url : https://github.com/Pradhan10/Java-Collections-and-Generics ➔ The difference between storing data in array vs arraylist ? Start with drawing analogies to array in C. ➔ How are we printing all elements in arraylist ? Did we write the for loop to iterate all elements in list anywhere ?
  • 8. Meet Joshua Bloch He wrote most of the java Collection framework and was chief architect in development of language.
  • 9. Story for illustration purposes only The main interfaces of the Java Collections Framework
  • 10. Why do you think the map interface was implemented seperately ? Tip Look at the mathematical difference between a set, a sequence and a mapping.
  • 11. Code example two Hit the url : https://github.com/Pradhan10/Java-Collections-a nd-Generics/blob/master/QueueClass.java
  • 12. Code example three Hit url : https://goo.gl/Md1 QAi
  • 14. The main reasons for using generics : 1 : Type safety 2 : Cast iron guarantee
  • 16. Cast-iron guarantee The implicit casts added by the compilation of generics never fail. (applies only when no unchecked warnings have been issued by the compiler.)
  • 18. The 3 most used type parameters 1 : <E>, <T>, <K, V> (Used in Map interface) 2 : ? extends E (Used in iterator class) 3 : ? super T (Used in Comparator method)
  • 19. Wildcard capture (?), add members of collection that are subtype of E
  • 20. Wildcard capture (?), destination may have elements of any subtype of T
  • 22. DSC Mail : appliedcs.lnct@gmail.com LinkedIn : https://www.linkedin.com /in/pradhan-rishi-sharma1 0