外文翻译-JAVA介绍_第1页
外文翻译-JAVA介绍_第2页
外文翻译-JAVA介绍_第3页
外文翻译-JAVA介绍_第4页
外文翻译-JAVA介绍_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0外文原文IntroductiontoJavaJavaisdesignedtomeetthechallengesofapplicationdevelopmentinthecontextofheterogeneous,network-widedistributedenvironments.Paramountamongthesechallengesissecuredeliveryofapplicationsthatconsumetheminimumofsystemresources,canrunonanyhardwareandsoftwareplatform,andcanbeextendeddynamically.Javaoriginatedaspartofaresearchprojecttodevelopadvancedsoftwareforawidevarietyofnetworkdevicesandembeddedsystems.Thegoalwastodevelopasmall,reliable,portable,distributed,real-timeoperatingplatform.Whentheprojectstarted,C+wasthelanguageofchoice.ButovertimethedifficultiesencounteredwithC+grewtothepointwheretheproblemscouldbestbeaddressedbycreatinganentirelynewlanguageplatform.DesignandarchitecturedecisionsdrewfromavarietyoflanguagessuchasEiffel,SmallTalk,ObjectiveC,andCedar/Mesa.Theresultisalanguageplatformthathasprovenidealfordevelopingsecure,distributed,networkbasedend-userapplicationsinenvironmentsrangingfromnetwork-embeddeddevicestotheWorld-WideWebandthedesktop.ThedesignrequirementsofJavaaredrivenbythenatureofthecomputingenvironmentsinwhichsoftwaremustbedeployed.ThemassivegrowthoftheInternetandtheWorld-WideWebleadsustoacompletelynewwayoflookingatdevelopmentanddistributionofsoftware.Toliveintheworldofelectroniccommerceanddistribution,Javamustenablethedevelopmentofsecure,highperformance,andhighlyrobustapplicationsonmultipleplatformsinheterogeneous,distributednetworks.Operatingonmultipleplatformsinheterogeneousnetworksinvalidatesthetraditionalschemesofbinarydistribution,release,upgrade,patch,andsoon.Tosurviveinthisjungle,Javamustbearchitectureneutral,portable,anddynamicallyadaptable.1TheJavasystemthatemergedtomeettheseneedsissimple,soitcanbeeasilyprogrammedbymostdevelopers;familiar,sothatcurrentdeveloperscaneasilylearnJava;objectoriented,totakeadvantageofmodernsoftwaredevelopmentmethodologiesandtofitintodistributedclient-serverapplications;multithreaded,forhighperformanceinapplicationsthatneedtoperformmultipleconcurrentactivities,suchasmultimedia;andinterpreted,formaximumportabilityanddynamiccapabilities.Together,theaboverequirementscomprisequiteacollectionofbuzzwords,soletsexaminesomeofthemandtheirrespectivebenefitsbeforegoingon.WhatscompletelynewisthemannerinwhichJavaanditsrun-timesystemhavecombinedthemtoproduceaflexibleandpowerfulprogrammingsystem.DevelopingyourapplicationsusingJavaresultsinsoftwarethatisportableacrossmultiplemachinearchitectures,operatingsystems,andgraphicaluserinterfaces,secure,andhighperformance,WithJava,yourjobasasoftwaredeveloperismucheasieryoufocusyourfullattentionontheendgoalofshippinginnovativeproductsontime,basedonthesolidfoundationofJava.Thebetterwaytodevelopsoftwareishere,now,broughttoyoubytheJavalanguageplatform.VerydynamiclanguageslikeLisp,TCL,andSmallTalkareoftenusedforprototyping.Oneofthereasonsfortheirsuccessatthisisthattheyareveryrobustyoudonthavetoworryaboutfreeingorcorruptingmemory.Similarly,programmerscanberelativelyfearlessaboutdealingwithmemorywhenprogramminginJava,Thegarbagecollectionsystemmakestheprogrammersjobvastlyeasier;withtheburdenofmemorymanagementtakenofftheprogrammersshoulders,storageallocationerrorsgoaway.AnotherreasoncommonlygiventhatlanguageslikeLisp,TCL,andSmallTalkaregoodforprototypingisthattheydontrequireyoutopindowndecisionsearlyontheselanguagesaresemanticallyrich.Javahasexactlytheoppositeproperty:itforcesyoutomakeexplicitchoices.Alongwiththesechoicescomealotofassistanceyoucanwritemethodinvocationsand,ifyougetsomethingwrong,yougettoldaboutitatcompiletime.Youdonthavetoworryaboutmethodinvocationerror.2TheJavabeginnermustgrasp30basicconceptsBasicconcept1.InOOPtheonlyrelationsiswhattheobjectsinterface,suchasthecomputersellerheleavesaloneinternalstructureofelectricalsource,butheisonlyconcernedaboutthatwhetherthepowerwillbesuppliedtoyou,alsosolongasknowcanornotbutisnothowandwhy.Allproceduresaremakeupofcertainattributeandthebehaviorobject,thedifferentobjectvisitinvokesthroughthefunctioninvocation,betweentheobjectallintercommunionareinvokethroughthemethodinvocation,Byobjectdataencapsulation,enhancesreuserateverymuch.2.InOOPthemostimportantthoughtisclass,theclassisthetemplate,isablueprint,constructanobjectfromaclass,namelyconstructaninstanceoftheclass.3.Encapsulation:isthatcombinesthedataandthebehaviorinapackage)andhidesthedatatherealizationprocesstotheobjectuser,inanobjectdataiscalleditsinstancefield.4.Throughexpandsaclasstoobtainanewclassiscalledinheritance,butallclassesareconstructedbytheobjectsuperrootclassofexpansion,superrootclassofasfollowscanmaketheintroduction.5.Object3principalcharacteristicsBehavior-explainedthisobjectcanmakewhat.Tate-whentheobjectexertsthemethodobjectreflection.Dentity-andothersimilarbehaviorobjectsdiscriminationsymbols.Eachobjecthasonlyindentityandamongthreecharacteristicstheyaffectmutually.6.Relationsamongclasses:Use-a:DependentrelationHas-a:PolymerizationrelationIs-a:inheritorrelation-example:AclasshasinheritedBclass,thistimeAclassnotonlyhasBclassofmethod,butalsohasitsownmethod(Individualityexistsingeneralcharacter)37.Structureobjectusestructure:Structureproposing,thestructureisonespecialmethod,thestructureobjectandtoitsinitialization.Example:ADataclassofstructurecallsDataNewData()-structureanewobject,alsoinitializecurrenttime.Datahappyday=newData()-anobjectevaluatesanvariablehappyday,thusenablesthisobjecttobeusedmanytimes,herebestatedthecausevariableandtheobjectvariablearedifferent.Newreturnsthevalueisaquotation.Constructorcharacteristic:Theconstructormayhave0,oneormanyparametersTheconstructorandtheclasshavethesamenameAclassmayhavemanyconstructor.TheconstructorhasnotreturnedvalueTheconstructoralwaysbetogetherusedwiththenewoperator8.Overloading:Whenmanymethodshavethesamenamewhenincludesthedifferentparameter,thenhastheoverloadingWhichmethoddoesthecompilerhavetochooseinvokes.9.Package:Javaallowoneormanyclassestobecometogetherasgroup,iscalledpackage,toorganizingdutyeasily,thestandardJavastorehousedividesintomanypackagesJava.Langjava.Utiljava,netandsoon,thepackageislayeredandalljavapackagesareinjavaandinajavaxpackage.10.Extendablethought:permittoconstructnewclassonexistingclasses,whenyouextendtheclasswhichalreadyexisted,thenyoureusethisclassofmethodandthefield,atthesametimeyoumightaddthenewmethodandthefieldinthenewclass.11.Expandableclass:Theexpandableclassfullymanifestedis-atoextendtherelationsTheformis:Class(subclass)extends(baseclass).12.Multi-modality:Injava,theobjectvariableismulti-modalityButinjavadoesnotsupportmultipleextend.13.Dynamiccombine:themechanismofinvokingobjectmethodmechanism.1)compilerexaminesobjectstatementtypeandmethodname.2)thecompilerexaminesthatmethodinvokesparametertype.43)staticcombine:Ifthemethodtypeispriavtestaticthefinal,compilercanaccuratelyknowwhichmethodshouldinvoke.4)whentheprocedurerunsandusesdynamiccombinetoinvokeamethod,themethodeditionwhichthenhypothesizedmachinemustinvokextheobjectactualtypewhichaimsattomatch.5)dynamiccombine:isaveryimportantcharacteristic,itcancausetheproceduretochangeagainmayexpandbutdoesnotneedtotranslatehassavedthecode.14.Finalclass:Inordertopreventotherpeoplederivethenewclassfromyoursclass,thisclassiscannotexpanded.15.Thedynamicinvocationspendlongertimethanthestaticinvocationexpenditure.16.Abstractclass:Stipulatedormanyabstractmethodsclassofitselfmustdefineisabstract.Example:PublicabstractstringgetDescripition17.InJavaeachclassisbeextendedbyobjectclass.18.equalandtoStringmethodinobjectclass.Equalusesintestinganobjectiswhetherequalwithanotherobject.ToStringreturnstorepresentthisobjectthestringofcharacter,eachclasscannearlyoverloadingthismethod,inordertoreturnstothecurrentconditionthecorrectexpression.(ThetoStringmethodisaveryimportantmethod)19.Generalprogramming:Anyclassoftypeallvaluesallmayreplacewithaobjectclassofvariable.20.Thearraytabulates:TheArrayListdynamicarraytabulates,isaclassofstorehouse,definesinjava.Inuitlpackage,butautomaticcontrolarraysize.21.inclassandclassofobject,getclassmethodreturnstotheclasstypeanexample,whentheprocedurestartcontainscanincreaseinthemainmethodclass,hypothesizedconfidentialincreaseallclasseswhichheneeds,eachincreaseclassallmustincreasetheclasswhichitneeds.522.Theclass:classmightdynamicoperatethejavacodeforthecompilationtheproceduretoprovidetheformidablefunctionreflection,thisfunctionwasJavaBeansisspeciallyuseful,theusereflectedJavatobeabletosupporttheVBcedureofanalysisclassabilityiscalledthereflector,inJavatoprovidethisfunctionthepackagetocallJava.Lang.Thereflectreflectionmechanismisextremelyformidable.1)whenrunanalysisclassability.2)whenrunsearchesobservesaclassofobject.3)realizesthegeneralarrayoperationcode.4)providesthemethodobject.Butthismechanismmainlyaimsatthetoolbutnottheapplicationandtheprocedure.Inthereflectionmechanismmostimportantpartisthatpermitsclassthatyouinspectstructure.WithtoAPIincludes:Java.Lang.Reflect.Fieldreturnstothefield.Java.Reflect.Methodreturnstothemethod.Java.Lang.Reflect.Constructorreturnstotheparameter.Methodpointer:Javadoesnothavethemethodpointer,makesamethodaddressanothermethod,mayinvokeitinbehind,erface:shouldshowingclasscoulddowhatbutnottoassignhowtodo,aclassmayrealizeoneormanyinterfaces.24.Theinterfaceisnotaclass,butistoconformstoainterfacerequestclassofsetofstandard.Ifrealizesainterfacetoneed2steps:1)thestatementclassneedstorealizeassignstheinterface.2)providesintheinterfaceallmethodsdefinition.StatedaclassrealizesainterfacetoneedtousetheimplementskeywordsClassactionBimplementsComparableitsactionbneedstoprovidethe6CompareTomethod,theinterfaceisnottheclass,cannotuseanewexampleinterface.25.Aclassonlythenasuperclass,butaclasscanrealizemanyinterfaces.InaJavaimportantinterface:Cloneable.26.Theinterfaceandcall-back:toprogramsacommonlyusedpatterniscall-back,inthepattern,youmayreferwhenthisclassofpatternsettledspecifictimeoccursreturnstoadjustsontheobjectthemethod.Example:ActionListenerinterfacemonitor.SimilarAPIincludes:Java.Swing.JOptionPaneJava.Swing.TimerJava.Awt.Tookit27.Objectclone:Theclonemethodisaobjectprotectionmethod,thismeantyourcodecannotsimpleinvokeit.28.Innerclassaninnerclassdefinitionisthedefinitioninanotherclass.Thereasonis:1)aninnerclassobjectcanvisitfoundsitsobjectrealization,includingprivatedata.2)aboutotherclassesinthesamepackageinthat,innerclasscanbehided.3)theanonymousinnerclassmaytheveryconvenientdefinitionaccent.In4)usesthecategorytobepossibletheextremelyconvenientcompilationeventdriver.29.Agentclass(proxy):1)appointingallcodesthatinterfacesrequest2)allmethods(toStringequals)thatobjectclassdefine30.Datatype:Javaiskindofemphasizingtypelanguage,eachvariableallmustbedeclareditstypesatfirst,injavaaltogetherhas8basictypes.fourkindsarethelong,twokindsarethefloat,oneisthechar,beingusedintheUnicodecodechar,Boolean.1.javaissimpleJavaandC+areverysimilar,butmuchsimpler.Allthehigh-levelprogramming7languagefeatures,isnotabsolutelynecessaryhavebeendeleted.Forexample,Javadoesnotoverloadoperator,thetitleofthedocument,pre-processing,computingpointer,thestructureofthejoint,multi-dimensionalarray,templatesandimplicittypeconversion.IfyouknowalittleC,C+orPascal,youwillsoonmasterJava.HereisasimpleprocedureJavaHelloWorld:publicclassHelloInternet(publicstaticvoidmain(Stringargv)(System.out.println(HelloIn-ternet!)2.Javaisobject-orientedJavaisanobject-orientedprogramminglanguage.Inadditiontothesimpletypes,suchasdigitalandBooleanoperatorsinaddition,Javaisanobjectofmost.Aswithanyobject-orientedlanguages,Javacodealsoorganizedbycategory.Eachcategoryprovidesadefinitionoftheobjectbehavior.Anothertypeofsuccessioncanbeakindofbehavior.Inthecategoryoftherootlevel,oftenthetargetcategory.Javasupportforthesingletypeofinheritedhierarchy.Thismeansthateachcategorycanonlyinheritoneothercategory.Someofthelanguagetoallowmultipleinheritance,butitmaycauseconfusionandunnecessarilycomplicatedlanguage.Forexample,imaginethatanobjectwouldinherittwocompletelydifferentcategory.Javaalsosupportsthekindofsummaryoftheinterface.Thisallowsprogrammerstodefinetheinterfacemethods,anddonothavetorushimmediatelytodeterminethemethodstoachieve.Atypeofinterfacecanbeanumberofpurposesinordertotrulymulti-inheritanceofanumberofadvantages.Theimplementationofanobjectcanbeanynumberofinterfaces.IDLinterfaceandJavainterfaceverysimilar.VeryeasytosetupIDLJcompiler.Inotherwords,JavacanbeusedtocreateaCORBAobjectsystemdistributedobjectsystem.IntheviewofmanycomputersystemsuseIDLinterfaceandCORBAobjects,suchcompatibilityisimportant.3.JavaisatypeofstaticInaJavaprogram,itisessentialtothedefinitionusedbythetarget(numberof8characters,suchasanarray)type.Thiswillhelpprogrammersquicklyfoundbecausetheprocedurewhenthecompilercandetectthetypeoferror.However,JavaSystemobjectsarealsodynamictypes.Arequirementforthetypeofdynamicisoftenpossible,soprogrammerscanwritetheproceduresfordifferenttypesofobjectstododifferentthings.4.IsaJava-basedcompilerWhenrunningJavaprograms,whichwerefirstcompiledintobytecode.Bytecodeisverysimilartothemachineinstructions,soJavaprogramisveryefficient.However,thebytecodedoesnotspecificallyforaparticularmachine,sononeedtorecompileJavaprogramcanbeinmanydifferentcomputerimplementation.Javasourcecodefileswerecompiledintoacategory,whichisequivalenttoprocessbytecodeperformance.InaJavaclassfile,andanexampleforallofthevariablesareinthelightof,andforthefirsttimeintheimplementationofthecodeberesolved.Thismakesthecodemorecommonandmoreeasilysubjecttorevision,butstillhigh.5.JavaisarchitectureneutralJavalanguageisthesameforeachcomputer.Forexample,simpletypesarethesame:32-bitintegeralways,always64-bitlongintegers.Itisstrange,suchasCandC+programminglanguage,andsofashionableitisnotthecase.Asaresultoftheselanguagessothedefinitionoffreedom,eachofthecompileranddevelopmentenvironmentwillbedifferent,sothatthisprocessnuisancebecomeatransplant.Javaprogramscaneasilygainaccesstotransplants,andthereisnoneedtore-compile.6.JavaisasoundJavaprogramcannotbecausedbythecollapseofthecomputer.Javacarefultestingofthesystemmemoryofeachvisit,makesureitislegitimateandwillnotcauseanyproblems.However,eveniftheJavaprogrammayalsobewrong.Ifthereissomekindofunexpectedthings,theprocesswillnotcollapse,andtoabandontheexception.Proceduresforsuchanexceptionwouldbefoundtoaddressthem.Traditionalcomputerprogramscanaccessthefullmemory.May(unconsciously)toamendanyofthevalueofmemory,whichwillcauseproblems.JavaprogramcanonlyaccessmemorytoallowthemaccesstothosepartsoftheJavaprogramcannotmodifyitdoesnotseektochangethe9value.7.JavaisacompactAstheJavaisdesignedtorunonasmallcomputer,asaprogramminglanguageforthesystemisrelativelysmall.Iteffectivelyinmorethan4MBofRAMtorunonPCmachine.JavatranslatoroccupiedbyonlyafewhundredKB.ThistranslatorfortheJavaplatformindependenceandportabilityisreliable.DuetoJavaisverysmall,itisaverysmallcomputermemory,suchastheJava-basedPC,aswellastelevisionsets,ovens,telephoneandhomecomputer,andsoon,itisideal.8.Javaisamulti-threadedJavaprogramcanrunmorethanonethread.Forexample,itcanbeathreadinatime-consumingtocompletethecalculation,andotheruserstointeractwiththethreadsofdialogue.Therefore,usersdonothavetostopworking,waitingfortheJavacomputingtime-consumingprocess.Inthemulti-threadedprogrammingenvironment,itisoftendifficultbecausemanythingsmayoccuratthesametime.However,Javaprovideseasy-to-usefeaturessimultaneously,sothattheprogrammingeasier.9.ThreadLocalperformanceDesignandonlyaddedinversion1.2oftheJavaplatform.Inmanyways,ThreadLocalisstillaworkinprogress;itwasrewrittenforversion1.3andagainforversion1.4,bothtimestoaddressperformanceproblems.InJDK1.2,ThreadLocalwasimplementedinamannerverysimilartoListing2,exceptthatasynchronizedWeakHashMapwasusedtostorethevaluesinsteadofaHashMap.(UsingWeakHashMapsolvestheproblemofThreadobjectsnotgettinggarbagecollected,atsomeadditionalperformancecost.)Needlesstosay,theperformanceofThreadLocalwasquitepoor.TheversionofThreadLocalprovidedwithversion1.3oftheJavaplatformissubstantiallybetter;itdoesnotuseanysynchronizationandsodoesnotpresentascalabilityproblem,anditdoesnotuseweakreferenceseither.Instead,theThreadclasswasmodifiedtosupportThreadLocalbyaddinganinstancevariabletoThreadthatholdsaHashMapmappingthread-localvariablestotheirvaluesforthecurrentthread.Becausethe10processofretrievingorsettingathread-localvariabledoesnotinvolvereadingorwritingdatathatmightbereadorwrittenbyanotherthread,youcanimplemntThreadLocal.get()andset()withoutanysynchronization.Also,becausethereferencestotheper-threadvaluesarestoredintheowningThreadobject,whentheThreadgetsgarbagecollected,socanitsper-threadvalues.Unfortunately,evenwiththeseimprovements,theperformanceofThreadLocalunderJava1.3isstillsurprisinglyslow.MyroughbrunningtheSun1.3JDKonatwo-processorLinuxsystemshowthataThreadLocal.get()operationtakesabouttwiceaslongasanuncontendedsynchronization.ThereasonforthispoorperformanceisthattheThread.currentThread()methodisquiteexpensive,accountingformorethantwo-thirdsoftheThreadLocal.get()runtime.Evenwiththeseweaknesses,theJDK1.3ThreadLocal.get()isstillmuchfasterthanacontendedsynchronization,soifthereisanysignificantchanceofcontentionatall(perhapsthereisalargenumberofthreads,orthesynchronizedblockisexecutedfrequently,orthesynchronizedblockislarge),ThreadLocalmaystillbemoreefficientoverall.UnderthenewestversionoftheJavaplatform,version1.4b2,performanceofThreadLocalandThread.currentThread()hasbeenimprovedsignificantly.Withthesenewimprovements,ThreadLocalshouldbefasterthanothertechniquessuchaspooling.Becauseitissimplerandoftenlesserror-pronethanthoseothertechniques,itwilleventuallybediscoveredasaneffectivewaytopreventundesiredinteractionsbetweenthreads.10.ThebenefitsofThreadLocalThreadLocaloffersanumberofbenefits.Itisoftentheeasiestwaytoastatefulclassthread-safe,ortoencapsulatenon-thread-safeclassessothattheycansafelybeusedinmultithreadedenvironments.UsingThreadLocalallowsustobypassthecomplexityofdeterminingwhentosynchronizeinordertoachievethread-safety,anditimprovesscalabilitybecauseitdoesntrequireanysynchronization.Inadditiontosimplicity,usingThreadLocaltostoreaper-

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论