SlideShare une entreprise Scribd logo
1  sur  81
Télécharger pour lire hors ligne
java.util and
                     CollectionFramework




Available 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 documentation / internet.
    • No intention of breaking any rights or what so
      ever.




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
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 IST


Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Simple Program




                                            ????????? toString()
Available at : http://www.asbspace.in/ppt                   Prof. Ashish Bhatia
Constructor




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Comparing Date




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Calendar
    •   Abstract Class
    •   No public constructor
    •   day, month, year, hour, minutes , seconds, era
    •   Many int constants
    •   Many methods




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Some Methods




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
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
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
•   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
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
    •   GreogrianCalendar gc = new
        GregorianCalendar();
         – Current date and time in default locale and time
           zone



Available at : http://www.asbspace.in/ppt         Prof. Ashish Bhatia
GregorianCalendar
    • Ff




   Year = Number of year elapsed from 1900
   Month = 0 indicating Jan

Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
GregorianCalendar
    fd




    • boolean isLeapYear(int year)
         – Test for leap year



Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
DateFormat




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
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, toString


Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
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 + Object



Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Program




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Output




Available 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)

    • Compare each element and size of array



Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
equals()




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
sort()
    • Sort the array
    • Ascending Order




Available 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 Array




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
binarySearch()




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Collection Framework
    • Standardizing and having interoperability
      between various data structures
    • Introduced in Java 1.2
    • Relies on Standard interfaces




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Collection Framework
    • Eight generics interfaces type
         – Determined the common methods for all
           collection class
    • Operations
         – Basic Operations
         – Array Operations
         – Bulk Operations



Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Basic Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Basic Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Array Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Bulk Operation




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Iterator
    • Lets you cycle through collection




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
Example




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
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 class



Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
List Interface
    •   Extends Collection
    •   Insertion, updating, all are index based
    •   Index starts from 0
    •   It can store duplicates value
    •   It adds its own methods




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
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
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.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
Vector Class




Available 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 adding and removing items after
           the Vector has been created


    • Synchronized
    • Each vector tries to optimize storage
      management by maintaining a capacity and
      a capacityIncrement
Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
Vector Class
    • Modified from Java 1.2 [ IS IT SAME AS JAVA
      2]
    • To implement List and become part of
      Collection Framework




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
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
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
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available 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. Ashish Bhatia
• Size = 4                              Capacity = 5
         – WHY



    •   Size = ?         Capacity = ?
    •   5,5
    •   5,8
    •   Any Other Option
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
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
Printing Vector




Available 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 = 10

Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
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
Stack




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ArrayList




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
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
Map Interface
    • Continued to Next Presentation




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia

Contenu connexe

Plus de ashishspace

I/O in java Part 1
I/O in java Part 1I/O in java Part 1
I/O in java Part 1ashishspace
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationashishspace
 
Nested and Enum in Java
Nested and Enum in JavaNested and Enum in Java
Nested and Enum in Javaashishspace
 
HTTP Basic and Servlet Basic
HTTP Basic and Servlet BasicHTTP Basic and Servlet Basic
HTTP Basic and Servlet Basicashishspace
 
Java packages and access specifiers
Java packages and access specifiersJava packages and access specifiers
Java packages and access specifiersashishspace
 
Data types and operators and statements
Data types and operators and statementsData types and operators and statements
Data types and operators and statementsashishspace
 

Plus de ashishspace (6)

I/O in java Part 1
I/O in java Part 1I/O in java Part 1
I/O in java Part 1
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Nested and Enum in Java
Nested and Enum in JavaNested and Enum in Java
Nested and Enum in Java
 
HTTP Basic and Servlet Basic
HTTP Basic and Servlet BasicHTTP Basic and Servlet Basic
HTTP Basic and Servlet Basic
 
Java packages and access specifiers
Java packages and access specifiersJava packages and access specifiers
Java packages and access specifiers
 
Data types and operators and statements
Data types and operators and statementsData types and operators and statements
Data types and operators and statements
 

Dernier

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
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
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
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
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 

Dernier (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
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
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
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
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 

Understanding Date Handling and Collection Framework

  • 1. java.util and CollectionFramework Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. 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 IST Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 4. Simple Program ????????? toString() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 5. Constructor Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 6. Comparing Date Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 7. Calendar • Abstract Class • No public constructor • day, month, year, hour, minutes , seconds, era • Many int constants • Many methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 8. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 9. Some Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 14. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 15. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 16. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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 zone Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 18. GregorianCalendar • Ff Year = Number of year elapsed from 1900 Month = 0 indicating Jan Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 19. GregorianCalendar fd • boolean isLeapYear(int year) – Test for leap year Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 20. DateFormat Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 21. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 22. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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, toString Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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 + Object Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 25. Program Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 26. Output Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 27. fill() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 28. fill() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 29. equals() • Return Boolean • Take two arguments • public static boolean equals( datatype [] a, datatype[] b) • Compare each element and size of array Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 30. equals() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 31. sort() • Sort the array • Ascending Order Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 32. sort() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 33. binarySearch() • Uses binary search method to find the index of element • Prerequisites : Sorted Array Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 34. binarySearch() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 35. Collection Framework • Standardizing and having interoperability between various data structures • Introduced in Java 1.2 • Relies on Standard interfaces Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 36. Collection Framework • Eight generics interfaces type – Determined the common methods for all collection class • Operations – Basic Operations – Array Operations – Bulk Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 37. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 38. Basic Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 39. Basic Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 40. Array Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 41. Bulk Operation Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 42. Iterator • Lets you cycle through collection Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 43. Example Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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 class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 45. List Interface • Extends Collection • Insertion, updating, all are index based • Index starts from 0 • It can store duplicates value • It adds its own methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 46. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 47. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 48. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. List Iterator • Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 51. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 52. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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 capacityIncrement Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 56. Vector Class • Modified from Java 1.2 [ IS IT SAME AS JAVA 2] • To implement List and become part of Collection Framework Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. 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. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 60. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 61. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 62. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 63. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 64. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 65. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 66. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 67. Now Lets add elements • addElement(Object o) • Size = ? Capacity = ? Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 68. • Size = 4 Capacity = 5 – WHY • Size = ? Capacity = ? • 5,5 • 5,8 • Any Other Option Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 69. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 70. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 71. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. Printing Vector Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 74. One Example  Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 75. Lets Create Vector • Size = ?? Capacity = ?? • DEFAULT = 10 Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 76. Will This Work !!! Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 77. How to Print area ? Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 78. Stack Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 79. ArrayList Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 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. Map Interface • Continued to Next Presentation Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia