Estrutura com iterador-1
|
|
- Andra Bryant
- 7 years ago
- Views:
Transcription
1 Estrutura com iterador-1 public class MyContainer Object [ ] items; int size; public Object get( int idx )... public boolean add( Object x )... public MyContainerIterator iterator( ) return new MyContainerIterator(this); public class MyContainerIterator private int current = 0; private MyContainer container; MyContainerIterator(MyContainer c) container = c; public boolean hasnext( ) return current < container.size; public Object next( ) return container.items[ current++ ]; Estrutura com iterador-2 public class MyContainer private Object [ ] items = new Object[ 5 ]; private int size = 0; public Iterator iterator( ) return new MyContainerIterator(this); public interface Iterator boolean hasnext(); Object next(); class MyContainerIterator implements Iterator private int current = 0; private MyContainer container; MyContainerIterator(MyContainer c) container = c; public boolean hasnext( ) return current < container.size; public Object next( ) return container.items[ current++ ]; -1
2 Estrutura com iterador-3 package weiss.ds; public class MyContainer private Object [ ] items = new Object[ 5 ]; private int size = 0; //... public Iterator iterator( ) return new LocalIterator(this); private static class LocalIterator implements Iterator private int current = 0; private MyContainer container; private LocalIterator( MyContainer c) container = c; public boolean hasnext( ) return current < container.size; public Object next( ) return container.items[ current++ ]; Estrutura com iterador-4 package weiss.ds; public class MyContainer private Object [ ] items = new Object[ 5 ]; private int size = 0; public Object get( int idx )... public boolean add( Object x )... public Iterator iterator( ) return new LocalIterator( ); private class LocalIterator implements Iterator private int current = 0; public boolean hasnext( ) return current < size; public Object next( ) return items[ current++ ]; -2
3 Iteradores Solução 1 Classes públicas para iterador e contentor Referência do iterador no contentor Iterador partilha dados do contentor Utilizador do contentor tem de definir iterador adequado Solução 2 Contentor devolve iterador genérico, programador usa interface Iterator iterator() é fábrica que produz iterador cujo tipo fica escondido do utilizador Solução 3 Classe do iterador é nested class no contentor Evita partilha de dados no package Iterador é objecto independente construído com referência ao contentor Solução 4 Classe do iterador é inner class do contentor Iterador está implicitamente associado ao contentor, e refere directamente os seus membros package weiss.util; public abstract class implements Collection * Tests if this collection is empty. public boolean isempty( ) return size( ) == 0; * Change the size of this collection to zero. public void clear( ) Iterator itr = iterator( ); while( itr.hasnext( ) ) itr.next( ); itr.remove( ); -3
4 * Obtains a primitive array view of the collection. the primitive array view. public Object [ ] toarray( ) Object [ ] copy = new Object[ size( ) ]; Iterator itr = iterator( ); int i = 0; while( itr.hasnext( ) ) copy[ i++ ] = itr.next( ); return copy; * Returns true if this collection contains x. * If x is null, returns false. * (This behavior may not always be appropriate.) x the item to search for. true if x is not null and is found in * this collection. public boolean contains( Object x ) if( x == null ) Iterator itr = iterator( ); while( itr.hasnext( ) ) if( x.equals( itr.next( ) ) ) return true; -4
5 * Removes non-null x from this collection. * (This behavior may not always be appropriate.) x the item to remove. true if remove succeeds. public boolean remove( Object x ) if( x == null ) Iterator itr = iterator( ); while( itr.hasnext( ) ) if( x.equals( itr.next( ) ) ) itr.remove( ); return true; * Return true if items in other collection * are equal to items in this collection * (same order, and same according to equals). public final boolean equals( Object other ) if( other == this ) return true; if(! ( other instanceof Collection ) ) Collection rhs = (Collection) other; if( size( )!= rhs.size( ) ) Iterator lhsitr = this.iterator( ); Iterator rhsitr = rhs.iterator( ); while( lhsitr.hasnext( ) ) if(!isequal( lhsitr.next( ), rhsitr.next( ) ) ) return true; -5
6 * Return the hashcode. public final int hashcode( ) int hashval = 1; Iterator itr = iterator( ); ); while( itr.hasnext( ) ) Object obj = itr.next( ); hashval = 31 * hashval + ( obj == null? 0 : obj.hashcode( ) return hashval; * Return true if two objects are equal; works * if objects can be null. private boolean isequal( Object lhs, Object rhs ) if( lhs == null ) return rhs == null; return lhs.equals( rhs ); -6
7 package weiss.util; public class extends implements List private static final int DEFAULT_CAPACITY = 10; private static final int NOT_FOUND = -1; private Object [ ] theitems; private int thesize; private int modcount = 0; * Construct an empty. public ( ) clear( ); * Construct an with same items as another Collection. public ( Collection other ) clear( ); Iterator itr = other.iterator( ); while( itr.hasnext( ) ) add( itr.next( ) ); -7
8 * Returns the number of items in this collection. public int size( ) return thesize; * Returns the item at position idx. idx the index to search in. ArrayIndexOutOfBoundsException if index is out of range. public Object get( int idx ) if( idx < 0 idx >= size( ) ) throw new ArrayIndexOutOfBoundsException( "Index " + idx + "; size " + size( ) ); return theitems[ idx ]; * Changes the item at position idx. public Object set( int idx, Object newval ) if( idx < 0 idx >= size( ) ) throw new ArrayIndexOutOfBoundsException( "Index " + idx + "; size " + size( ) ); Object old = theitems[ idx ]; theitems[ idx ] = newval; return old; * Tests if some item is in this collection. public boolean contains( Object x ) return findpos( x )!= NOT_FOUND; -8
9 * Returns the position of first item matching x in this collection, * or NOT_FOUND if not found. private int findpos( Object x ) for( int i = 0; i < size( ); i++ ) if( x == null ) if( theitems[ i ] == null ) return i; else if( x.equals( theitems[ i ] ) ) return i; return NOT_FOUND; * Adds an item to this collection, at the end. x any object. true. public boolean add( Object x ) if( theitems.length == size( ) ) Object [ ] old = theitems; theitems = new Object[ theitems.length * ]; for( int i = 0; i < size( ); i++ ) theitems[ i ] = old[ i ]; theitems[ thesize++ ] = x; modcount++; return true; -9
10 * Removes an item from this collection. public boolean remove( Object x ) int pos = findpos( x ); if( pos == NOT_FOUND ) else remove( pos ); return true; * Removes an item from this collection. public Object remove( int idx ) Object removeditem = theitems[ idx ]; for( int i = idx; i < size( ) - 1; i++ ) theitems[ i ] = theitems[ i + 1 ]; thesize--; modcount++; return removeditem; -10
11 * Change the size of this collection to zero. public void clear( ) thesize = 0; theitems = new Object[ DEFAULT_CAPACITY ]; modcount++; * Obtains an Iterator object used to traverse the collection. an iterator positioned prior to the first element. public Iterator iterator( ) return new Iterator( 0 ); * Obtains a ListIterator object used to traverse the collection bidirectionally. an iterator positioned prior to the requested element. idx the index to start the iterator. Use size() to do complete * reverse traversal. Use 0 to do complete forward traversal. IndexOutOfBoundsException if idx is not between 0 and size(), inclusive. public ListIterator listiterator( int idx ) return new Iterator( idx ); -11
12 Iterator * This is the implementation of the Iterator. * It maintains a notion of a current position and of * course the implicit reference to the. private class Iterator implements ListIterator private int current; private int expectedmodcount = modcount; private boolean nextcompleted = false; private boolean prevcompleted = false; Iterator( int pos ) if( pos < 0 pos > size( ) ) throw new IndexOutOfBoundsException( ); current = pos; Iterator public boolean hasnext( ) if( expectedmodcount!= modcount ) throw new ConcurrentModificationException( ); return current < size( ); public boolean hasprevious( ) if( expectedmodcount!= modcount ) throw new ConcurrentModificationException( ); return current > 0; public Object next( ) if(!hasnext( ) ) throw new NoSuchElementException( ); nextcompleted = true; prevcompleted = false; return theitems[ current++ ]; -12
13 Iterator public Object previous( ) if(!hasprevious( ) ) throw new NoSuchElementException( ); prevcompleted = true; nextcompleted = false; return theitems[ --current ]; public void remove( ) if( expectedmodcount!= modcount ) throw new ConcurrentModificationException( ); if( nextcompleted ).this.remove( --current ); else if( prevcompleted ).this.remove( current ); else throw new IllegalStateException( ); prevcompleted = nextcompleted = false; expectedmodcount++; -13
Class 32: The Java Collections Framework
Introduction to Computation and Problem Solving Class 32: The Java Collections Framework Prof. Steven R. Lerman and Dr. V. Judson Harward Goals To introduce you to the data structure classes that come
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2016S-05 Abstract Data Types and Lists David Galles Department of Computer Science University of San Francisco 05-0: Abstract Data Types Recall that an Abstract Data
More informationData Structures and Algorithms Lists
Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 5-0: Abstract Data Types An
More informationIntroduction to Stacks
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack. What is a Stack? Stack is a data structure in which data is added
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch20 Data Structures I PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
More informationObject-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
More informationAP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
More informationA binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
More informationAPI for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.
Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing
More informationCollections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),
Arrays Has special language support Iterators Collections in Java Iterator (i) Collections (also called containers) Collection (i) Set (i), HashSet (c), TreeSet (c) List (i), ArrayList (c), LinkedList
More informationSoftware Engineering II. Java 2 Collections. Bartosz Walter <Bartek.Walter@man.poznan.pl>
Software Engineering II Java 2 Collections Bartosz Walter Agenda 1. Basic interfaces: Collection, Set, List, Map 2. Iterators 3. Utility classes for Collections and Arrays
More informationSoftware Development with UML and Java 2 SDJ I2, Spring 2010
Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda week 7, 2010 Pakages Looking back Looking forward Packages Interfaces Page 1 Spring 2010 Download, Install/Setup 1. Java SE SDK (http://java.sun.com/javase/downloads)
More informationQueues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!
More informationGeneric Types in Java. Example. Another Example. Type Casting. An Aside: Autoboxing 4/16/2013 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK.
Generic Types in Java 2 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK Lecture 15 CS2110 Spring 2013 When using a collection (e.g., LinkedList, HashSet, HashMap), we generally have a single type T of
More informationAnalysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
More informationpublic class Autenticador { private static final ThreadLocal<UsuarioInterface> threadusuario = new ThreadLocal<UsuarioInterface>();
JBook Shadowing - Oracle Source folder: src/main/java Main package: br.com.infowaypi.jbook. Actual package: autenticacao Java file: Autenticador.java package br.com.infowaypi.jbook.autenticacao; public
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More information1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: 15.1-15.3. Data Structures
1.00 Lecture 35 Data Structures: Introduction Stacks, Queues Reading for next time: Big Java: 15.1-15.3 Data Structures Set of reusable classes used in algorithms, simulations, operating systems, applications
More informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationDatastrukturer och standardalgoritmer i Java
1 (8) Datastrukturer och standardalgoritmer i Java Dokumentet listar ett urval av konstruktorer och metoder för några vanliga Javaklasser. Class ArrayList ArrayList() Constructs an empty list. void
More informationJAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
More informationProgramming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
More informationUIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
More informationCollections and iterators
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0 Concepts covered so far Abstraction Modularization Classes define types Class and object diagrams
More informationCS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
More informationCompSci-61B, Data Structures Final Exam
Your Name: CompSci-61B, Data Structures Final Exam Your 8-digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings.
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is
More informationLINEAR INEQUALITIES. less than, < 2x + 5 x 3 less than or equal to, greater than, > 3x 2 x 6 greater than or equal to,
LINEAR INEQUALITIES When we use the equal sign in an equation we are stating that both sides of the equation are equal to each other. In an inequality, we are stating that both sides of the equation are
More informationBinary Search Trees (BST)
Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search
More informationWorking with Java Collections
Working with Java Collections Java 2 Collections Lists - linear, supporting many operations Sets - unordered, unique items Sorted sets - like sets, but items can be visited in sorted order Java 2 Collections
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationCircular Linked List. Algorithms and Data Structures
Circular Linked List EENG212 Algorithms and Data Structures Circular Linked Lists In linear linked lists if a list is traversed (all the elements visited) an external pointer to the listmust be preserved
More informationCpt S 223. School of EECS, WSU
Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,
More informationJava Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More informationProgramming with Data Structures
Programming with Data Structures CMPSCI 187 Spring 2016 Please find a seat Try to sit close to the center (the room will be pretty full!) Turn off or silence your mobile phone Turn off your other internet-enabled
More informationFirst Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
More informationException Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1
Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance
More informationData Structures in the Java API
Data Structures in the Java API Vector From the java.util package. Vectors can resize themselves dynamically. Inserting elements into a Vector whose current size is less than its capacity is a relatively
More informationThe Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
More informationThe Interface Concept
Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()
More informationChapter 8: Bags and Sets
Chapter 8: Bags and Sets In the stack and the queue abstractions, the order that elements are placed into the container is important, because the order elements are removed is related to the order in which
More informationAlgorithms and Data Structures Written Exam Proposed SOLUTION
Algorithms and Data Structures Written Exam Proposed SOLUTION 2005-01-07 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are
More informationCourse: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
More informationWhat is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
More informationRecursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.
Recursion Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive. Why recursion? o For many problems, the recursion solution is more natural than the alternative
More informationIterators. Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation.
Iterators Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation when to use it - to access an aggregate object's contents without exposing
More informationOutline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson
Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications Array-Based Linked List-Based 4 Additional Information Mike Jacobson (University
More informationLoops and ArrayLists
Chapter 6 Loops and ArrayLists What is in this Chapter? When programming, it is often necessary to repeat a selected portion of code a specific number of times, or until some condition occurs. We will
More information6. Control Structures
- 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,
More informationPrinciples of Software Construction: Objects, Design and Concurrency. Java Collections. toad 15-214. Fall 2013
Principles of Software Construction: Objects, Design and Concurrency Java Collections toad 15-214 Fall 2013 Jonathan Aldrich Charlie Garrod School of Computer Science 2012-13 C Garrod, J Aldrich, and W
More informationOrdered Lists and Binary Trees
Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:
More informationProf. Edwar Saliba Júnior
package Conexao; 2 3 /** 4 * 5 * @author Cynthia Lopes 6 * @author Edwar Saliba Júnior 7 */ 8 import java.io.filenotfoundexception; 9 import java.io.ioexception; 10 import java.sql.sqlexception; 11 import
More informationTypeScript for C# developers. Making JavaScript manageable
TypeScript for C# developers Making JavaScript manageable Agenda What is TypeScript OO in TypeScript Closure Generics Iterators Asynchronous programming Modularisation Debugging TypeScript 2 What is TypeScript
More informationJAVA Program For Processing SMS Messages
JAVA Program For Processing SMS Messages Krishna Akkulu The paper describes the Java program implemented for the MultiModem GPRS wireless modem. The MultiModem offers standards-based quad-band GSM/GPRS
More informationCompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement
CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationObject Oriented Software Design
Object Oriented Software Design Inner classes, RTTI, Tree implementation Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 29, 2010 G. Lipari (Scuola Superiore Sant
More informationDATA STRUCTURE - STACK
DATA STRUCTURE - STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationThe Java Collections Framework
The Java Collections Framework Definition Set of interfaces, abstract and concrete classes that define common abstract data types in Java e.g. list, stack, queue, set, map Part of the java.util package
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationPractical Session 4 Java Collections
Practical Session 4 Java Collections Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack The Collections class Wrapper classes Collection A group
More informationStack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
More informationCOSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19
Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4
More informationClasses and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
More informationIteration CHAPTER 6. Topic Summary
CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many
More informationO que há de novo no C# 4.0 e no Visual Basic 10
O que há de novo no C# 4.0 e no Visual Basic 10 Agnaldo Diogo dos Santos MCT, MCPD, 4 MCITP, 5 MCTS, MCSE, MCDBA, MCSD, MCP, SCJP 50minutos.com.br/blog agnaldo@50minutos.com.br @50minutos Essência x Formalismo
More informationChapter 13 - Inheritance
Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package
More informationJavaScript: Control Statements I
1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can
More informationOverview. What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test?
Testing CMSC 202 Overview What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test? 2 What is Software Testing? Software testing is any activity aimed at evaluating
More informationStacks and queues. Algorithms and Data Structures, Fall 2011. Rasmus Pagh. Based on slides by Kevin Wayne, Princeton
Algorithms and Data Structures, Fall 2011 Stacks and queues Rasmus Pagh Based on slides by Kevin Wayne, Princeton Algorithms, 4 th Edition Robert Sedgewick and Kevin Wayne Copyright 2002 2011 Stacks and
More informationJava Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types
Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts
More informationCSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris
CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris 1 Collections - Set What is a Set? A Set is an unordered sequence of data with no duplicates Not like a List where you
More informationSoftware Testing. Jeffrey Carver University of Alabama. April 7, 2016
Software Testing Jeffrey Carver University of Alabama April 7, 2016 Warm-up Exercise Software testing Graphs Control-flow testing Data-flow testing Input space testing Test-driven development Introduction
More informationContinuous Integration Part 2
1 Continuous Integration Part 2 This blog post is a follow up to my blog post Continuous Integration (CI), in which I described how to execute test cases in Code Tester (CT) in a CI environment. What I
More informationThis loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10
Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution
More informationRecursion and Recursive Backtracking
Recursion and Recursive Backtracking Computer Science E-119 Harvard Extension School Fall 01 David G. Sullivan, Ph.D. Iteration When we encounter a problem that requires repetition, we often use iteration
More informationPart 3: GridWorld Classes and Interfaces
GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement
More informationHash Tables. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited
Hash Tables Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited We ve considered several data structures that allow us to store and search for data
More informationUNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 61B Fall 2014 P. N. Hilfinger Unit Testing with JUnit 1 The Basics JUnit is a testing framework
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationA Grammar for the C- Programming Language (Version S16) March 12, 2016
A Grammar for the C- Programming Language (Version S16) 1 Introduction March 12, 2016 This is a grammar for this semester s C- programming language. This language is very similar to C and has a lot of
More informationJava Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
More informationLecture 2 Notes: Flow of Control
6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The
More informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationIntroduction to Programming (in C++) Sorting. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC
Introduction to Programming (in C++) Sorting Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Sorting Let elem be a type with a operation, which is a total order A vector
More informationMassachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 1 October 14, 2011. Instructions
Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 1 October 14, 2011 Name: Athena* User Name: Instructions This quiz is 50 minutes long. It contains 1 pages
More informationSection IV.1: Recursive Algorithms and Recursion Trees
Section IV.1: Recursive Algorithms and Recursion Trees Definition IV.1.1: A recursive algorithm is an algorithm that solves a problem by (1) reducing it to an instance of the same problem with smaller
More informationWhat is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation
Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in Last-In In-First-Out (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria
More information12-6 Write a recursive definition of a valid Java identifier (see chapter 2).
CHAPTER 12 Recursion Recursion is a powerful programming technique that is often difficult for students to understand. The challenge is explaining recursion in a way that is already natural to the student.
More informationC++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
More informationUnit 6. Loop statements
Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now
More informationJava Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
More informationJDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
More informationGrundlæggende Programmering IT-C, Forår 2001. Model solutions to. Written exam in Introductory Programming
Question 1 Question 1.1 The program prints the following four lines: 8 14 18 2 Question 1.2 The program prints the following six lines: 2 7 16 Question 1.3 The problem is solved using two for-loops: static
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch15 Exception Handling PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
More informationTopic 11 Scanner object, conditional execution
Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright
More informationSmallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces.
OBJECTIVES OF JAVA Objects in java cannot contain other objects; they can only have references to other objects. Deletion of objects will be managed by Run time system. An Object can pass a message to
More informationJava Collection Framework hierarchy. What is Data Structure? Chapter 20 Lists, Stacks, Queues, and Priority Queues
Chapter 20 Lists, Stacks, Queues, and Priority Queues Objectives q To explore the relationship between interfaces and classes in the Java Collections Framework hierarchy ( 20.2). q To use the common methods
More information