CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner

Slides:



Advertisements
Similar presentations
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Advertisements

Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
1 CSC241: Object Oriented Programming Lecture No 07.
1 CS1130 Spring 2011: David Gries & Walker White Transition to Object-Oriented Programming Assumes programming knowledge in a language like Matlab, C,
Abstract Data Types (ADTs) Data Structures The Java Collections API
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CPS 100, Fall COMPSCI 100, Fall 2011 Owen Astrachan w/ Michael Hewner
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
Programming Languages and Paradigms Object-Oriented Programming.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CPS 100, Spring COMPSCI 100, Spring 2010 Owen Astrachan
Compsci 06/101, Fall COMPSCI 06/101, Fall 2010 Owen Astrachan Robert Duvall
CSCA48 Course Summary.
CSC 212 Object-Oriented Programming and Java Part 1.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
(c) University of Washington14-1 CSC 143 Java Collections.
Introduction. 2COMPSCI Computer Science Fundamentals.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
1 Object Oriented Programming Lecture IX Some notes on Java Performance with aspects on execution time and memory consumption.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
A Computer Science Tapestry 12.1 Tools for programming l Syntatic details of control and variables  If, while, switch, function calls  Scope and lifetime.
CPS 100, Fall COMPSCI 100, Fall 2009 Owen Astrachan
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
CPS Anagram: Using Normalizers l How can we normalize an Anaword object differently?  Call normalize explicitly on all Anaword objects  Have.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
CSC 212 – Data Structures Lecture 37: Course Review.
CompSci 100E Functions (Static Methods)  Java function.  Takes zero or more input arguments.  Returns one output value.  Applications.  Scientists.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
CPS 100, Spring COMPSCI 100, Spring 2009 Owen Astrachan
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
Written by: Dr. JJ Shepherd
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Compsci 06/101, Spring COMPSCI 06/101, Spring 2011 Introduction to Computer Science Owen Astrachan
Genome Revolution: COMPSCI 006G 15.1 Recursion and Recursive Structures l Definition in the dictionary: in mathematics an expression in which a value is.
OOP Basics Classes & Methods (c) IDMS/SQL News
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CSE 501N Fall ‘09 03: Class Members 03 September 2009 Nick Leidenfrost.
CPS Anagram: Using Normalizers l How can we normalize an Anaword object differently?  Call normalize explicitly on all Anaword objects  Have.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
AP National Conference, AP CS A and AB: New/Experienced A Tall Order? Mark Stehlik
CompSci 100 Prog Design and Analysis II
Using the Java Collection Libraries COMP 103 # T2
CompSci 100E cs. duke CompSci 100E Dietolf (Dee) Ramm
Modern Programming Tools And Techniques-I
CompSci 100 Dietolf (Dee) Ramm
Week 6 Object-Oriented Programming (2): Polymorphism
Introduction to Data Structure
Java String Class String is a class
COMPSCI 100, Spring 2008 Owen Astrachan
Java Basics – Arrays Should be a very familiar idea
Presentation transcript:

CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner

CompSci 100E 1.2 What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex. C.A.R. (Tony)Hoare

CompSci 100E 1.3 Programming != Computer Science  What is the nature of intelligence? How can one predict the performance of a complex system? What is the nature of human cognition? Does the natural world 'compute'?  It is the interplay between such fundamental challenges and the human condition that makes computer science so interesting. The results from even the most esoteric computer science research programs often have widespread practical impact. Computer security depends upon the innovations in mathematics. Your Google search for a friend depends on state-of-the-art distributed computing systems, algorithms, and artificial intelligence.

CompSci 100E 1.4 Efficient design, programs, code Object-oriented design and patterns. Software design principles transcend language, but … Engineer, scientist: what toolkits do you bring to programming? Mathematics, design patterns, libraries --- standard and Duke CPS Know data structures and algorithms. Trees, hashing, binary search, sorting, priority queues, greedy methods, … Using the language: Java (or C++, or Python, or …), its idioms, its idiosyncracies

CompSci 100E 1.5 Course Overview  Lectures, Labs, Quizzes, Programs  Lectures based on readings, questions, programs o Online quizzes used to motivate/ensure reading o In-class questions used to ensure understanding  Programs o Theory and practice of data structures and OO programming o Fun, practical, tiring, … o Weekly programs and longer programs  Labs based on current work o Get in practical stuff o Become familiar with tools  Exams/Tests (closed book)  Two “midterms”  Final

CompSci 100E 1.6 Questions If you gotta ask, you’ll never know Louis Armstrong: “What’s Jazz?” If you gotta ask, you ain’t got it Fats Waller: “What’s rhythm?” What questions did you ask today? Arno Penzias

CompSci 100E 1.7 Tradeoffs Simple, elegant, quick, efficient: what are our goals in programming? What does XP say about simplicity? Einstein? How do we decide what tradeoffs are important? Tension between generality, simplicity, elegance, … Fast programs, small programs, run anywhere-at-all programs. Runtime, space, your time, CPU time… Programming, design, algorithmic, data- structural

CompSci 100E 1.8 OO design in code/wordcount  Count number of different words in an array, how can we accommodate more than one approach? public interface UniqueCounter { public int uniqueCount(String[] list); }  Three (or more) approaches: 

