Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
CS 106 Introduction to Computer Science I 04 / 27 / 2007 Instructor: Michael Eckmann.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 7 Object Oriented Programming in Java Advanced Topics Collection.
15-Jun-15 Lists in Java Part of the Collections Framework.
Professor Evan Korth (adapted from Sun’s collections documentation)
Chapter 2 Data Design and Implementation. Homework You should have already read section 2.2 You should have already read section 2.2 Read Section 2.3.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
12-Jul-15 Lists in Java Part of the Collections Framework.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
1 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
Java's Collection Framework
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
Information and Computer Sciences University of Hawaii, Manoa
111 © 2002, Cisco Systems, Inc. All rights reserved.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
CS 106 Introduction to Computer Science I 04 / 25 / 2008 Instructor: Michael Eckmann.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
CS Ananda Gunawardena.  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 1 ArrayLists Section 9.9.
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
List data type(ADT). Lists Elements : a 1,a 2,a 3,… a i-1,a i, a i+1,…a n Null List contains: 0 elements Types of Operations on list 1.Insertion 2.Deletion.
CS-2852 Data Structures LECTURE 2 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Collections Dwight Deugo Nesa Matic
Object Oriented Programming in Java Habib Rostami Lecture 7.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
CS 151: Object-Oriented Design December 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
1 CS162: Introduction to Computer Science II Abstract Data Types.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Data Structures Lakshmish Ramaswamy.
Implementing ArrayList Part 1
Introduction to Collections
TCSS 143, Autumn 2004 Lecture Notes
JAVA Collections Framework Set Interfaces & Implementations
Programming in Java Lecture 11: ArrayList
Introduction to Collections
Collections in Java The objectives of this lecture are:
Introduction to Collections
ArrayLists 22-Feb-19.
Collections Framework
Introduction to Collections
Introduction to Data Structure
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Part of the Collections Framework
Java Generics & Iterators
Presentation transcript:

Data Design and Implementation

Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items - e.g, an int or a float variable Composite type : A data type whose elements are composed of multiple data items e.g. A CLASS 2

Structured composite type  Structured composite type:  An organized collection of components. The organization determines how to access the components of the collection  E.g. An Array or A Tree 3

Atomic (Simple) and Composite Data Types 4

Java’s Built-In Types 5

The Java Class Construct composite, unstructured data types.  is used to create composite, unstructured data types.  It is composed of :  1. named data fields ( instance variables) 2. methods. 2. methods. 6

An array differs from a class :  An array is a homogenous structure, whereas classes are heterogeneous structures. E.g. an array of integers has only integers in it. A class has variables of different types and methods  7

Accessing components  A component of an array is accessed by its position in the array e.g. board[2] [3] 8

Arrays  Because array components are accessed by position,  an array is a structured composite type. 9

Component of square:  A component of a class is accessed by an identifier (the object created of it).  Square sq = new Square(10,20, 40, Color.Red);  int x = sq.getX();  We access the parts of the class with an object 10

11  Because class components are accessed by creating an object,  an class is a unstructured composite type.

Definitions Data abstraction: The separation of a data type’s logical properties from its implementation  A doctor sees (abstracts) the person as patient. E.g. name, height, weight of a person  An employer sees (abstracts) a person as Employee. E.g.name, age, health, degree of study, of a person. 12

Data encapsulation  We can abstract the important characteristics of Person  and store all the characteristics of a person in Person class  The Person class can be used by both the Doctor or Employer classes or ……..others 13

Abstract Data Type  An abstract data type is an interface  a) it defines a collection of data e.g. an array of clients  b)and the particular operations that are allowed on that array  ( through methods ) 14

15 An ADT :  therefore has a name E.G. A STACK, A QUEUE, An ARRAYLIST  A domain of values(data) - the elements in the stack, items stored in the array in the ArrayList  a set of operations that can be performed (methods) on the data ABSTRACT DATA TYPES – ADT’ s

Collections- Details  A collection is an object that serves as a repository for other objects.  MOST ADT are Collections - since they store the data they are operating on  The Java Collections Framework contains classes that represent collections of objects. 16

Collections & ADT’s  In general, a collection refers to a class whose role is to: provide methods to add, remove and  provide methods to add, remove and  manage the elements that are in the collection. 17

Collections - ArrayList  The ArrayList class in the Collections Framework is implemented with an array.  There is also a SortedArrayList, which maintains the array in sorted order 18

Collections & ADT’s  Collections can be implemented in a variety of ways. Array  The ArrayList uses an Array methods and contains methods that perform operations on array. e.g. Adding or deleting items etc. 19

ADT’s  ADT’s can be implemented with both e.g. arrays or linked lists.  The choice of an array or a linked list depends upon the implementation 20

The ArrayList Class  IS Part of the java.util package.  An ArrayList list can grow and shrink depending on need.  When the array is full, its size is doubled 21

ARRAYLIST  ArrayList class: you store variables of type Object.  Or now type T - a generic type built on class Object  22

ArrayList  An ArrayList has a size() method - how many objects it is currently holding  It has other methods :  add, remove, find, isEmpty etc. See:  /util/ArrayList.html /util/ArrayList.html 23

ArrayList Operations 24

Use Arraylist – unsorted - when:  The amount of space required may change from one execution of the program to the next.  The position of an element in the array list has no relevance to the application.  There is no order to the items stored 25

26 Collection Interface & Map Interface

27 LIST & SET INTERFACEs

28

 public interface List extends Collection  {  E get(int index);  E set(int index, E element);  boolean add(E element);  void add(int index, E element);  E remove(int index);  boolean addAll(int index, Collection c);  int indexOf(Object o);  int lastIndexOf(Object o);  ListIterator listIterator(); ListIterator listIterator(int index); } 29

Collection Interface-List inherits these methods  public interface Collection extends Iterable {  int size();  boolean isEmpty();  boolean contains(Object element);  boolean add(E element);  boolean remove(Object element);  Iterator iterator();  boolean containsAll(Collection c);  boolean addAll(Collection c);  boolean removeAll(Collection c);  boolean retainAll(Collection c);  void clear();  public T[] toArray(T[] a); 30

Designing ADTs this term  Determine the general purpose of your program. application program performs.  List the specific types of operations the application program performs. 31

DESIGNING AN ADT  Decide first which ADT to use:  an ArrayList, A Stack? Depends on the problem  Identify a set of public methods to be provided by the ADT class to perform the desired operations 32

Designing ADTs  Identify potential error situations and classify into 1. Those that are handled by throwing an exception 2. Those that are ignored. 33

Designing ADTs 6. Define the needed exception classes. 7. Decide on a protection level for the identified data. 8. Implement the ADT. ( Using the ARRAYLIST OR STACK 9. Create a test driver and test your ADT. 34

35 Analysis of List Implementations In both array and linked implementations, many operations are similar in efficiency Most are O(1), except when shifting or searching occurs, in which case they are order O(n) except when shifting or searching occurs, in which case they are order O(n)