Programming MethodologyLecture26.docx
《Programming MethodologyLecture26.docx》由会员分享,可在线阅读,更多相关《Programming MethodologyLecture26.docx(20页珍藏版)》请在冰豆网上搜索。
ProgrammingMethodologyLecture26
ProgrammingMethodology-Lecture26
Instructor(MehranSahami):
Allright.Welcomebackto?
whatkindofdayisitgoingtobein106a?
Anyonewantto?
fun-filledandexciting.Italwaysis.Thanksforplayingalong.Soacouplequickannouncementsbeforewestart.Oneannouncementisthatthereisonehandouttoday,soseveralpeoplehaveaskedinthepast,theseprogramsthatImakeintheseclassesarekindofcool.Iwouldliketobeabletosharethemwithmyfriendsandrelativesandwhoeverelse.We'regoingtotalkalittlebitabouthowyoudothattodayandwhatthatmeansunderneaththehood,butthehandoutactuallyexplainsitall.It'sthisnotionofajarfile.We'lltalkmoreaboutajarfileaswegoalong.
Thegraphicscontext,forthoseofyouwhoaredoingit,isduetoday.Justwondering,quickshowofhands,howmanypeopleenteredthegraphicscontest.Wow.NotasmanyasIwould'vethought.Therecouldbeacouplepeoplewhoareathome,evenifyoudon'twinofgetting100onthefinalinarandomdrawing.Sothat'sagoodsign.
OnethingIdowanttocheck,Ijustheardalittlebitbeforeclassthatsomefolkswerehavingsometroublesubmittingtheirgraphicscontestbecausethereactuallymighthavebeenanissuewiththeserverthattakessubmissions.Soifyousubmittedtothegraphicscontest,whetheryou'reinhereoryouhappentobewatchingthevideo,emailme,andletmeknowwhatthenameofyourcontestentrywas.Thatway,Iknowforsurethatweactuallygotallthecontestentriesthatwethinkwehad,andifwedidn'tgetone,Icanemailyouback.ThethingIwouldaskyouis,ifyoucan'temailmeanytimethisweekendbecausethisweekendisactually,whenwe'regoingtomakethefirstpasslookingoverallthecontestentries,andthenwe'regoingtohaveasmallpoolthatwe'lltaketothesectionleaders.Theywillvoteandgivethewinner.I'llannouncethewinnerinclassnextweek.
Imightshowademoofthewinningtwoaswell.Wemightdotherandomdrawinginclassaswelltoseewhoactuallygetsthethirdcovetedrandomdrawingspot,evenifyoudon'twin.Sopleaseemailmeifyouenteredthegraphicscontest,justtomakesure.
OneotherthingwithemailforSCPDstudents,Iknowit'sstillalittletooearlytothinkaboutfinalexams,butifyou'reanSCPDstudent,it'snottooearly.Ifyou'renotanSCPDstudent,it'snottooearly,either.ButforSCPDstudents,ifyou'retakingthefinalexam,ifyouplanoftakingitatyoursitesandyou'renotgoingtocomeoncampustotakeit,emailmeby5:
00p.m.December5,lettingmeknowthatyou'retakingitatyoursiteandthenameandemailofyoursitecoordinator,justlikethemidterm.Thatway,Icangettheinformationtoyoursitecoordinatorforthefinalwellbeforethefinal.
Ifyou'replanningoncomingoncampustotakethefinal,youcanfeelfreetosendmeanemailtosayyou'recomingoncampus.IfIdon'thearfromyou,Iwillassumeyou'recomingoncampus.Soyouonlyneedtoemailmeifyou'retakingitatyoursite,sopleasedothatifyou'reanSCPDstudentandyouplanontakingitatyoursite.
Anyquestionsaboutanythingwe'vedonesofarbeforewediveintoournextgreattopic?
Allright.
Oneofthethingsthatwe'vedonethewholetimeinthisclassisweusethesethingscalledtheACMlibraries.TheACMlibrariesareasetoflibrariesthatareactuallycreatedbyataskforceofpeople.TheACMistheAssociationofComputingMachinery.Wetalkedaboutthemattheverybeginningoftheclasswhenwetalkedabouttheselibraries.Theyputtogethersomenicelibrariesofstuffthatarereallyusefulforteaching,whichiswhyweusethem.
Today,whatI'mgoingtodoisliftalittlebitunderneaththehoodandtalkaboutstandardJava,whichiswhatyouwouldgetifyoudidn'tusetheACMlibrariesandyoujustusedthestandardJavalibraries.Now,there'snoreasonwhyyoucan'tcontinuetousetheACMlibrariesafterthisclass.They'rejustanothersetoflibrariesthatwerewrittenbyagroupofpeoplethatyou'recertainlywelcometouse.
Sothere'snoreasonwhyyoushouldstopusingthem,buttherewereacoupleimportantissuesrelatedtostandardJava.Nowit'stimeforyoutoknow.Sothefirstthingthat'srelatedtothinkingaboutstandardJavaiswhenyou'rerunningyourprograms,whenyougointoEclipseandyouclickonthelittlerunningguytocompileyourprograms.Itgiveyoualistofwhatclassesyouactuallymightwanttorun.
Ifyouonlyhaveoneproject,youmayonlygetonechoice,butoneofthethingsyoukindofthinkaboutisinthenamesurferprogram,Iactuallyhavefourorfivedifferentclasses.Howcomeitalwaysknewwhichclasstorun?
HowcomeitalwaysknewthenamesurferclasswastheclassthatIactuallyshouldrun?
Anyonewanttoventureaguess?
Student:
[Inaudible].
Instructor(MehranSahami):
It'stheonlyclasswith[inaudible]whichisveryrelatedtoanunderlyingissue.It'stheonlyclassthatactuallywasextendingprograms.Sooneoftheextendedprograms,whatactuallywashappeningintheseACMlibrariesisyouweregettingamethodcalledmain.Mainisactuallytheplace?
you'reoldenoughtoseemain.MainisactuallythemethodatwhichJavaclassesactuallystartrunning.
Sooneofthethingsyoushouldthinknow,youneverwroteamethodcalledmain.Ineversawamethodcalledmain,andyou'retellingmethat'swhereJavaprogramsactuallystartrunning.Yeah,infactitis.It'sbecauseprogramsprovidedthismainmethodforyou.Whatthismainmethoddidintheprogramwasessentiallygettherestofyouprogramrunningbygettingafewthingssetupandthenkickingoffyourrunmethod.Soyoudidn'tactuallyneedtoworryaboutthis.
Butnowyou'resortofoldenoughtoactuallyseewhatthatmainmethodisallabout.Soifwethinkaboutwhatthismainmethoddoes,theheaderforthemainmethodisalsokindofweird.Thisispartofthereasonwhywenevershowedyouthemainmethodbefore.Theheaderforthemainmethodisactuallypublicstaticvoidmain,butwe'renotdoneyet.Mainactuallyhassomearguments.Ithasanarrayofstringscalledargsandarguments,andthensomethinginherehappensinsideofme.
Ifweshowedthistoyouonthefirstday,wewould'vehadtogothroughandexplainwhatallthesewordsmeantbeforeweexplainedwhatmainevenwas,beforeweexplainedhowyouwriteyourfirstprogram.Thatwould'vebeenapain.Nowwecanjusttellyou.Publicmainsisapublicmethod.Youknowthat.Youprobablyrecalltheotherpublicmethodsyou'vewritten.Staticmeansthatthisisactuallyamethodthatbelongstotheclass?
it'snotsomethingthatyouwouldactuallycallonaparticularobject.
Soyouneverhavesomeobject?
like,here'smyobjectX,andIcallX.main.Mainisjustsomethingthatgetscalled.It'saclassmethodasopposedtobeingamethodthatgetscalledonaninstance.Voidmeansitjustreturnsnothing.
Whatisgettingpassedinhereisanarrayofstrings.Whereisthatarrayofstringscomingfrom?
Thisactuallyharksbacktowhencomputersweren'tallniceandgraphicalandeverything.Whenpeoplewroteprograms,thewroteprogramandweretypingonwhat'scalledacommandline.Theywrongthenameoftheprogramout.Theyactuallytypedit,andthentheytypedabunchofthingsthattheywantedtobepassedintotheprogramsuchasinitialinformationtostartthatprogram.Thatwastheinitialthing,soifyouhadsomeprogramlikenamesurfer,youmightactuallystartoffbygivingthenameoftheprogram.
Thenafternamesurfer,youmightgiveitthenameofthedatafile,likedatadottext.Youmight'vegivenitsomeotherthingsaswellthatwereseparatedbyspaces.Thislistofstuffisessentiallywhatgetspassedinhereasarguments.They'restrings,andthisishowtheprogramwouldactuallyknowwhatcameinonthecommandlinewhentheprogramwaskickedoff.Java'snotthatoldofalanguage.Itsortofcamearoundandgainingpopularityin1995.Peopleweren'tdoingalotofthisin1995.Ialreadyhadmymouseandmyfoldersandallthisotherstuff,evenifyouweresixyearsold.Youprobablydid.
You'relike,Inevertypedthisstuff,sowhydoIcareaboutit?
ThereasonwhyJava'sderivedfromanotherlanguagecalledC,andthere'savariationcalledC++thatwascreatedwhenpeoplewerewritingprogramsinthedaysofyore.Thewholenotionofmainandhavingsomeargumentstogetpassedtomainkindofcamealongwiththebaggageofactuallyhavingaprogramlanguagethatmatchesthesamestyleprogramminglanguageswhentheydiddothis.
SoalotofthetimesinrealJavaprogramsthesedays,therearen'treallyanyarguments.Iftherearearguments,there'ssomesystemparametersorsomethinglikethat.Wedon'tusuallyworryaboutthem.SowhenyougoandlookatsomeotherJavaprogramthatisn'tusingtheACMlibrariesandyouseethismainthing,andyou'rewonderingwhatit'sallabout,youcanthinkofmainanalogouslytorun.It'sjustwherethewholetimeyou'vebeenthinkingofrunaswhereyou'reexecutionstarts,mainisreallywhereexecutionstarted.
Ifyouthinkaboutexecutionactuallystartedinmain,sohowdidthisthingactuallykickoffmyrunmethod?
Nowyou'resortofoldenoughtoseethat,too.Sowhatitactuallydid?
let'ssaythiswasthemainmethodissomethinglikenamesurfer.Sosomewhereinsideofaprogram,insideoftheACMlibrariesforprogram,wehadthismainmethodthatfiguredoutwhatthenameofyourclasswas.Essentially,ithadaone-linerinitthatwould'vebeenequivalenttothis.
Newnamesurferdotstartcards.Soit'saoneliner.Nowyouknowwhatthismeans.Whatwasitactuallydoing?
Whenmainst