资源描述:
《Java编程思想-毕业论文外文文献翻译》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
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“lowerthevolume,”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