1 / 18

More Java: Static and Final, Abstract Class and Interface, Exceptions , Collections Framework

More Java: Static and Final, Abstract Class and Interface, Exceptions , Collections Framework . Abstract class and interface. Abstract class : Declaration omitting implementation Interface : a "contract" that spells out how software interacts .

brone
Télécharger la présentation

More Java: Static and Final, Abstract Class and Interface, Exceptions , Collections Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework CS300

  2. Abstract class and interface • Abstract class: Declaration omitting implementation • Interface: a "contract" that spells out how software interacts. • Example: sort contacts on your phone based on e-mail addresses CS300

  3. Java vsC#: Classes / Interfaces CS300

  4. Java vsC#: Classes / Interfaces CS300

  5. Static and Final • Final declaration cannot be changed • Classes, methods, fields, parameters and local variables can be final • Static: belongs to the class in which it is described, not an instance of a class • Example: • Download QuietStatic.java and LoudStatic.java • Create StaticClientfor QuietStatic where you increment class member and instance member • Fill in LoudStatic CS300

  6. Exceptions • Handle unusual conditions CS300

  7. Java vsC#: Exception Handling CS300

  8. Collection framework • One of the most powerful and convenient tools of Java • java.util package: http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html CS300

  9. Collection interface types • Collection: root type. Group of objects, not necessarily ordered, not necessarily addressable, possibly containing duplicates. You can: • Add/remove things from it • Get its size • Iterate over it CS300

  10. Collection interface types • List: ordered collection, index from 0 to length -1. May contain duplicates. You can: • Add/remove things from it • Get its size • Iterate over it • Map an element to its index • Map an index to an element • Change an element at a specific index CS300

  11. Collection interface types • Set: unordered collection. Does not contain duplicates. You can: • Add/remove things from it • Get its size • Iterate over it • Map: like a list. Instead of mapping a collection of objects to integer indexes, it maps them to a set of key objects • Examples:mapping of words to their definitions, dates to events, or URLs to cached content CS300

  12. Collection interface types • What you can do with a Map: • Add/remove things from it • Get its size • Iterate over it • Map an element to its key • Map keyto an element • Change an element at a specific key CS300

  13. Collection interface types • Iterator: Returns elements from a collection from which it is derived, exactly once, in response to calls to its next method. CS300

  14. Collection implementation types • ArrayList: list implemented by an array. • Quick to index • Slow to change size • LinkedList: list that can change size quickly but it is slower to index. CS300

  15. Collection implementation types • HashSet: set that is implemented as a hash.add, remove, contains, and size all execute at constant time assuming well behaved hash. May contain no more than one null. • HashMap: implementation of Map that uses hash table as its index. add, remove, contains, and size all execute at constant time assuming well behaved hash. May contain a single null key but any number of values may be null. CS300

  16. Collection implementation types • TreeMap: orderedMap, objects in the map are sorted according to their natural order, or according to Comparator. CS300

  17. Java Generics CS300

  18. References • Programming Android by ZigurdMednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura • Exceptions http://docs.oracle.com/javase/6/docs/api/java/lang/Exception.html CS300

More Related