CS62 - Spring 2010 - Lecture 1
introduction to students
- major, year, college
- CS background
- Why are you taking this course?
- What do you hope to get out of the course?
goals of the class
- Prereqs: 51 or AP CS. Should be familiar with Java specifically:
- control structures
- advanced programming: more practice and more tools
- data structures
- basic performance analysis and design decisions
- After this class, you'll be ready to take upper division CS courses
from cs160 in the Fall
- show class web page
- rough schedule
- two labs on Wed. and are required (no lab this week)
- must come to one, but feel free to come to both
- labs will lead generally be a lead in to assignment
- computer accounts
- I'll post everything online on the class web page
- I will post my notes
- Academic honesty (the code you write must be your own)
What makes a good computer program?
- reusable/easy to modify
- data encapsulation/information hiding/abstraction
- You write your code, how does your program actually end up running and showing up on the computer?
- Let's ask some more directed questions
- what is a string?
- an ordered list of characters
- what functionality do we have?
- how is it implemented?
- Could be many different ways, but most of the time, we don't care as long as the functionality is preserved. This is data abstraction.
- The functionality, is called the interface
- How this is done internally, is called the implementation
Object oriented programming: The key to an object oriented programming language is managing complexity
- private, internal data
- methods to access and manipulate the data
- the only thing you need to know about a class is it's interface, i.e. it's public methods, not the details of how it's implemented
Why is OO programming useful/good?
Design a card dealer class
- represent some number of decks of cards
- What operations/functionality do we want (this is the interface)?
- deal/get next card
- are there cards left?
- What should the constructor consist of?
- number of decks
- Implementation details:
- What data do we need to store?
- somehow the state of the cards
- How are we going to store that data?
- Fill in the details of the methods
- comment code!
- coding style: I provide a style guideline online, but as you get better at programming you can experiment with what style works best for you. Just make sure you're consistent and it makes sense
- constants: should always be caps and start with "private static final"
- what do all of those words mean?
- the book suggests using "protected" instead of "private". I'm going to use "private" and will talk about the difference soon.
- What is "public static void main(String args)" and what do each of the parts mean?
- Notice that all of our data is private (i.e. not accessible to outside classes), but we provide methods that allow interaction
- What is the functionality of the Random class? What methods does it have?
- We can look it up in the API
- "import" allows us to bring in additional outside resources in to our class
- How else could we implement the CardDealer methods?
- just keep track of which cards have been dealt and then randomly pick a card from those remaining
- same interface as CardDealer class, but different implementation
- notice the use of private methods (setAllTrue)
- which approach is better?
- CardDealer seems more intuititive
- CardDealer is more efficient (particularly as we have fewer undealt cards)
- CardDealerBoolean uses less memory
- how many bits do we need to store a boolean variable?
- int's use 32 bits to represent the numbers... how many numbers can we represent?
Design a stopwatch class
- What functionality should we have?
- Be specific about the functionality:
- What happens if we call start twice in ?
- What happens if we call stop twice in a row? or without having called start?
- What happens if we call start then call reset (without calling stop)?
- What data do we need to store?
- start time
- stop time (or accumulated time)
- whether it's running or not (what happens if we just hit stop twice without using a running variable?)