資源描述:
《Java編程思想-畢業(yè)論文外文文獻(xiàn)翻譯》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、ThinkinginJavaAlthoughitisbasedonC++,Javaismoreofa“pure”object-orientedlanguage.BothC++andJavaarehybridlanguages,butinJavathedesignersfeltthatthehybridizationwasnotasimportantasitwasinC++.Ahybridlanguageallowsmultipleprogrammingstyles;thereasonC++ishybridistosupportbackwardcompatibil
2、itywiththeClanguage.BecauseC++isasupersetoftheClanguage,itincludesmanyofthatlanguage’sundesirablefeatures,whichcanmakesomeaspectsofC++overlycomplicated.TheJavalanguageassumesthatyouwanttodoonlyobject-orientedprogramming.Thismeansthatbeforeyoucanbeginyoumustshiftyourmindsetintoanobjec
3、t-orientedworld(unlessit’salreadythere).ThebenefitofthisinitialeffortistheabilitytoprograminalanguagethatissimplertolearnandtousethanmanyotherOOPlanguages.Inthischapterwe’llseethebasiccomponentsofaJavaprogramandwe’lllearnthateverythinginJavaisanobject,evenaJavaprogram.Eachprogramming
4、languagehasitsownmeansofmanipulatingdata.Sometimestheprogrammermustbeconstantlyawareofwhattypeofmanipulationisgoingon.Areyoumanipulatingtheobjectdirectly,orareyoudealingwithsomekindofindirectrepresentation(apointerinCorC++)thatmustbetreatedwithaspecialsyntax?AllthisissimplifiedinJava
5、.Youtreateverythingasanobject,usingasingleconsistentsyntax.Althoughyoutreateverythingasanobject,theidentifieryoumanipulateisactuallya“reference”toanobject.Youmightimaginethissceneasatelevision(theobject)withyourremotecontrol(thereference).Aslongasyou’reholdingthisreference,youhaveaco
6、nnectiontothetelevision,butwhensomeonesays“changethechannel”or“l(fā)owerthevolume,”whatyou’remanipulatingisthereference,whichinturnmodifiestheobject.Ifyouwanttomovearoundtheroomandstillcontrolthetelevision,youtaketheremote/referencewithyou,notthetelevision.Also,theremotecontrolcanstandon
7、itsown,withnotelevision.Thatis,justbecauseyouhaveareferencedoesn’tmeanthere’snecessarilyanobjectconnectedtoit.Soifyouwanttoholdawordorsentence,youcreateaStringreference:Buthereyou’vecreatedonlythereference,notanobject.Ifyoudecidedtosendamessagetosatthispoint,you’llgetanerror(atruntim
8、e)becausesis