What is an Interface? 4 Common in everyday life. –Movie theaters, TVs, VCRs, etc. 4 Java interface definitions are simple: –Method headers. –Field definitions.

Slides:



Advertisements
Similar presentations
Chapter 23 Organizing list implementations. This chapter discusses n The notion of an iterator. n The standard Java library interface Collection, and.
Advertisements

Introduction to Computation and Problem
Java Programming: Advanced Topics 1 Collections and Utilities.
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
Double-Linked Lists and Circular Lists
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
CS18000: Problem Solving and Object-Oriented Programming.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
Exercise 1 Suppose C is a class that implements interfaces I and J. Which of the following Requires a type cast? C c = ……? I i = …..? J j = …..? c =
OOP with Java, David J. Barnes Interfaces1 A set of features offered by a class. Often offered by more than one class. –Iterator : Returned by the iterator.
Bag implementation Add(T item) – Enlarge bag if necessary; allocate larger array Remove(T item) – Reduce bag if necessary; allocate smaller array Iterator.
Lists and Iterators CSC311: Data Structures 1 Chapter 6 Lists and Iterators Objectives Array Lists and Vectors: ADT and Implementation Node Lists: ADT.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
1 Lecture 24 ADT Part V (Linked List Using Iterator) Overview  Utility Classes.  List Iterator.  View of the List Iterator.  Adding to the Head of.
1 The Collection Interface public interface Collection extends Iterable { boolean add(E e); boolean addAll(Collection c); void clear(); boolean contains(Object.
CS 280 Data Structures Professor John Peterson. Project 9 Questions? IS280.
1 Collections Working with More than One Number or Data Type or Object.
Tirgul OOP No.3 Iterators. What is an Iterator? An object that provides a way to access elements of an aggregate object sequentially, without exposing.
1 Topic 8 Iterators "First things first, but not necessarily in that order " -Dr. Who.
CS 307 Fundamentals of Computer ScienceIterators 1 Topic 14 Iterators "First things first, but not necessarily in that order " -Dr. Who.
Iterators CS 367 – Introduction to Data Structures.
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities Chapter 4.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
1 Lecture 09 Iterators and Enumerations Reading for these lectures: Weiss, Section Iterator Interface. Much better is: ProgramLive, Section 12.3.
Abstract and Nested Classes
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
EECE 310: Software Engineering Iteration Abstraction.
IMPLEMENTING ARRAYLIST – Part 2 COMP 103. RECAP  Abstract Classes – overview, details in 2 nd year  Implementing the ArrayList: size(), get(), set()
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
LinkedList Many slides from Horstmann modified by Dr V.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
1 Iterators "First things first, but not necessarily in that order " -Dr. Who CS Computer Science II.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 13 Implementing.
Using Iterators Trey Chandler Burlington Williams High School Mr. Langner’s Class,
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
Nested Classes CompSci 230 S Software Construction.
List Interface and Linked List Mrs. Furman March 25, 2010.
Iterators ITI 1121 N. El Kadri. Motivation Given a (singly) linked-list implementation of the interface List, defined as follows, public interface List.
Generic Programming and Inner classes ge·ner·ic 1a : relating or applied to or descriptive of all members of a genus, species, class, or group : common.
Iterators, Iterator, and Iterable 2015-T2 Lecture 8 School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Thomas Kuehne.
Iterator Pattern. Traversing two different collections  When bringing two previously developed objects together, it can be difficult to change an implementation.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
Data Structures I Collection, List, ArrayList, LinkedList, Iterator, ListNode.
CS 46B: Introduction to Data Structures July 21 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Collections Dwight Deugo Nesa Matic
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Iterators. Iterator  An iterator is any object that allows one to step through each element in a list (or, more generally, some collection).
1 Iterators & the Collection Classes. 2 » The Collection Framework classes provided in the JAVA API(Application Programmer Interface) contains many type.
CompSci 230 S Software Construction
University of Central Florida COP 3330 Object Oriented Programming
Data Structures Lakshmish Ramaswamy.
"First things first, but not necessarily in that order " -Dr. Who
null, true, and false are also reserved.
CSE 143 Lecture 27: Advanced List Implementation
Recursion B.Ramamurthy 2/23/2019 Ramamurthy.
"First things first, but not necessarily in that order " -Dr. Who
slides created by Alyssa Harding
CSC 205 – Java Programming II
Java Generics & Iterators
Presentation transcript:

What is an Interface? 4 Common in everyday life. –Movie theaters, TVs, VCRs, etc. 4 Java interface definitions are simple: –Method headers. –Field definitions ( public static final ).

An Interface Definition interface VCR { public boolean loadTape(String tapeName); public boolean eject(); public boolean play(); public boolean pause(); public boolean stop(); public boolean ff(); public boolean rew(); public int getStatus(); public static final int PLAYING = 0, PAUSED = 1, STOPPED = 2, FORWARD = 3, BACKWARD = 4, NOTAPE = 5; }

Implementing an Interface class PanasonicVCR implements VCR {... public boolean eject(){ if(getStatus() != NOTAPE){ setStatus(NOTAPE); return true; } else{ return false; }... }

The Iterator interface public interface Iterator { public boolean hasNext(); public Object next() throws NoSuchElementException; } LinkedList public ListIterator listIterator(int index) ListIteratorlistIterator Iterator it = l.listIterator(0); while (it.hasNext()){ Object elm = it.next(); … }

The Enumeration Interface public interface Enumeration { public boolean hasMoreElements(); public Object nextElement() throws NoSuchElementException; } Hashtable public Enumeration elements()Enumeration public Enumeration keys()Enumeration

Packages 4 What is a package? –A package is an encapsulation of classes possibly stored in multiple files. 4 Why packages? –Provide another level of modularity –Provide another level of protection

Defining and Using Packages 4 Defining packages 4 Using packages 4 Managing Java source and class files package packageName; import packageName.ClassName; import packageName.*;