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 !

JAVA Collection and generics

  • 1.
    Java : Collectionand Introduction to Generics Developer Students Club - LNCT
  • 2.
    What is collection? The image shows a collection of watches.
  • 3.
    1. Intro A collectionis 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 internallyuses 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 theurl : 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 Hewrote most of the java Collection framework and was chief architect in development of language.
  • 9.
    Story for illustrationpurposes only The main interfaces of the Java Collections Framework
  • 10.
    Why do youthink the map interface was implemented seperately ? Tip Look at the mathematical difference between a set, a sequence and a mapping.
  • 11.
    Code example two Hitthe url : https://github.com/Pradhan10/Java-Collections-a nd-Generics/blob/master/QueueClass.java
  • 12.
    Code example three Hiturl : https://goo.gl/Md1 QAi
  • 13.
  • 14.
    The main reasonsfor using generics : 1 : Type safety 2 : Cast iron guarantee
  • 15.
  • 16.
    Cast-iron guarantee The implicitcasts added by the compilation of generics never fail. (applies only when no unchecked warnings have been issued by the compiler.)
  • 17.
  • 18.
    The 3 mostused 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
  • 21.
  • 22.
    DSC Mail : appliedcs.lnct@gmail.com LinkedIn: https://www.linkedin.com /in/pradhan-rishi-sharma1 0
  • 23.