CompSci 100E 1.9 Fast, cheap, out-of-control?  This is valid and correct Java code, questions? import java.util.*; public class SetUniqueCounter implements UniqueCounter { public int uniqueCount(String[] list) { TreeSet set = new TreeSet(); set.addAll(Arrays.asList(list)); return set.size(); }

CompSci 100E 1.10 Some Java / Matlab Differences  Compile & Execute vs Interactive  In Java, compile, then run ( execute ) – like.m files  Matlab executes as you type in program  Java requires declaration of variables  Need to tell about the variable before creating  Declaration is distinct from Definition (creation)  Java is not matrix oriented  Operators ( +, -, *, /, % ), do not work on matrices  You must write code with loops for matrix operations  - or use functions (methods)

CompSci 100E 1.11 Some Java / Matlab Differences  No exponentiation operator  Cannot say X^3 for X 3  Use X*X*X or a function  Syntax differences  Use of braces, {... }, in place of xxx … end  Semicolon has somewhat different meaning  Use quotes, ”... ”, for strings not ’... ’  Loops and if require parentheses (... )  You’ll find many more differences  Will be an annoying, but transient problem

CompSci 100E 1.12 Some Java Vocabulary and Concepts  Java has a huge standard library  Organized in packages : java.lang, java.util, javax.swing, …  API browseable online, but Eclipse IDE helps a lot  Java methods have different kinds of access inter/intra class  Public methods …  Private methods …  Protected and Package methods …  Primitive types (int, char, double, boolean) are not objects but everything else is literally an instance of class Object  foo.callMe();

CompSci 100E 1.13 Basic data structures and algorithms  Arrays are typed and fixed in size when created  Not like vector in C++  Don't have to fill the array, but cannot expand it  Can store int, double, String, Foo, …  ArrayList (and related class Vector and interface List) grows  Stores objects, not primitives  Accessing elements can require a downcast  ArrayList objects grow themselves intelligently  java.util package has lots of data structures and algorithms  Use rather than re-implement, but know how do to do both

CompSci 100E 1.14 Tracking different/unique words  We want to know how many times ‘the’ occurs  Do search engines do this? Does the number of occurrences of “basketball” on a page raise the priority of a webpage in some search engines? o Downside of this approach for search engines?  Constraints on solving this problem  We must read every word in the file (or web page)  Search for the word? Avoid counting twice? Store?  Are there fundamental limits on any of these operations? Where should we look for data structure and algorithmic improvements?

CompSci 100E 1.15 What does it try to do? Why is it wrong? public class SlowUniqueCounter implements UniqueCounter{ public int uniqueCount(String[] list) { int count = 0; int diffSize = list.length; for(int k=0; k < diffSize; k++){ String word = list[k]; count++; for(int j=k+1; j < diffSize; j++){ if (list[j].equals(word)){ list[j] = list[diffSize-1]; diffSize--; } return count; }

CompSci 100E 1.16 Search: measuring performance  How fast is fast enough? /** pre: a contains a.size() entries * post: return true if and only if key found in a */ boolean search(ArrayList a, String key) { for(int k=0; k < a.size(); k++) if (a[k].equals(key)) return true; return false; }  Java details: parameters? Return values? ArrayLists?  How do we measure performance of code? Of algorithm?  Does processor make a difference? G5? Itanium? 64-bit?

CompSci 100E 1.17 Tradeoffs in processing and counting  Read words, then sort, determine # unique words?  frog, frog, frog, rat, tiger, tiger, tiger, tiger  If we look up words one-at-a-time and bump counter if we haven't seen a word, is this slower than previous idea?  How do we look up word, how do we add word  Are there kinds of data that make one approach preferable?  What is best case, worst case, average case?

CompSci 100E 1.18 Benefits of inheritance, interfaces  Consider new algorithm for determining unique word count public static void test(UniqueCounter uc, String[] list){ double start = System.currentTimeMillis(); int count = uc.uniqueCount(list); double end = System.currentTimeMillis(); System.out.println(count+" unique words"); System.out.println((end-start)/1000+" seconds"); }  Why can we pass different kinds of objects to test ?  Why is this an advantage?  Inheritance and late/dynamic binding

CompSci 100E 1.19 Why inheritance?  Add new shapes easily without changing much code  Shape s1 = new Circle();  Shape s2 = new Square();  Interface/abstract base class:  interface or abstraction  Function called at runtime  concrete subclass  All abstract functions implemented  Later we'll override  “is-a” view of inheritance  Substitutable for, usable in all cases as-a shape mammal ScoreEntry FullHouse, LargeStraight User’s eye view: think and program with abstractions, realize different, but conforming implementations, don’t commit to something concrete until as late as possible

CompSci 100E 1.20 Example of inheritance  What is behavior of a shape? void doShape(Shape s) { System.out.println(s.area()); System.out.println(s.perimeter()); s.expand(2.0); System.out.println(s.area()); System.out.println(s.perimeter());} Shape s1 = new Circle(2); Shape s2 = new Square(4); Shape s3 = new Rectangle(2,5); doShape(s1); doShape(s2); doShape(s3);

CompSci 100E 1.21 Inheritance (language independent)  First view: exploit common interfaces in programming  Iterators in Java or C++/Tapestry  Implementation varies while interface stays the same  Second view: share code, factor code into parent class  Code in parent class shared by subclasses  Subclasses can override inherited method o Subclasses can override and call  Polymorphism/late(runtime) binding (compare: static)  Function actually called determined when program runs, not when program is compiled

CompSci 100E 1.22 Who is Alan Perlis?  It is easier to write an incorrect program than to understand a correct one  Simplicity does not precede complexity, but follows it  If you have a procedure with ten parameters you probably missed some  If a listener nods his head when you're explaining your program, wake him up  Programming is an unnatural act  Won first Turing award