CS61BDataStructuresandProgrammingMethodology
June232008DavidSun
http://inst.eecs.berkeley.edu/~cs61b/su08/
CourseOverview
CourseGoals
• Roughlyathirdofeachofthesethings:– Java– Datastructuresandalgorithms– Programmingmethodology
Relevance
PrerequisitesandExpectations• Haven’ttaken61A?– Talktotheinstructorafterclass.
• Yourfirsttimetakingsummersessioncourse?– Thesummersessionrunsat2xthespeed.
– Expectanaverageof12hoursofself‐scheduledstudy/programminglabperweek,outsideofscheduledmeetingtimes.
CourseMechanics
ClassMeetingtimes• Lectures:– Mon/Tue/Wed/Thurs,11:00am–12:30pm,306Soda.
• Labssections:– 2timesaweek,onMon/Wed,275SodaHall
• Discussionsections:– 2timesaweek,onTue/Thurs,310/320SodaHall
LabsandDiscussions
• Labs– Startingthisweek.– GetyourInstructionalAccount.
• Discussions– Willcovernewmaterial.Youshouldattend!– KnowthenameofyourTA.
– Alsostartingthisweek.
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
ReachingUs
• Email:[email protected]– Forfastestresponse– Pleaseavoidmailingusdirectly– Pleaseaddtext“[CS61B]”tothesubjectheader
• Newsgroup:ucb.class.cs61b– Requiredreading.
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.
Grading
• 200totalpoints.– Homework(30pts)– Projects(70pts)– Midterm1(25pts)– Midterm2(25pts)– Final(50pts)
• GradingScale– Nocurving.Yourgradedependssolelyonhowwellyoudointhisclass.
– 185+pointsisanA+,175‐185isaA,downtoD‐(75‐85).
Assessments
• Homework– 12homeworkassignments,equallyweighted– Assignedattheendofeachlabsection
• ThreeProjects:– Project1(individual)– Projects2and3(workinagroupoftwoorthreestudents).
• Midterm1– July8th,inclass120minutes
• Midterm2– July29th,inclass120minutes
• Final– Aug14th(lastdayofinstruction),inclass180minutes.
PolicyonLateness
• Latehomeworks– Notbeaccepted.
• Lateprojects– Loose1percentforeverytwohoursbywhichyoumissthedeadline.
• Freethreelatedays(72hours)– Forprojectworkonly.– Forthesecondandthirdproject,thenumberofsliphoursistheaveragebetweenwhat’sleftforyouandyourpartner.
Collaboration
• Appropriate:– DiscussinghowtoapproachhomeworkproblemsorprojectsisOK,aslongasyouwritethecode.
• Nocoderule:– youshouldneverexamineorbeinpossessionofanotherstudent'ssolutionorpartialsolution,eitherelectronicallyorinhardcopyform
– youshouldnotgiveyoursolutiontosomeoneelse.
UCWise
Eclipse
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); } } }
DifferencetoScheme
• Javaprogramsmustbecompiledbeforeyoucanrunthem.
Schemeprogram(.scm)Javaprogram(.java)
Result
eval javac
.classfile
java
Result
Classes• Twowaystogetclasses:– Defineonyourself(innextlecture)– Useonedefinedbyothers.Manycomeinthe“JavaStandardLibrary”providedwitheveryJavacompiler.
• String class– Built‐inclass– Asequenceofcharacters,e.g.theword“Hello”
Variables
• EveryvariableinJavamustbedeclared.– String myString;
– NoStringobjectiscreatedjustyet!• Tocreateanobject
– myString = new String(“Hello”); – new String(“Hello”); constructsanewStringobject.
– TheassignmentstatementcausesmyStringtoreferencetheobject.
myString
Hello
(class)D (variablename)
DifferenceBetweenSchemeandJava
• EveryvariableinJavahasatype(orclass),andyoumustexplicitly“declare”it.
• Toassignvalue1tox– Scheme:(let ((x 1))) – Java:int x; x = 1;
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
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.
Methods
• Constructorsaremethodsthatcreatenewobjects
• Onceanobjectiscreated,othermethodscanactontheobject
s2 = s1.toUppercase();//“HELLO”
String s3 = s2.concat(“!!”); //”HELLO!!”
String s4 = “*”.concat(s2).concat(“*”);
//*HELLO*
(object) (method)
ReadingAssignments
• HeadFirstJava– Chapters1‐2– CS61Breadings(readSchemetoJavaarticle)
• Nexttime:– Types– DefiningClasses