26
CS 61B Data Structures and Programming Methodology June 23 2008 David Sun http://inst.eecs.berkeley.edu/~cs61b/su08/

CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

CS61BDataStructuresandProgrammingMethodology

June232008DavidSun

http://inst.eecs.berkeley.edu/~cs61b/su08/

Page 2: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

CourseOverview

Page 3: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

CourseGoals

•  Roughlyathirdofeachofthesethings:– Java– Datastructuresandalgorithms– Programmingmethodology

Page 4: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Relevance

Page 5: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

PrerequisitesandExpectations•  Haven’ttaken61A?– Talktotheinstructorafterclass.

•  Yourfirsttimetakingsummersessioncourse?– Thesummersessionrunsat2xthespeed.

– Expectanaverageof12hoursofself‐scheduledstudy/programminglabperweek,outsideofscheduledmeetingtimes.

Page 6: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

CourseMechanics

Page 7: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

ClassMeetingtimes•  Lectures:– Mon/Tue/Wed/Thurs,11:00am–12:30pm,306Soda.

•  Labssections:– 2timesaweek,onMon/Wed,275SodaHall

•  Discussionsections:– 2timesaweek,onTue/Thurs,310/320SodaHall

Page 8: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

LabsandDiscussions

•  Labs– Startingthisweek.– GetyourInstructionalAccount.

•  Discussions– Willcovernewmaterial.Youshouldattend!– KnowthenameofyourTA.

– Alsostartingthisweek.

Page 9: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

TAs,OfficeHours

•  TeachingAssistants:– BenBlum– AdamKirk– GeorgeWang

•  OfficeHours– David:Mon/Wed2‐4p.min360HMM(buildingbehindCoryHall)

– Ben:Tue/Thur2‐4p.min611SodaHall– Adam:Tues4‐5pmandWed5‐6pmin611SodaHall– George:Thurs4‐5pmandFri2‐3pminSodaHall– Alsobyappointment

Page 10: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

ReachingUs

•  Email:[email protected]– Forfastestresponse– Pleaseavoidmailingusdirectly– Pleaseaddtext“[CS61B]”tothesubjectheader

•  Newsgroup:ucb.class.cs61b– Requiredreading.

Page 11: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Textbooks

•  HeadFirstJava–  byKathySierraandBertBates(secondedition,OReilly,2005);

•  PragmaticUnitTestinginJavawithJUnit–  byAndrewHuntandDavidThomas(ThePragmaticBookshelf,

2004)•  Objects,Abstraction,DataStructuresandDesignusing

Java5.0–  byElliotB.KomanandPaulA.T.Wolfgang(Wiley,2005)–  Downloadableversionformuchless:

•  http://he‐cda.wiley.com/WileyCDA/HigherEdTitle/productCd‐0471692646,courseCd‐CX1500.html

•  Readingsareimportanttotheclass.Pleasekeepupspeed.

Page 12: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Grading

•  200totalpoints.– Homework(30pts)– Projects(70pts)– Midterm1(25pts)– Midterm2(25pts)– Final(50pts)

•  GradingScale– Nocurving.Yourgradedependssolelyonhowwellyoudointhisclass.

– 185+pointsisanA+,175‐185isaA,downtoD‐(75‐85).

Page 13: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Assessments

•  Homework–  12homeworkassignments,equallyweighted–  Assignedattheendofeachlabsection

•  ThreeProjects:–  Project1(individual)–  Projects2and3(workinagroupoftwoorthreestudents).

•  Midterm1–  July8th,inclass120minutes

•  Midterm2–  July29th,inclass120minutes

•  Final–  Aug14th(lastdayofinstruction),inclass180minutes.

Page 14: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

PolicyonLateness

•  Latehomeworks– Notbeaccepted.

•  Lateprojects– Loose1percentforeverytwohoursbywhichyoumissthedeadline.

•  Freethreelatedays(72hours)– Forprojectworkonly.– Forthesecondandthirdproject,thenumberofsliphoursistheaveragebetweenwhat’sleftforyouandyourpartner.

Page 15: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Collaboration

•  Appropriate:– DiscussinghowtoapproachhomeworkproblemsorprojectsisOK,aslongasyouwritethecode.

•  Nocoderule:– youshouldneverexamineorbeinpossessionofanotherstudent'ssolutionorpartialsolution,eitherelectronicallyorinhardcopyform

– youshouldnotgiveyoursolutiontosomeoneelse.

Page 16: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

UCWise

Page 17: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Eclipse

Page 18: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

AFirstJavaProgram

•  EveryJavaprogramneedsaclassdefinition.•  AClassdefinitionconsistsofacollectionof

methods.•  Allthestatementsunderthemainmethodis

executedwhenjavaexecutestheprogram.

public class FirstApp { public static void main(String[] args){ String[] greeting = new String[3]; greeting[0] = "Welcome to CS 61b"; greeting[1] = "from David, Ben, Adam"; greeting[2] = "and George"; for (String g: greeting){ System.out.println(g); } } }

Page 19: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

DifferencetoScheme

•  Javaprogramsmustbecompiledbeforeyoucanrunthem.

Schemeprogram(.scm)Javaprogram(.java)

Result

eval javac

.classfile

java

Result

Page 20: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Classes•  Twowaystogetclasses:– Defineonyourself(innextlecture)– Useonedefinedbyothers.Manycomeinthe“JavaStandardLibrary”providedwitheveryJavacompiler.

•  String class– Built‐inclass– Asequenceofcharacters,e.g.theword“Hello”

Page 21: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Variables

•  EveryvariableinJavamustbedeclared.–  String myString;

– NoStringobjectiscreatedjustyet!•  Tocreateanobject

–  myString = new String(“Hello”); – new String(“Hello”); constructsanewStringobject.

– TheassignmentstatementcausesmyStringtoreferencetheobject.

myString

Hello

(class)D (variablename)

Page 22: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

DifferenceBetweenSchemeandJava

•  EveryvariableinJavahasatype(orclass),andyoumustexplicitly“declare”it.

•  Toassignvalue1tox– Scheme:(let ((x 1))) – Java:int x; x = 1;

Page 23: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

ObjectsandReferences

//declare two new string variable and assign two //different empty string objects

String s1 = new String(); String s2 = new String();

//constructs a new string; make s1 reference it

s1 = “Hello”; s2 = s1; s2 = new String (s1); //constructs a copy of s1; //make s2 reference to it.

//Assign s2 the value of s1

Page 24: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Constructors•  We’veseen3Stringconstructors:

– new String() constructsanemptystringwithnocharacters.

– “hello” constructsastringcontainingcharacters“hello”

– new String(s1) takesparameters1.Makesacopyoftheobjects1references.

– Otherconstructorsexist.Checktheonlinedocumentation.

•  Generallyconstructoralwayshavethesamenameastheclass– Onlyexception:thespecial“quotes”syntax.– new String() andnew String(s1) aredifferentconstructors.

Page 25: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

Methods

•  Constructorsaremethodsthatcreatenewobjects

•  Onceanobjectiscreated,othermethodscanactontheobject

s2 = s1.toUppercase();//“HELLO”

String s3 = s2.concat(“!!”); //”HELLO!!”

String s4 = “*”.concat(s2).concat(“*”);

//*HELLO*

(object) (method)

Page 26: CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. · First Java – by Kathy Sierra and Bert Bates (second edition, OReilly, 2005); •

ReadingAssignments

•  HeadFirstJava– Chapters1‐2– CS61Breadings(readSchemetoJavaarticle)

•  Nexttime:– Types– DefiningClasses