CPS 100 2.1 What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 The Collections API.
Advertisements

Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Computer Science 209 Software Development Equality and Comparisons.
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Equality Programming in C# Equality CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Compiler Construction
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
15-Jun-15 Lists in Java Part of the Collections Framework.
Generic Programming David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 The problem Assume we have a nice Stack implementation. Our stack.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Generic Programming Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 The Problem Assume we have a nice Stack implementation. Our stack receives.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
Generic Programming David Rabinowitz. June 14, 2006 Object Oriented Design Course 2 The problem Assume we have a nice Stack implementation. Our stack.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
12-Jul-15 Lists in Java Part of the Collections Framework.
Java's Collection Framework
CPS 108 : Spring From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea  Not really a standard language like C++  Arguably.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
CompSci 100 Prog Design and Analysis II Sept 7, 2010 Prof. Rodger 1CompSci 100 Fall 2010.
Chapter 3 Introduction to Collections – Stacks Modified
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
Announcements  I will discuss the labtest and the written test #2 common mistakes, solution, etc. in the next class  not today as I am still waiting.
Class Inheritance UNC-CHAPEL HILL COMP 401 BRIAN CRISTANTE 5 FEBRUARY 2015.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
Compsci 06/101, Fall What will we do today? l Practice solving problems  Solving problems without a computer  Is this different than solving.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Generics and Collections. Introduction Generics New feature of J2SE 5.0 Provide compile-time type safety Catch invalid types at compile time Generic methods.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
Compsci 100, Fall Data and Information How and why do we organize data? Differences between data and information? What about knowledge?
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Data structures Abstract data types Java classes for Data structures and ADTs.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Genome Revolution: COMPSCI 006G 2.1 Control in Java and Programming l The computer executes your program one statement at a time, from top to bottom within.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Compsci 06/101, Fall Vocabulary l What's the Spanish word for 'boy'? 'eat'?  How do you know? l What about the Turkish equivalents?  How do.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
1 Interfaces in Java’s Collection Framework Rick Mercer.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
CompSci 100e 3.1 Plan for the week l Classes and Objects l Model-View-Controller l Maps and Hashing l Upcoming  Towards Algorithm analysis l APTs:  IsomorphicWords,
CPS 100, Spring Data and Information How and why do we organize data? Differences between data and information? What about knowledge?
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
CPS APTs and structuring data/information l Is an element in an array, Where is an element in an array?  DIY: use a loop  Use Collections, several.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
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.
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
CompSci 100e 7.1 Plan for the week l Review:  Boggle  Coding standards and inheritance l Understand linked lists from the bottom up and top-down  As.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
Building Java Programs Generics, hashing reading: 18.1.
CompSci Toward understanding data structures  What can be put in a TreeSet?  What can be sorted?  Where do we find this information?  How do.
Java: Base Types All information has a type or class designation
Data and Information How and why do we organize data? Differences between data and information? What about knowledge?
Java: Base Types All information has a type or class designation
CS2013 Lecture 7 John Hurley Cal State LA.
Java String Class String is a class
Introduction to Java Collection
Presentation transcript:

CPS What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l Object oriented programming using Java  IDE  Language  Problem-solving  From design to code

CPS Toward understanding data structures l What can be put in a TreeSet? l What can be sorted?  Where do we find this information?  How do we understand the information? l What can be put in an ArrayList? Why is this different?  What operations exist on an ArrayList?  What about an array, or operations done on an ArrayList as opposed to what an ArrayList does to itself?

CPS What can an Object do (to itself)? l  Look at java.lang.Object  What is this class? What is its purpose? l toString()  Used to print ( System.out.println ) an object  overriding toString() useful in new classes  String concatenation: String s = "value "+x;  Default is basically a pointer-value

CPS What else can you do to an Object? l equals(Object o)  Determines if guts of two objects are the same, must override, e.g., for using a.indexOf(o) in ArrayList a  Default is ==, pointer equality l hashCode()  Hashes object (guts) to value for efficient lookup l If you're implementing a new class, to play nice with others you must  Override equals and hashCode  Ensure that equal objects return same hashCode value

CPS Objects and values l Primitive variables are boxes  think memory location with value l Object variables are labels that are put on boxes String s = new String("genome"); String t = new String("genome"); if (s == t) {they label the same box} if (s.equals(t)) {contents of boxes the same} s t What's in the boxes? "genome" is in the boxes

CPS Objects, values, classes l For primitive types: int, char, double, boolean  Variables have names and are themselves boxes (metaphorically)  Two int variables assigned 17 are equal with == l For object types: String, ArrayList, others  Variables have names and are labels for boxes  If no box assigned, created, then label applied to null  Can assign label to existing box (via another label)  Can create new box using built-in new l Object types are references or pointers or labels to storage

CPS Anatomy of a class public class Foo { private int mySize; private String myName; public Foo(){ // what’s needed? } public int getSize(){ return mySize; } public double getArea(){ double x; x = Math.sqrt(mySize); return x; } l What values for vars (variables) and ivars (instance variables)?

CPS David Parnas "For much of my life, I have been a software voyeur, peeking furtively at other people's dirty code. Occasionally, I find a real jewel, a well-structured program written in a consistent style, free of kludges, developed so that each component is simple and organized, and designed so that the product is easy to change. "

CPS Parnas on re-invention "We must not forget that the wheel is reinvented so often because it is a very good idea; I've learned to worry more about the soundness of ideas that were invented only once. "

CPS David Parnas (entry in Wikipedia)Wikipedia l Module Design: Parnas wrote about the criteria for designing modules, in other words, the criteria for grouping functions together. This was a key predecessor to designing objects, and today's object-oriented design. l Social Responsibility: Parnas also took a key stand against the Strategic Defense Initiative (SDI) in the mid 1980s, arguing that it would be impossible to write an application that was free enough from errors to be safely deployed. Strategic Defense Initiative l Professionalism: Parnas became one of the first software engineers to earn a professional engineering license in Canada. He believes that software engineering is a branch of traditional engineering.

CPS What about a 'struct' (plain old data) l We use classes, data/state is private, methods are public  Why do we have rules? When can they be broken?  Why are there both structs and classes in C++? l What about helping class, e.g., word and frequency together?  We can have one class nested in another, then we don't have to worry so much about encapsulation l We'll see example for a new class that can be compared using equality and can be sorted  Comparable interface must be symmetric with.equals  What happens if this isn't the case? Sometimes ok?

CPS John von Neumann “Anyone who attempts to generate random numbers by deterministic means is, of course, living in a state of sin.” “There's no sense in being precise when you don't even know what you're talking about. “ “There are two kinds of people in the world: Johnny von Neumann and the rest of us.” Eugene Wigner, Noble Physicist

CPS Tomato and Tomato, how to code java.util.Collection and java.util.Collections  one is an interface add(), addAll(), remove(), removeAll(), clear() toArray(), size(), iterator()  one is a collection of static methods sort(), shuffle(), reverse(), max() frequency(), indexOfSubList () java.util.Arrays  Also a collection of static methods sort(), fill(), binarySearch(), asList()