Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
CMPSCI 187
Introduction to Programming
with Data Structures
Computer Science 187
Lecture 1
INTRODUCTION
Instructors:
Allen Hanson
hanson@cs.umass.edu
TA:
Scott Kuindersma
scottk@cs.umass.edu
1
CMPSCI 187
Items to Discuss
Getting into the course.
Homework and Grading.
Working together.
TAs: office hours etc.
On-Line course material.
2
CMPSCI 187
Course Goals and Content
Learn specifics of use of some important data structures
Learn how to for design and evaluate data structures
Develop an object-oriented philosophy
Deepen general facility in programming
Learn to use Java
Data structure : A systematic way of organizing and
accessing data.
Algorithm : A step-by-step procedure for performing
some task in a finite amount of time.
3
CMPSCI 187
(Secret) Agenda
Understand, appreciate fundamental data
structures & their relationship to algorithms
Appreciate the interplay between DS,
algorithms, and OO programming
Become a skilled code reader
Become a skilled Java programmer
4
CMPSCI 187
Who fails, and why..
Phrasebook Java
Don’t know what you don’t know (come to
class!)
In general CS is as much about technique as
about brains
Passivity: this course in not a big-needle shot
of knowledge in the head
Write code….practice, practice, practice
5
CMPSCI 187
Textbook
Elliot B. Koffman and Paul A. T. Wolfgang
Data Structures: Objects, Abstraction, and
Design Using Java 5.0
[John Wiley and Sons, 2005]
Available at
Textbook
annex and possibly
Jeffrey Amherst Bookstore (downtown
Amherst)
http://www.jeffbooks.com/Info.html
6
CMPSCI 187
Jeffrey Amherst Location
N. Pleasant Street
Amity Street
Main Street
S. Pleasant Street
7
CMPSCI 187
Syllabus
Will cover a fair amount of the textbook
Material will be covered in order shown on syllabus
Detailed syllabus on course WIKI page
Web Page: http://www.cs.umass.edu/cs187
WIKI page: http://twikiedlab.cs.umass.edu/bin/view/Hanson187/WebHome
Lectures will hit the high points of material in the
book plus additional material not in the book.
Wednesday discussion sessions will be more
informal.
8
CMPSCI 187
Homework and Grading
Quantity
1
1
6 or 7
Worth
midterm exam
final exam
programming projects
Owl & Discussion sheets
20%
35%
30%
15%
Must get at least a C on the final to get a C overall
Collaboration?
YES …..encouraged, BUT final
work must be your own.
9
CMPSCI 187
Course Syllabus -- Topics
(not necessarily in order)
Java - Review/Overview
Generics
Object-Oriented Design
Trees
Abstract Data Types
Priority Queues
Computational
Dictionaries
Complexity
Stacks & Queues
Recursion
Vectors, Lists &
Sequences
Search Trees
Sorting, Sets & Selection
Graphs (time permitting)
Strings and Pattern
Matching (time permitting)
10
CMPSCI 187
On-Line Resources
Course Wiki Page:
http://twiki-edlab.cs.umass.edu/bin/view/Hanson187/WebHome
Course Overview and Administration
Course Staff
Course Schedule
Lecture Notes
Homework Assignments
Exams
Discussion Notes and Assignments
Useful Links
Grades
11
CMPSCI 187
WIKI Front Page
VERY IMPORTANT
Late breaking news
Changes in
assignment dates
Important
announcements
12
CMPSCI 187
Syllabus page
Reading to be done
PRIOR to class
13
CMPSCI 187
TA
Scott Kuindersma
CS 207
scottk@cs.umass.edu
I am a first year graduate student in
the Computer Science MS/PhD
program at UMass Amherst. My
primary research interest is
biologically-inspired models for
machine learning.
My hope is that such research will not only lead to more effective
computational learning models, but also provide some further
insight into the mechanisms for learning and prediction in the brain.
14
CMPSCI 187
Consulting
HOURS
TBA
Consulting is in LGRT 224.
LGRT 224 shared with 121 consulting.
Watch 187 bulletin board (WIKI page) for
more information.
15
CMPSCI 187
Getting Into the Course
Prerequisites: C or better in CS123
Programming experience in Java, C++
Permission of Instructor
If not registered:
Fill
in override form
Look for announcement on 187 Bulletin board
Course has openings
If you are not registered, see me after class.
16
CMPSCI 187
Questions
What year are you in?
Math experience?
Intended major?
Have you taken CMPSCI 121?
Programming experience
never?
- consider switching to 121
Basic?
- consider switching to 121
Pascal?
- tough call, course assumes Java or C+
C?
- tough call, course assumes Java or C++
C++?
- should be OK but will require extra work
Java?
- should have at least one full semester
Scheme? - probably OK
Python? - probably OK
17
CMPSCI 187
Questions, continued
Do you have a computer?
If yes, what kind:
Macintosh?
IBM PC or compatible?
Others?
Have you ever used a Java Integrated
Development Environment before? If yes:
Sun JDK under Unix? Windows? MacOs?
Metroworks Code Warrior?
Microsoft J++/Jbuilder?
BlueJay?
Eclipse?
18
CMPSCI 187
EDLab Accounts
Everyone has an account
Will use the EdLab to submit Java source code and
other assignment information
Make sure you can log onto your account
Initially,
cd cs187 (all your 187 work should be done here)
User name =Most usernames will be first character of your
first name appended your lastname and then truncated to 8
characters.
Password = 9 digit student account number or whatever you
set it to last semester.
Problems logging on? See me or TA.
19
CMPSCI 187
CMPSCI 187
….on to the Java Review
20
CMPSCI 187
Topics of the Review
Essentials of object-oriented programming, in Java
Java primitive data types, control structures, and
arrays
Using some predefined classes:
Math
JOptionPane????, I/O streams
String, StringBuffer, StringBuilder
StringTokenizer
Writing and documenting your own Java classes
21
CMPSCI 187
Salient Characteristics of Java
Java is platform independent: the same program can
run on any correctly implemented Java system
Java is object-oriented:
Java designed as
Structured in terms of classes, which group data with operations
on that data
Can construct new classes by extending existing ones
A core language plus
A rich collection of commonly available packages
Java can be embedded in Web pages
22
CMPSCI 187
Classes and Objects
The class is the unit of programming
A Java program is a collection of classes
class definition (usually) in its own .java file
The file name must match the class name
Each
A class describes objects (instances)
Describes
their common characteristics: is a blueprint
Thus all the instances have these same characteristics
These characteristics are:
Data
fields for each object
Methods (operations) that do work on the objects
23
CMPSCI 187
What's a Java program?
A bunch of files, living in a project (directory)
Each file contains a class declaration
Somewhere inside the classes there is a main
method:
public static main (String [] args)
which gets called when you run a java project.
Two kinds of Java programs:
Applets: designed to be downloaded into a web browser
Applications: stand-alone programs that perform some task
(e.g. Word, Excel, Photoshop…)
187 concentrates on applications.
24
CMPSCI 187
Hello, World
import java.io.*;
class HelloWorld
{
/**
* main method…prints the string Hello, World
*/
public static void main(String[] args)
{
System.out.println("Hello, World") ;
} // end of method main
} // end of class Hello
25
CMPSCI 187
Java Processing and Execution
Begin with Java source code in text files:
Model.java
A Java source code compiler produces Java byte
code
one file per class: Model.class
May be standalone or part of an IDE
Outputs
A Java Virtual Machine loads and executes
class files
May
compile them to native code (e.g., x86) internally
26
CMPSCI 187
Compiling and Executing a
Java Program
27
Grouping Classes: The Java
API
CMPSCI 187
API = Application Programming Interface
Java = small core + extensive collection of packages
A package consists of some related Java classes:
Swing: a GUI (graphical user interface) package
AWT: Application Window Toolkit (more GUI)
util: utility data structures (important to CS 187!)
The import statement tells the compiler to make
available classes and methods of another package
A main method indicates where to begin executing a
class (if it is designed to be run as a program)
28
CMPSCI 187
Data Structures and Algorithms
From Goodrich & Tamassia (1st edition), p. 5
29
CMPSCI 187
Abstract Data Types
An abstract data type (ADT) is an abstraction of a data
structure: no coding is involved.
User
The ADT specifies:
For example, if we were going to model
a bag of marbles as an ADT,
we could specify that
What can be stored in the structure
What operations can be done on/by the ADT
Public Interface
Abstract Data Type
Implementation#1
Implementation#2
Implementation#3
Details hidden from user!
this ADT stores marbles
this ADT supports putting in a marble and getting out a marble
There are lots of formalized and standardized ADTs
In this course, we will look at many of them:
stacks, queues, lists, trees, …...
30
CMPSCI 187
Object-Oriented Design
Principles and Techniques
Principles
Abstraction
Encapsulation
Modularity
Techniques
Classes and
Objects
Interfaces and
Strong Typing
Inheritance and
Polymorphism
31
CMPSCI 187
Object-Oriented Design Principles
Modularity
From Goodrich & Tamassia , p. 62
32
CMPSCI 187
Object-Oriented Design
Principles and Techniques
33
From Goodrich & Tamassia (1st edition) , p. 10
CMPSCI 187
‘Chance’ Simulation
import java.util.Random;
public class Chance{
Random R;
public Chance()
{R = new Random(); }
public boolean coinToss()
{return (R.nextInt(2) == 1);}
public int dieToss()
{return(R.nextInt(6) + 1);}
public int diceToss()
{return (dieToss() + dieToss()); }
}
34
CMPSCI 187
Test Program for Chance
public class ChanceTester
{
public static void main(String[] args)
{
Chance C = new Chance();
for (int j = 0; j < 10; j++)
System.out.println("throwing dice.." + C.diceToss());
}//End Main
}//End ChanceTester
-----------------------------------------------------throwing dice..8
throwing dice..10
throwing dice..12
…
throwing dice..3
throwing dice..6
throwing dice..8
35