java.util and                     CollectionFrameworkAvailable at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
• This presentation is for teaching purpose only.    • This presentation may contain some material      from books / api d...
Date and Time Related Classes    •   Date    •   TimeZone    •   Calendar    •   GregorianCalendar    • Epoch : 1st Jan 19...
Simple Program                                            ????????? toString()Available at : http://www.asbspace.in/ppt   ...
ConstructorAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Comparing DateAvailable at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Calendar    •   Abstract Class    •   No public constructor    •   day, month, year, hour, minutes , seconds, era    •   M...
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Some MethodsAvailable at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
TimeZone    • Class    • Maintains offset value    • ID for instances    • public static TimeZone getDefault()    • public...
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
•   public String getId()    •   public String getDisplayName()    •   public int getOffset(long date)    •   public int g...
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
GregorianCalendar    •   Concrete class of Calendar    •   Two fields AD and BC for era    •   7 constructors    •   Greog...
GregorianCalendar    • Ff   Year = Number of year elapsed from 1900   Month = 0 indicating JanAvailable at : http://www.as...
GregorianCalendar    fd    • boolean isLeapYear(int year)         – Test for leap yearAvailable at : http://www.asbspace.i...
DateFormatAvailable at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Array Class    • Contains various methods for manipulating      arrays - mostly static methods    • Contains a static fact...
fill method    • public static void fill(datatype[] array, datatype      value)    • public static void fill(datatype[] ar...
ProgramAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
OutputAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
fill()Available at : http://www.asbspace.in/ppt            Prof. Ashish Bhatia
fill()Available at : http://www.asbspace.in/ppt            Prof. Ashish Bhatia
equals()    • Return Boolean    • Take two arguments    • public static boolean equals( datatype [] a,      datatype[] b) ...
equals()Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
sort()    • Sort the array    • Ascending OrderAvailable at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
sort()Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
binarySearch()    • Uses binary search method to find the index      of element    • Prerequisites : Sorted ArrayAvailable...
binarySearch()Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Collection Framework    • Standardizing and having interoperability      between various data structures    • Introduced i...
Collection Framework    • Eight generics interfaces type         – Determined the common methods for all           collect...
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Basic OperationsAvailable at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Basic OperationsAvailable at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Array OperationsAvailable at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Bulk OperationAvailable at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Iterator    • Lets you cycle through collectionAvailable at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ExampleAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Set Interface    • Defines a set    • Collection of unique element [ no duplication]    • Extends the Collection         –...
List Interface    •   Extends Collection    •   Insertion, updating, all are index based    •   Index starts from 0    •  ...
MethodsAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
MethodsAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
MethodsAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
List Iterator    • public interface ListIterator<E> extends      Iterator<E>    • A ListIterator has no current element;  ...
List Iterator    •Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
List Iterator   • In general, to use an iterator to cycle through     thecontents of a collection, follow these steps:   1...
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class    • Dynamic Array         – The size of a Vector can grow or shrink as needed           to accommodate addin...
Vector Class    • Modified from Java 1.2 [ IS IT SAME AS JAVA      2]    • To implement List and become part of      Colle...
Vector Class Constructors                                            Initial Size 10    • The increment specifies the numb...
Vector Class    • Starts with initial capacity    • Allocates more space for new objects once the      capacity is reached...
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector ClassAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Now Lets add elements    • addElement(Object o)    • Size = ? Capacity = ?Available at : http://www.asbspace.in/ppt   Prof...
• Size = 4                              Capacity = 5         – WHY    •   Size = ?         Capacity = ?    •   5,5    •   ...
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Solution : Generics    • <Object>         – Specifies the data type    • Vector<String> v = new Vector<String> ();    • Ve...
Printing VectorAvailable at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
One Example Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Lets Create Vector    • Size = ?? Capacity = ??    • DEFAULT = 10Available at : http://www.asbspace.in/ppt     Prof. Ashis...
Will This Work !!!Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
How to Print area ?Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
StackAvailable at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ArrayListAvailable at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ArrayList    • Resizable-array implementation of      the List interface.    • Implements all optional list operations, an...
Map Interface    • Continued to Next PresentationAvailable at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Upcoming SlideShare
Loading in …5
×

Understanding Date Handling and Collection Framework

940
-1

Published on

Gives a brief usage of Dates in java followed by collection framework

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
940
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Understanding Date Handling and Collection Framework

  1. 1. java.util and CollectionFrameworkAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  2. 2. • This presentation is for teaching purpose only. • This presentation may contain some material from books / api documentation / internet. • No intention of breaking any rights or what so ever.Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  3. 3. Date and Time Related Classes • Date • TimeZone • Calendar • GregorianCalendar • Epoch : 1st Jan 1970 0:0:0.0 GMT – 1st January 1970 5:30:0.0 ISTAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  4. 4. Simple Program ????????? toString()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  5. 5. ConstructorAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  6. 6. Comparing DateAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  7. 7. Calendar • Abstract Class • No public constructor • day, month, year, hour, minutes , seconds, era • Many int constants • Many methodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  8. 8. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  9. 9. Some MethodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  10. 10. TimeZone • Class • Maintains offset value • ID for instances • public static TimeZone getDefault() • public static void setDefault(TimeZone zone)Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  11. 11. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  12. 12. • public String getId() • public String getDisplayName() • public int getOffset(long date) • public int getRawOffset • public void setRawOffset(int offmilliseconds) • public static TimeZone getTimeZone(String ID)Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  13. 13. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  14. 14. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  15. 15. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  16. 16. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  17. 17. GregorianCalendar • Concrete class of Calendar • Two fields AD and BC for era • 7 constructors • GreogrianCalendar gc = new GregorianCalendar(); – Current date and time in default locale and time zoneAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  18. 18. GregorianCalendar • Ff Year = Number of year elapsed from 1900 Month = 0 indicating JanAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  19. 19. GregorianCalendar fd • boolean isLeapYear(int year) – Test for leap yearAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  20. 20. DateFormatAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  21. 21. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  22. 22. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  23. 23. Array Class • Contains various methods for manipulating arrays - mostly static methods • Contains a static factory that allows arrays to be viewed as lists. • fill, equals, sort, binarysearch, toStringAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  24. 24. fill method • public static void fill(datatype[] array, datatype value) • public static void fill(datatype[] array, int fromindex , int toindex, datatype value) • datatype = Primitive Datatype + ObjectAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  25. 25. ProgramAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  26. 26. OutputAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  27. 27. fill()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  28. 28. fill()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  29. 29. equals() • Return Boolean • Take two arguments • public static boolean equals( datatype [] a, datatype[] b) • Compare each element and size of arrayAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  30. 30. equals()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  31. 31. sort() • Sort the array • Ascending OrderAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  32. 32. sort()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  33. 33. binarySearch() • Uses binary search method to find the index of element • Prerequisites : Sorted ArrayAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  34. 34. binarySearch()Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  35. 35. Collection Framework • Standardizing and having interoperability between various data structures • Introduced in Java 1.2 • Relies on Standard interfacesAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  36. 36. Collection Framework • Eight generics interfaces type – Determined the common methods for all collection class • Operations – Basic Operations – Array Operations – Bulk OperationsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  37. 37. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  38. 38. Basic OperationsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  39. 39. Basic OperationsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  40. 40. Array OperationsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  41. 41. Bulk OperationAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  42. 42. Iterator • Lets you cycle through collectionAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  43. 43. ExampleAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  44. 44. Set Interface • Defines a set • Collection of unique element [ no duplication] • Extends the Collection – All the methods • HashSet and TreeSet are concrete classes • AbstractSet : base abstract classAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  45. 45. List Interface • Extends Collection • Insertion, updating, all are index based • Index starts from 0 • It can store duplicates value • It adds its own methodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  46. 46. MethodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  47. 47. MethodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  48. 48. MethodsAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  49. 49. List Iterator • public interface ListIterator<E> extends Iterator<E> • A ListIterator has no current element; its cursor position always lies between the element that would be returned by a call toprevious() and the element that would be returned by a call to next(). • An iterator for a list of length n has n+1 possible cursor positions,Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  50. 50. List Iterator •Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  51. 51. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  52. 52. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  53. 53. List Iterator • In general, to use an iterator to cycle through thecontents of a collection, follow these steps: 1.Obtain an iterator to the start of the collection by calling the collection’s iterator( ) method. 2.Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true. 3.Within the loop, obtain each element by calling next( ).Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  54. 54. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  55. 55. Vector Class • Dynamic Array – The size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created • Synchronized • Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrementAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  56. 56. Vector Class • Modified from Java 1.2 [ IS IT SAME AS JAVA 2] • To implement List and become part of Collection FrameworkAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  57. 57. Vector Class Constructors Initial Size 10 • The increment specifies the number of elements to allocate each time that a vector is resized upward.Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  58. 58. Vector Class • Starts with initial capacity • Allocates more space for new objects once the capacity is reached • It allocates more space that required so allocation is done minimal time • Double size if nothing is specified • What if incr size = 0 [ Default Value]Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  59. 59. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  60. 60. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  61. 61. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  62. 62. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  63. 63. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  64. 64. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  65. 65. Vector ClassAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  66. 66. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  67. 67. Now Lets add elements • addElement(Object o) • Size = ? Capacity = ?Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  68. 68. • Size = 4 Capacity = 5 – WHY • Size = ? Capacity = ? • 5,5 • 5,8 • Any Other OptionAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  69. 69. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  70. 70. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  71. 71. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  72. 72. Solution : Generics • <Object> – Specifies the data type • Vector<String> v = new Vector<String> (); • Vector<Rectangle> v = new Vector<Rectangle> ();Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  73. 73. Printing VectorAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  74. 74. One Example Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  75. 75. Lets Create Vector • Size = ?? Capacity = ?? • DEFAULT = 10Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  76. 76. Will This Work !!!Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  77. 77. How to Print area ?Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  78. 78. StackAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  79. 79. ArrayListAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  80. 80. ArrayList • Resizable-array implementation of the List interface. • Implements all optional list operations, and permits all elements, including null. • This class is roughly equivalent to Vector, except that it is unsynchronized.Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  81. 81. Map Interface • Continued to Next PresentationAvailable at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×