CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. ·...
Transcript of CS 61B Data Structures and Programming Methodologycs61b/su08/lec/lecture1.pdf · 2008. 6. 23. ·...
![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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/1.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/2.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/3.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/4.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/5.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/6.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/7.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/8.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/9.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/10.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/11.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/12.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/13.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/14.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/15.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/16.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/17.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/18.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/19.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/20.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/21.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/22.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/23.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/24.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/25.jpg)
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); •](https://reader033.fdocuments.in/reader033/viewer/2022060518/604b96293e640306874e2641/html5/thumbnails/26.jpg)
ReadingAssignments
• HeadFirstJava– Chapters1‐2– CS61Breadings(readSchemetoJavaarticle)
• Nexttime:– Types– DefiningClasses