Principles of Software Construction: Objects, Design and Concurrency. Java Collections. toad Fall 2013
|
|
|
- Kelly Pope
- 9 years ago
- Views:
Transcription
1 Principles of Software Construction: Objects, Design and Concurrency Java Collections toad Fall 2013 Jonathan Aldrich Charlie Garrod School of Computer Science C Garrod, J Aldrich, and W Scherlis
2 Administrivia Midterm exam in class next Tuesday, 15 Oct Midterm review session Sunday 1 3 p.m., Hamburg Hall 1000 Review sheet will be released before the review session Will also release a sample midterm exam soon 2
3 Key concepts from Tuesday 3
4 Key concepts from Tuesday GUIs The Model-View-Controller pattern The Observer pattern Java Swing architecture Threading architecture Swing components Using the Observer pattern in Swing 4
5 Design patterns we have seen so far: Composite Template Method Strategy Observer Model-View-Controller Decorator 5
6 Key concepts for today A tour of the Java Collections Framework Some of the features Some of the common usage patterns Some of the design patterns in use Iterator, Marker Interface, Factory Method, Adapter, Strategy, Decorator, Template Method 6
7 The philosophy of the Collections framework Powerful and general Small in size and conceptual weight Only include fundamental operations "Fun and easy to learn and use" 7
8 The java.util.collection<e> interface boolean add(e e);! boolean addall(collection<e> c);! boolean remove(e e);! boolean removeall(collection<e> c);! boolean retainall(collection<e> c);! boolean contains(e e);! boolean containsall(collection<e> c);! void clear();! int size();! boolean isempty();! Iterator<E> iterator();! Object[] toarray()! E[] toarray(e[] a);!! 8
9 The java.util.list<e> interface Defines order of a collection Extends java.util.collection<e>: boolean add(int index, E e);! E get(int index);! E set(int index, E e);! int indexof(e e);! int lastindexof(e e);! List<E> sublist(int fromindex, int toindex);! 9
10 The java.util.set<e> interface Enforces uniqueness of each element in collection Extends java.util.collection<e>: Aside: The Marker Interface pattern Problem: You want to define a behavioral constraint not enforced at compile time. Solution: Define an interface with no methods. 10
11 The java.util.queue<e> interface Extends java.util.collection<e>: boolean add(e e); // These three methods! E remove(); // might throw exceptions! E element();!! boolean offer(e e);! E poll(); // These two methods! E peek(); // might return null! 11
12 The java.util.map<k,v> interface Does not extend java.util.collection<e> V put(k key, V value);! V get(object key);! V remove(object key);! boolean containskey(object key);! boolean containsvalue(object value);! void putall(map<k,v> m);! int size();! boolean isempty();! void clear();! Set<K> keyset();! Collection<V> values(); Set<Map.Entry<K,V>> entryset();! 12
13 One problem: Java arrays are not Collections To convert a Collection to an array Use the toarray method List<String> arguments = new LinkedList<String>();! // puts something into the list! String[] arr = (String[]) arguments.toarray();! String[] brr = arguments.toarray(new String[0]); To view an array as a Collection Use the java.util.arrays.aslist method String[] arr = {"foo", "bar", "baz", "qux"};! List<String> arguments = Arrays.asList(arr);! 13
14 One problem: Java arrays are not Collections To convert a Collection to an array Use the toarray method List<String> arguments = new LinkedList<String>();! // puts something into the list! String[] arr = (String[]) arguments.toarray();! String[] brr = arguments.toarray(new String[0]); To view an array as a Collection Use the java.util.arrays.aslist method String[] arr = {"foo", "bar", "baz", "qux"};! List<String> arguments = Arrays.asList(arr);! Aside: The Adapter pattern Problem: Existing library or class does not match the interface you want Solution: Expose the functionality of the object in a different form! 14
15 What do you want to do with your Collection today? 15
16 Traversing a Collection Old-school Java for loop for ordered types List<String> arguments = ;! for (int i = 0; i < arguments.size(); ++i) {! System.out.println(arguments.get(i));! Modern standard Java for-each loop List<String> arguments = ;! for (String s : arguments) {! System.out.println(s);! } Use an Iterator 16
17 The Iterator pattern public interface java.util.iterator<e> {! boolean hasnext();! E next();! void remove(); // removes previous returned item! } // from the underlying collection! To use, e.g.: List<String> arguments = ;! for (Iterator<String> it = arguments.iterator();! it.hasnext(); ) {! String s = it.next();! System.out.println(s);! 17
18 Using a java.util.iterator<e> public interface Iterator<E> {! boolean hasnext();! E next();! void remove(); // removes previous returned item! } // from the underlying collection! To use to remove items, e.g.: List<String> arguments = ;! for (Iterator<String> it = arguments.iterator();! it.hasnext(); ) {! String s = it.next();! if (s.equals("charlie"))! it.remove();! // The next line will always print false! System.out.println(arguments.contains("Charlie"));!! 18
19 Using a java.util.iterator<e>: A warning The default Collections implementations are mutable The java.util.iterator assumes the Collection does not change while the Iterator is being used You will get a ConcurrentModificationException! List<String> arguments = ;! for (Iterator<String> it = arguments.iterator();! it.hasnext(); ) {! String s = it.next();! if (s.equals("charlie"))! arguments.remove("charlie"); // runtime error! 19
20 Aside: The Factory Method pattern public interface Collection<E> {! boolean add(e e);! boolean addall(collection<e> c);! boolean remove(e e);! boolean removeall(collection<e> c);! boolean retainall(collection<e> c);! boolean contains(e e);! boolean containsall(collection<e> c);! void clear();! int size();! Defines an interface for boolean isempty();! creating an Iterator, Iterator<E> iterator();! but allows Collection Object[] toarray()! implementation to decide E[] toarray(e[] a);! which Iterator to create. 20
21 Sorting a Collection Use the Collections.sort method: public static void main(string[] args) {! List<String> lst = Arrays.asList(args);! Collections.sort(lst);! for (String s : lst) {! System.out.println(s);! Abuse the SortedSet: public static void main(string[] args) {! SortedSet<String> set =! new TreeSet<String>(Arrays.asList(args));! for (String s : set) {! System.out.println(s);! 21
22 Sorting your own types of objects public interface Comparable<T> {! int compareto(t o);! General contracts: a.compareto(b) should return: <0 if a is less than b! 0 if a and b are equal >0 if a is greater than b! Should define a total order If a.compareto(b) < 0 and b.compareto(c) < 0, then a.compareto(c) should be < 0 If a.compareto(b) < 0, then b.compareto(a) should be > 0 Should usually be consistent with.equals! a.compareto(b) == 0 iff a.equals(b)! 22
23 Comparable objects an example public class Integer implements Comparable<Integer> {! private int val;! public Integer(int val) { this.val = val;! public int compareto(integer o) {! if (val < o.val) return -1;! if (val == o.val) return 0;! return 1;! } Aside: Why did I not just return val o.val? 23
24 Comparable objects another example! Make Name comparable:! public class Name {! private String first;! private String last;! public Name(String first, String last) { // should! this.first = first; this.last = last; // check! } // for null!!!!!! } Hint: Strings implement Comparable<String>! 24
25 Comparable objects another example! Make Name comparable:! public class Name implements Comparable<Name> {! private String first;! private String last;! public Name(String first, String last) { // should! this.first = first; this.last = last; // check! } // for null!! public int compareto(name o) {! int lastcomparison = last.compareto(o.last);! if (lastcomparison!= 0) return lastcomparison;! return first.compareto(o.first);! 25
26 Alternative comparisons public class Employee implements Comparable<Employee> {! protected Name name;! protected int salary;!! } What if we want to sort Employees by name, usually, but sometimes sort by salary? 26
27 Alternative comparisons public class Employee implements Comparable<Employee> {! protected Name name;! protected int salary;!! } What if we want to sort Employees by name, usually, but sometimes sort by salary? Answer: There's a Strategy pattern interface for that public interface Comparator<T> {! public int compare(t o1, T o2);! public boolean equals(object obj);! } 27
28 Writing a Comparator object public class Employee implements Comparable<Employee> {! protected Name name;! protected int salary;! public int compareto(employee o) {! return name.compareto(o.name);!! public class EmpSalComp implements Comparator<Employee> { public int compare (Employee o1, Employee o2) {! return o1.salary o2.salary; // Why is this OK?! public boolean equals(object obj) {! return obj instanceof EmpSalComp;! } 28
29 Using a Comparator Order-dependent classes and methods take a Comparator as an argument public class Main {! public static void main(string[] args) {! SortedSet<Employee> empbyname = // sorted by name! new TreeSet<Employee>();!! SortedSet<Employee> empbysal = // sorted by salary! new TreeSet<Employee>(new EmpSalComp());! 29
30 Aside: The java.util.sortedset<e> interface Extends java.util.set<e>: Comparator<E> comparator();! E first();! E last();! SortedSet<E> subset(e fromelement, E toelement);! SortedSet<E> headset(e toelement);! SortedSet<E> tailset(e fromelement); The comparator method returns null if the natural ordering is being used 30
31 The java.util.collections class Standard implementations of common algorithms binarysearch, copy, fill, frequency, indexofsublist, min, max, ncopies, replaceall, reverse, rotate, shuffle, sort, swap, public class Main() {! public static void main(string[] args) {! List<String> lst = Arrays.asList(args);! Collections.sort(lst);! for (String s : lst) {! System.out.println(s);! 31
32 The java.util.collections class Standard implementations of common algorithms binarysearch, copy, fill, frequency, indexofsublist, min, max, ncopies, replaceall, reverse, rotate, shuffle, sort, swap, public class Main() {! public static void main(string[] args) {! List<String> lst = Arrays.asList(args);! int x = Collections.frequency(lst, "Charlie");! System.out.println("There are " + x +! " students named Charlie");! 32
33 The java.util.collections class Many uses of the Decorator pattern: static List<T> unmodifiablelist(list<t> lst);! static Set<T> unmodifiableset( Set<T> set);! static Map<K,V> unmodifiablemap( Map<K,V> map);! static List<T> synchronizedlist(list<t> lst);! static Set<T> synchronizedset( Set<T> set);! static Map<K,V> synchronizedmap( Map<K,V> map);!.!.!. 33
34 The java.util.collections class An actual method declaration static int binarysearch(! List<? extends Comparable<? super T>> list,! T key);! An object of some type T to search for A List of objects of some type that has a compareto method that can take an object of type T as an argument 34
35 Java Collections as a framework You can write specialty collections Custom representations and algorithms Custom behavioral guarantees e.g., file-based storage JDK built-in algorithms would then be calling your collections code 35
36 The abstract java.util.abstractlist<t> abstract T get(int i); // Template Method.! abstract int size(); // Template Method.! boolean set(int i, E e); // set add remove are! boolean add(e e); // pseudo-abstract! boolean remove(e e); // Template Methods.! boolean addall(collection<e> c);! boolean removeall(collection<e> c);! boolean retainall(collection<e> c);! boolean contains(e e);! boolean containsall(collection<e> c);! void clear();! boolean isempty();! Iterator<E> iterator();! Object[] toarray()! E[] toarray(e[] a);!! 36
37 Next time Midterm exam on Tuesday 37
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
Collections 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
Generic 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
Practical 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
Data 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
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
The 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
CMSC 202H. ArrayList, Multidimensional Arrays
CMSC 202H ArrayList, Multidimensional Arrays What s an Array List ArrayList is a class in the standard Java libraries that can hold any type of object an object that can grow and shrink while your program
Object-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,
Data 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
Java 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
AP 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
CSE 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
http://algs4.cs.princeton.edu dictionary find definition word definition book index find relevant pages term list of page numbers
ROBERT SEDGEWICK KEVI WAYE F O U R T H E D I T I O ROBERT SEDGEWICK KEVI WAYE ROBERT SEDGEWICK KEVI WAYE Symbol tables Symbol table applications Key-value pair abstraction. Insert a value with specified.
CompSci-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.
First 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
Java 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
cs2010: algorithms and data structures
cs2010: algorithms and data structures Lecture 11: Symbol Table ADT. Vasileios Koutavas 28 Oct 2015 School of Computer Science and Statistics Trinity College Dublin Algorithms ROBERT SEDGEWICK KEVIN WAYNE
Software 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)
Per imparare a programmare bisogna programmare
Per imparare a programmare bisogna programmare Brian Kernighan Java collections framework Commonly reusable collection data structures Abstract Data Type ADTs store data and allow various operations on
A 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)
CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park
CMSC 132: Object-Oriented Programming II Design Patterns I Department of Computer Science University of Maryland, College Park Design Patterns Descriptions of reusable solutions to common software design
CS 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)
API 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
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad 15-214. Spring 2013
Principles of Software Construction: Objects, Design and Concurrency GUIs with Swing 15-214 toad Spring 2013 Christian Kästner Charlie Garrod School of Computer Science 2012-13 C Garrod, C Kästner, J Aldrich,
J 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
Java Map and Set collections
Java Map and Set collections Java Set container idea interface Java Map container idea interface iterator concordance example Java maps and sets [Bono] 1 Announcements Lab this week based on an example
CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions
CS 2112 Spring 2014 Assignment 3 Data Structures and Web Filtering Due: March 4, 2014 11:59 PM Implementing spam blacklists and web filters requires matching candidate domain names and URLs very rapidly
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
CS 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
Chapter 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
Working 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
1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
COSC 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
You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
Java Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class
CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,
15-214: Principles of Software Construction 8 th March 2012
15-214 Midterm Exam Andrew ID: SOLUTIONS 1 / 13 15-214: Principles of Software Construction 8 th March 2012 Name: SOLUTIONS Recitation Section (or Time): Instructions: Make sure that your exam is not missing
Introduction 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
JDK 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
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game
Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.
Introducing Variance into the Java Programming Language DRAFT
Introducing Variance into the Java Programming Language A Quick Tutorial DRAFT Christian Plesner Hansen Peter von der Ahé Erik Ernst Mads Torgersen Gilad Bracha June 3, 2003 1 Introduction Notice: This
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219
Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
Quick Introduction to Java
Quick Introduction to Java Dr. Chris Bourke Department of Computer Science & Engineering University of Nebraska Lincoln Lincoln, NE 68588, USA Email: [email protected] 2015/10/30 20:02:28 Abstract These
Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.
Software Testing Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Testing can only reveal the presence of errors and not the
Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from www.agileskills.org
Unit Test 301 CHAPTER 12Unit Test Unit test Suppose that you are writing a CourseCatalog class to record the information of some courses: class CourseCatalog { CourseCatalog() { void add(course course)
e ag u g an L g ter lvin v E ram Neal G g ro va P Ja
Evolving the Java Programming Language Neal Gafter Overview The Challenge of Evolving a Language Design Principles Design Goals JDK7 and JDK8 Challenge: Evolving a Language What is it like trying to extend
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
CS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
Arrays in Java. Working with Arrays
Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such
Stacks. Data Structures and Data Types. Collections
Data Structures and Data Types Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack, Queue, Graph,... Data
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Computer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
Basic Programming and PC Skills: Basic Programming and PC Skills:
Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
Java 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
Stacks 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
Classes 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
Unit 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
UIL 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
AP Computer Science Java Mr. Clausen Program 9A, 9B
AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will
JAVA - 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
Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
Course: 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
Continuous 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
Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
D06 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
Creating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
Programming Methods & Java Examples
Programming Methods & Java Examples Dr Robert Harle, 2009 The following questions may be useful to work through for supervisions and/or revision. They are separated broadly by handout, but borders are
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
COMPUTER SCIENCE. Paper 1 (THEORY)
COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------
Chapter 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
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
Computer Science 210: Data Structures. Searching
Computer Science 210: Data Structures Searching Searching Given a sequence of elements, and a target element, find whether the target occurs in the sequence Variations: find first occurence; find all occurences
GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012
GUIs with Swing Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2012 Slides copyright 2012 by Jeffrey Eppinger, Jonathan Aldrich, William
12-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.
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139
ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
For live Java EE training, please see training courses
2012 Marty Hall Basic Java Syntax Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/java.htmlcoreservlets com/course-materials/java html 3 Customized Java
public static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
