2025年畢業(yè)設(shè)計(jì)論文_第1頁(yè)
2025年畢業(yè)設(shè)計(jì)論文_第2頁(yè)
2025年畢業(yè)設(shè)計(jì)論文_第3頁(yè)
2025年畢業(yè)設(shè)計(jì)論文_第4頁(yè)
2025年畢業(yè)設(shè)計(jì)論文_第5頁(yè)
已閱讀5頁(yè),還剩57頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

參考文獻(xiàn)[1]百度百科.Java語(yǔ)言的特點(diǎn)和優(yōu)勢(shì)[EB/OL]./view/edd3e74ffe4733687e21aac9.html[2]榮欽科技.Java2游戲設(shè)計(jì)[M].北京.清華大學(xué)出版社.2004.[3]程成.軟件工程[M].北京.機(jī)械工業(yè)出版社.2003.[4]袁海燕,王文濤.Java實(shí)用程序設(shè)計(jì)100例[M].北京.人民郵電出版社.2005.[5]王伯欣.J2ME無(wú)線.Java[M].北京.應(yīng)用開(kāi)發(fā)電子工業(yè)出版社.2004.[6]曹瑩,苗志剛,趙秀明.淺談Java優(yōu)勢(shì)[J].中國(guó)科技信息,2006.[7]邵敏敏,陳德平.解析Java的多線程機(jī)制[J].電腦知識(shí)與技術(shù).2006.[8]朱平.Java程序設(shè)計(jì)教學(xué)[J].湖北教育學(xué)院學(xué)報(bào).2006.[9]猛偉君.李龍海.付少鋒.周利華.基于VC++和JAVA的多線程設(shè)計(jì)和實(shí)現(xiàn)[J].2006.[10]秦琴.Java語(yǔ)言的異常處理設(shè)計(jì)[J].中國(guó)科技信息.2006.[11]倪道義.手機(jī)游戲架構(gòu)分析[J].科技論壇,2011,(9):90.[12]BennySkogberg.AndroidAppliactionDevelopment[D].Sweden:MalmoUniversity,2010.[13]CayS.Horstmann,GaryCornell.IntroductiontoJava[M].London:Macmillan.2006.[14]BruceEckel.ThinkinginJava[M].London:PrenticeHallPTR.2003.

致謝花有重開(kāi)日,人無(wú)再少年。隨著畢業(yè)論文的提交,大學(xué)生活畫(huà)上了完美的句號(hào)。但這同時(shí)也象征著新的開(kāi)始,自己將獨(dú)自走向新的臺(tái)階,邁向人生征程新的開(kāi)始?;叵氪髮W(xué)四年的學(xué)習(xí)生活,許多事情浮現(xiàn)腦海,仿佛前不久才發(fā)生。剛進(jìn)入大學(xué)校園時(shí)與父母歡樂(lè)和興奮的場(chǎng)景還歷歷在目。一切都是那么新鮮,那么富有吸引力。有快樂(lè)也有艱辛,有收獲也有失落。感謝軟件學(xué)院給予幫助過(guò)我的所有老師。18班的友情也同樣終身難忘難忘,是你們陪我共同度過(guò)了人生重要的一段路程,無(wú)論將來(lái)走到哪里,你們都是我人身中珍貴的回憶。我要感謝指導(dǎo)教師和杰普老師。這個(gè)論文是在她們的悉心指導(dǎo)和熱情幫助下完成的,老師們認(rèn)真負(fù)責(zé)的工作態(tài)度,精益求精的工作作風(fēng)以及平易近人的人格魅力都使我受益匪淺。對(duì)于在畢業(yè)設(shè)計(jì)完成過(guò)程中遇到的問(wèn)題,她們無(wú)論在理論上還是在實(shí)踐中,都對(duì)我進(jìn)行了認(rèn)真的指導(dǎo),使我的專業(yè)實(shí)踐能力得到很大提高,這對(duì)于我以后的學(xué)習(xí)和工作都有幫助。在此,特別向指導(dǎo)老師表示衷心的感謝,請(qǐng)兩位老師接受我最誠(chéng)摯的敬意!謝謝你們認(rèn)真輔導(dǎo),使我能夠順利完成畢業(yè)設(shè)計(jì)的開(kāi)發(fā)工作。同時(shí)也要感謝幫助過(guò)我的同學(xué)們,在略微乏味的學(xué)海中,讓我體會(huì)到友情的無(wú)價(jià)。同時(shí),我也想感謝我的家人,他們不僅幫助我茁壯成長(zhǎng)、給予我關(guān)懷和照顧,而且,是他們培養(yǎng)了我對(duì)科學(xué)文化知識(shí)的興趣。沒(méi)有他們,就沒(méi)有我今天的成績(jī)。在今后的日子里,我想說(shuō),我會(huì)一如既往的認(rèn)真下去,將自己在學(xué)生階段所學(xué)知識(shí)運(yùn)用到社會(huì)實(shí)踐當(dāng)中,我會(huì)不忘初心,用自己的努力報(bào)答你們!由于本人水平有限以及時(shí)間緊湊,本文可能會(huì)出現(xiàn)一些不足之處,這這里,我懇請(qǐng)各位老師給予指正和幫助。附錄200334thAnnualIEEEComputerSoftwareandApplicationsConferenceWorkshopsCS1andCS2:writecomputergamesinJavaShinNAKAJIMAKeijiHOKAMURANaoyasuUBAYASHINationalInstituteofInformaticsKyushuUniversityKyushuUniversityTokyo,JapanFukuoka,JapanFukuoka,JapanEmail:nkjm@nii.ac.jpEmail:polikeiji@Email:ubayashi@Abstract—Javahasbecomeahugeandcomplextechnologyplatform,fordevelopers,inordertobettermastertheJavatechnology,in-depthunderstandingoftheunderlyingtechnicalprocessingdetailsisessential.Themasteryofthecoreconceptsandideascanhelpuslearnbyanalogy,helpustoenhanceourunderstandingoftheentireJavaplatform.HerearetheJavatechnologyplatformdescribedinseveralcoreconcepts,whichcontainstheideaswillhelpusamoreprofoundunderstandingofJavatechnology.Keywords:Java;VirtualMachine;Classfile;API;I.INTRODUCTIONJavaisanobject-orientedprogramminglanguage,notonlyabsorbthevariousadvantagesoftheC++language,butalsotoabandontheC++difficulttounderstandthemulti-inheritance,pointerandotherconcepts,sotheJavalanguagehasapowerfulandeasytousetwofeatures.Javalanguageasastaticobject-orientedprogramminglanguagerepresentatives,anexcellentrealizationoftheobject-orientedtheory,allowingprogrammerstoelegantwayofthinkingcomplexprogramming[1].Javahasthecharacteristicsofsimplicity,object-oriented,distributed,robustness,security,platformindependenceandportability,multi-thread,anddynamic[2].Javacanwritedesktopapplications,Webapplications,distributedsystemsandembeddedsystemapplications[3].II.JAVAVIRTUALMACHINEThemaintaskoftheJavavirtualmachineistoinstalltheclassfileandexecutethebytecode.TheJavavirtualmachinecontainsaclassloaderthatcanloadclassfilesfromprogramsandAPIs.OnlythoseclassesthatarerequiredbytheprogramtobeexecutedintheJavaAPIwillbeloaded.Bytecodeisexecutedbytheexecutionengine.IndifferentJavavirtualmachines,theexecutionenginemaybeverydifferent.Inthevirtualmachineimplementedbythesoftware,thesimplestexecutionengineisaone-timeinterpretationofthebytecode.Anotherexecutionengineisfaster,butalsoconsumesmorememory,called"just-in-timecompiler".Inthiscase,thefirstbytecodetobeexecutedwillbecompiledintothelocalmachinecode.Thecompiledlocalmachinecodeiscachedandcanbereusedwhenthemethodiscalledlater.Thethirdexecutionengineistheadaptiveoptimizer.Inthisway,thevirtualmachinebeginsbyinterpretingthebytecode,butitmonitorstheactivityoftherunningprogramandrecordsthemostfrequentlyusedcodesegments.Whentheprogramisrunning,thevirtualmachineonlycompilesthemostfrequentlycompiledcodeintolocalcode,andtheothercodeiskeptveryfrequentlyandiskeptasbytecode-thevirtualmachinecontinuestoexplainthem.AnadaptiveoptimizerallowstheJavavirtualmachinetoperformoptimizedlocalcodein80%to90%ofthetime,butonly10%to20%ofthecodethataffectsperformance.WhentheJavavirtualmachineisimplementedbythesoftwareonthehostoperatingsystem,theJavaprograminteractswiththehostbycallingthenativemethod.TherearetwomethodsinJava:Javamethodsandlocalmethods.JavamethodiswrittenbytheJavalanguage,compiledintobytecodefiles,storedintheclassfile.Localmethodsarewritteninotherlanguages(suchasc,c++orassemblylanguage),compiledintoprocessor-relatedmachinecode.Localmethodsarestoredinthedynamiclinklibrary,theformatisproprietarytoeachplatform.WhenaJavaprogramcallsalocalmethod,thevirtualmachineloadsthedynamiclibrarythatcontainsthelocalmethodandcallsthemethod.ThelocalmethodistoconnecttheJavaprogramandtheunderlyinghostoperatingsystemconnectionmethod.Accesstheunderlyingoperatingsystemresources.AlocalNativeinterface(JNI)-allowslocalmethodstorunonanyJavaplatformimplementationofaparticularhostsystem.Ifyouwanttouseresourcesonspecifichost,theycannotaccessfromtheJavaAPI,youcanwriteaplatform-relatedJavaprogramtocallthelocalmethod.Ifyouwanttoensurethattheprogramplatformindependence,thenonlythroughtheJavaAPItoaccesstheunderlyingsystemresources.Figure1JavaVirtualMachineWorkingprincipleIII. CLASSLOADERARCHITECTUREJavaapplicationcanusetwoclassloaders:the"bootstrap"classloaderandtheuser-definedclassloader.Startingtheclassloader(whichisuniqueinthesystem)ispartoftheJavaVirtualMachineimplementation.Thebootclassloadertypicallyusesadefaultwaytoloadclassesfromalocaldisk,includingtheJavaAPIclasses(thebootloaderisalsoknownastheoriginalclassloader,thesystemclassloader,orthedefaultclassloader).Javaapplicationscaninstalluser-definedclassloadersatruntime,andthisclassloadercanuseacustomwaytoloadclasses.Forexample,downloadtheclassfilefromthenetwork.Althoughthebootloaderisanessentialpartofthevirtualmachineimplementationandtheuser-definedclassloaderisnot,theuser-definedclassloadercanbewritteninJavaandcanbecompiledintoaclassfilethatcanbeloadedbyavirtualmachine.Asinstantiatedasotherobjects.Becausethereisauser-definedclassloader,sodonothavetocompilethetimetoknowtherunningJavaapplicationswilleventuallyjoinalltheclass.User-definedclassloadersmakeitpossibletorunextendedJavaapplications.Whenitisrunning,theapplicationcansolvewhichadditionalclassesitneedstobeabletodecidewhethertouseoneormoreuser-definedclassloaderstoload.SinceclassloadersarewritteninJava,classloadingisdonewithanystylethatcanbeexpressedinJavacode.Theseclassescanbedownloadedoverthenetwork,canbeobtainedfromsomedatabases,andcanevenbedynamicallygenerated.Wheneachclassisloaded,theJavavirtualmachinemonitorstheclassandseeswhetheritisloadedbytheclassloaderorbytheuser-definedclassloader.Whentheloadedclassreferencesanotherclass,thevirtualmachineloadsthereferencedclassusingtheclassloaderthatloadsthefirstclass.Forexample,ifavirtualmachineloadsaVolcanoclassusingaspecificclassloader,itwillusetheclassloadertoloadallclassesusedbytheVolcanoclassSincetheJavavirtualmachinetakestheloadoftheclassinthisway,theloadedclasscanonlyseeotherclassesthatareloadedbythesameclassloaderbydefault.Inthisway,theJavaarchitectureallowsyoutocreatemultiplenamespacesinaJavaapplication.EachclassloaderintheruntimeJavaprogramhasitsownnamespace.Javaapplicationscancreatehowmany(orhowmany)classesthatareloadedbydifferentclassloadersarestoredindifferentnamespaces,andtheycannotaccesseachotherunlesstheapplicationexplicitlyallowsittodoso.WhenwritingaJavaapplication,classesthatareloadedfromdifferentsourcefilescanbeseparatedindifferentnamespaces.Inthisway,youcanusetheJavaclassloaderarchitecturetocontroltheinteractionbetweenthecodeloadedinanyofthedifferentsourcefiles,inparticular,topreventmaliciouscodefromgainingaccesstoordamagetogoodwillcode.TheWebbrowserisanexampleofadynamicextensionthatusesauser-definedclassloadertodownloadclassfilesforJavaappletsfromthenetwork.TheWebbrowserusesaJavaapplicationtoinstalltheuser-definedclassloader.Thisuser-definedclassloaderisoftenreferredtoastheJavaAppletclassloader,whichknowshowtorequestaclassfilefromanHTTPserver.JavaAppletcanbeusedasadynamicextensionoftheexample,becausetheJavaapplicationdoesnotknowwhenitwillstartfromthenetworktodownloadthebrowserrequestclassfile.OnlywhenthebrowserencounteredaJavaappletpage,itwasdecidedwhethertheneedtodownloadclassfiles.Webbrowser-initiatedJavaapplicationstypicallycreatedifferentuser-definedclassloadersforeachnetworkaddressthatprovidesclassfiles,sodifferentuser-definedclassloadersloaddifferentsourceclassfiles.WhichcanbeplacedseparatelyunderthedifferentnamespaceoftheJavahostapplication.BecausedifferentJavaappletfilesareplacedindifferentnamespaces,maliciousJavaappletcodedoesnotdirectlyaccessclassfilesdownloadedfromotherplaces.Thiscanlimitorpreventmutualaccessbetweencodefromdifferentsources.Figure2 classloaderarchitectureVI.JAVACLASSFILEJavaclassfilesmakeJavamoresuitableforthenetworkintermsofplatformindependenceandnetworkmobility.ItstaskinplatformindependenceistoprovideJavaprogramswithbinaryformsofservicesthatareindependentoftheunderlyinghostplatform.ThisapproachbreaksthetraditionofCorC++andotherlanguages,andprogramswritteninthesetraditionallanguagesareusuallycompiledfirstandthenconnectedintoseparate,binaryfilesthatspecificallysupportspecifichardwareplatformsandoperatingsystems.Often,binaryexecutablesonaplatformcannotworkonotherplatforms.JavaclassfilescanrunonanyhardwareplatformthatsupportstheJavavirtualmachineandthebinaryfilesontheoperatingsystem.Figure3javaclassfileWhencompilingandconnectingaC++program,theresultingexecutablebinariescanonlyberunonthespecifiedhardwareplatformandoperatingsystembecausethebinariescontainthemachinelanguageforthetargetprocessor.TheJavacompilertoJavasourcefileinstructionstranslatedintobytecode,thisbytecodeistheJavavirtualmachine"machinelanguage."Classfilesaredesignedsothattheycanbequicklytransmittedoverthenetwork.Second,becausetheJavaprogramisdynamicallylinkedanddynamicallyexpanded,classfilescanbedownloadedwhenneeded.ThisfeatureallowsJavaapplicationstoschedulethetimetodownloadclassfilesfromthenetwork,therebyminimizingend-userlatency.Figure4javaclassV.APIAPI(ApplicationProgrammingInterface)isapre-definedfunction,thepurposeistoprovideapplicationsanddevelopersbasedonasoftwareorhardwaretoaccessasetofroutines,withouthavingtoaccessthesourcecode,orunderstandtheinternalworkMechanismdetails.ThestandardscurrentlyappliedtotheAPIincludetheANSIstandardSQLAPI.Therearealsosomeothertypesofstandardsarestillbeingdeveloped.APIcanbeappliedtoallcomputerplatformsandoperatingsystems.TheseAPIsconnectdataindifferentformats.Eachdataformatrequiresdifferentdatacommandsandparameterstoachievethecorrectdatacommunication,butatthesametimewillproducedifferenttypesoferrors.Therefore,inadditiontotheknowledgerequiredtoperformdatasharingtasks,thesetypesofAPIsmustalsoaddressmanynetworkparameterproblemsandpossibleerrorconditions,thatis,eachapplicationmustknowwhetherithasstrongperformancesupportforinter-programcommunication.Onthecontrary,sincethisAPIonlyhandlesaninformationformat,theinformationdeliveryAPIinthiscaseonlyprovidessmallercommands,networkparameters,andsubsetoferrorconditions.Becauseofthis,deliveryAPIapproachgreatlyreducesthecomplexityofthesystem,sowhentheapplicationneedstoachievedatasharingthroughmultipleplatforms,theuseofinformationdeliveryAPItypeistheidealchoice.Informationdelivery:referstotheloosecouplingortightcouplingbetweentheapplicationofsmallformatinformation,throughthedirectcommunicationbetweenprogramstoachievedatasharing.ThestandardscurrentlyappliedtotheAPIincludetheANSIstandardSQLAPI.Therearealsosomeothertypesofstandardsarestillbeingdeveloped.APIcanbeappliedtoallcomputerplatformsandoperatingsystems.TheseAPIsconnectdataindifferentformats.Eachdataformatrequiresdifferentdatacommandsandparameterstoachievethecorrectdatacommunication,butatthesametimewillproducedifferenttypesoferrors.Therefore,inadditiontotheknowledgerequiredtoperformdatasharingtasks,thesetypesofAPIsmustalsoaddressmanynetworkparameterproblemsandpossibleerrorconditions,thatis,eachapplicationmustknowwhetherithasstrongperformancesupportforinter-programcommunication.Onthecontrary,sincethisAPIonlyhandlesaninformationformat,theinformationdeliveryAPIinthiscaseonlyprovidessmallercommands,networkparameters,andsubsetoferrorconditions.Becauseofthis,deliveryAPIapproachgreatlyreducesthecomplexityofthesystem,sowhentheapplicationneedstoachievedatasharingthroughmultipleplatforms,theuseofinformationdeliveryAPItypeistheidealchoice.Informationdelivery:referstotheloosecouplingortightcouplingbetweentheapplicationofsmallformatinformation,throughthedirectcommunicationbetweenprogramstoachievedatasharingRemoteProcedureCall(RPC):implementscommunicationbetweenprogramsbyactingonashareddatabufferStandardQueryLanguage(SQL):isthestandardaccesstothedataquerylanguage,throughthecommondatabasetoachievedatasharingbetweenapplications.FileTransfer:FileTransferDatasharingbetweenapplicationsisachievedbysendingformattedfiles.Informationdelivery:referstotheloosecouplingortightcouplingbetweentheapplicationofsmallformatinformation,throughthedirectcommunicationbetweenprogramstoachievedatasharing.Figure5javarelationshipdiagramofthecollectionclassBeforeaplatformcanevensupportJavaprograms,theAPImustbeexplicitlyimplementedonthisparticularplatform.Toaccessthelocalresourcesonthehost,theJavaAPIcallsthelocalmethod.SinceJavaAPIclassfilescalllocalmethods,Javaprogramsdonotneedtocallthemagain.Inthisway,theJavaAPIclassfileprovidesJavaprogramswithplatform-independent,standardinterfacesfortheunderlyinghost.ForJavaprograms,theJavaAPIhasthesameperformanceandpredictablebehavior,regardlessoftheplatform.ItisbecausetheJavavirtualmachineandtheJavaAPIareexplicitlyimplementedoneachparticularhostplatform,sotheJavaprogramitselfcanbecomeaplatform-independentprogramTheJavaAPIalsocontributestotheJavasecuritymodel.WhentheJavaAPImethodperformsanypotentiallydangerousoperation(suchasmakingalocaldiskwrite),itchecksthroughtheaccesscontrollertoverifythatitisauthorized.Theaccesscontrollerisaclassthatisusedtoperformastackcheckandhasdecidedwhetherornottoallowanoperation.VI.JAVACHARACTERISTICSJavahasthefollowingcharacteristics:Simple:OneoftheprinciplesofJavaistobuildasimpleandeasy-to-usesystemthatallowsuserstostartdesigningprogramswithouthavingtobetrained,soJava'ssyntaxisasmuchaspossiblethecurrentprogramissimilartomanydesignershaveusedCandC++languages.Also,JavaremovedC,andC++manyrarelyused,difficulttounderstandoroftenconfusedfunction,alotofinheritance,pointerandsoon.Object-OrientedObject-orientedObject-orientedistheconceptandtechnologywidelyusedintheinformationindustryinrecentyears.Ithasmanygoodfeatures.Objectencapsulationcanmaketheobjectinterfacedefinitionclear;inheritancecanincreasethereusabilityofthesoftware,contributetoclassificationandtemplatedesign.Implementingtheobject-orientedconceptanditsvariousgoodfeaturesisoneofthedesignconceptsofJava.Thedevelopmentofdistributedcomputernetworksmakestheapplicationofinformationtowardsadistributedenvironment,Sothemoderninformationdevelopmentlanguageandtheenvironmentshouldbewiththedistributedcharacteristicsandfunctions.Javahasanetwork-enabledlibrarythatincludestheabilitytointegratewithTCP/IPnetworkcommunicationprotocolssuchasHTTPandFTP.4.RobustTheprogramwrittenbyJavaiscapableofrunninginavarietyofsituationsandmusthavehighstability.Javainthedevelopmentofthetimetoaddtopreventthememoryisoverwrittenanddatacorruptionrelatedprocessingmechanism.Security(Java)isdesignedforuseinthenetworkanddistributedenvironment,sosecurityisaveryimportantconsideration.Javahasanumberofsimpletocomplexsecuritymeasures,caneffectivelypreventtheinvasionanddestructionofthevirusoccurred.ArchitectureNeutralTherearemanydifferenttypesofcomputersonthenetwork,andthereareverydifferentdifferencesfromthecentralprocessortotheoperatingsystem.Soitisquitedifficulttomaketheapplicationrunoneverymachine.Forthispurpose,theJavacompilercanproduceastructure-neutralobjectcodefileformat-ByteCode.Thisbytecodecanrunonmanydifferentcomputers.7.MultithreadingMultithreadingisoneofthetoolsnecessarytodevelopcomplexandpowerfulprograms,andJavaalsosupportsthisimportantfeature.Sourcefile:Useatexteditor,suchasEditorNotepadtowritesourcefiles.unavailableWordeditorbecauseitcontainsinvisiblecharacters.Willbecompiledsourcefilessaved,thesourcefileextensionmustbeJava.Compiler:Thesourcefileiscompiledbythecompiler(Javac.exe)togenerateabytecodefilewitha.Classextension.Bytecodefilesarecomposedofplatform-independentbinarycode,whichisinterpretedbytheinterpreterasalocalmachinecode.RunningJavaprograms:Javaprogramsaredividedintotwocategories-Javaapplications(Application)andJavaapplet(applet).JavaapplicationsmustpasstheJavainterpreter(java.exe)Toexplaintheimplementationofitsbytecodefile;JavaappletcanbesupportedbytheJavastandardbrowsertosolveReleaseexecution.VII.CONCLUSIONTheJavalanguageisarapiddevelopmentofthecomputerlanguageprogram,whichprofoundlyshowstheessenceofthepreparationoftheprogram,coupledwithitssimpleandrigorousstructureandsimplegrammarforitsfuturedevelopmentandmaintenanceprovidesaguarantee.Asaresultofthenetworkapplicationsupportandmultimediaaccess,willpromotetheInternetandenterprisenetworkWebapplications[6].Inaddition,inordertokeepJavagrowingandadvancingtheJavacommunity,SunannouncedtheopeningoftheJavacoresourcecodeattheJavaOneDeveloperConferencetoencouragemorepeopletoparticipateinJavacommunityactivities.FromtheJavacommunityandIBMandotherglobaltechnologypartnersintwoareasofsupport,Javatechnologyininnovationandsocialprogresscontinuetoplayastrongandimportantrole[4],andwiththedifficultyofwritingitsprogramsothatmoreprofessionalswillfocusonPlacedinthepreparationoftheJavalanguageandthedesignoftheframework[3].ACKNOWLEDGMENTThereportedworkherewasconductedincollaborationwithRossJACKSON(ENSIMAG,France)andKellyTOMWELL(UniversitedePierreetCurie,France)whentheyvisitedNIIduringtheirinternshipinthesummerof2003.REFERENCESR.J(Bud)Bates.GPRS:GeneralPacketRadioService.McGraw-Hill,2003,.Cameron,J.R.JSP&JSDtheJacksonapproachtosoftwaredevelopment.SilverSpringMD:IEEEComputerSocietyPress,1983,.M.J.King,J.P.Pardoe.ProgramdesignusingJSPapracticalintroduction.BasingstokeHampshire:Macmillan,1992,.JamesGoodwill.PureJavaServerPages.IndianapolisInd:Sams,2000,.GwenaelLeBodic.MobilemessagingtechnologiesandservicesSMSEMSandMMS.NewYork:J.Wiley,2005,.[6]HenryLabord(?)re,VincentJonack.SMSandMMSinterworkinginmobilenetworks.Boston:ArtechHouse,2004,CS1和CS2:用Java編寫(xiě)電腦游戲摘要Java已經(jīng)成為一個(gè)龐大而復(fù)雜的技術(shù)平臺(tái),對(duì)于開(kāi)發(fā)人員而言,要想更好的掌握J(rèn)ava技術(shù),深入理解底層的技術(shù)處理細(xì)節(jié)必不可少。對(duì)核心概念和思想的掌握可以幫助我們舉一反三、觸類旁通,有助于提升我們對(duì)整個(gè)Java平臺(tái)的理解力。這里所介紹的是Java技術(shù)平臺(tái)的幾個(gè)核心概念,其中所蘊(yùn)含的思想有助于我們更深刻的理解Java技術(shù)。關(guān)鍵字:Java;虛擬機(jī);Class文件;API;1引言Java是一門面向?qū)ο缶幊陶Z(yǔ)言,不僅吸收了C++語(yǔ)言的各種優(yōu)點(diǎn),還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語(yǔ)言具有功能強(qiáng)大和簡(jiǎn)單易用兩個(gè)特征。Java語(yǔ)言作為靜態(tài)面向?qū)ο缶幊陶Z(yǔ)言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚?,允許程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程[1]。Java具有簡(jiǎn)單性、面向?qū)ο?、分布式、健壯性、安全性、平臺(tái)獨(dú)立與可移植性、多線程、動(dòng)態(tài)性等特點(diǎn)[2]。Java可以編寫(xiě)桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等[3]。2Java虛擬機(jī)Java虛擬機(jī)的主要任務(wù)是裝在class文件并且執(zhí)行其中的字節(jié)碼。Java虛擬機(jī)包含一個(gè)類裝載器,它可以從程序和API中裝載class文件。JavaAPI中只有程序執(zhí)行時(shí)需要的那些類才會(huì)被裝載。字節(jié)碼由執(zhí)行引擎來(lái)執(zhí)行。

不同的Java虛擬機(jī)中,執(zhí)行引擎可能實(shí)現(xiàn)得非常不同。在由軟件實(shí)現(xiàn)的虛擬機(jī)中,最簡(jiǎn)單的執(zhí)行引擎就是一次性解釋字節(jié)碼。另一種執(zhí)行引擎更快,但是也更消耗內(nèi)存,叫做"即時(shí)編譯器(just-in-timecompiler)"。在這種情況下,第一次被執(zhí)行的字節(jié)碼會(huì)被編譯成本地機(jī)器代碼。編譯出的本地機(jī)器代碼會(huì)被緩存,當(dāng)方法以后被調(diào)用的時(shí)候可以重用。第三種執(zhí)行引擎是自適應(yīng)優(yōu)化器。在這種方法里,虛擬機(jī)開(kāi)始的時(shí)候解釋字節(jié)碼,但是會(huì)監(jiān)視運(yùn)行中程序的活動(dòng),并且記錄下使用最頻繁的代碼段。程序運(yùn)行的時(shí)候,虛擬機(jī)只把那些活動(dòng)最頻繁的代碼編譯成本地代碼,其他的代碼由于使用得不是很頻繁,繼續(xù)保留為字節(jié)碼-由虛擬機(jī)繼續(xù)解釋它們。一個(gè)自適應(yīng)的優(yōu)化器可以使得Java虛擬機(jī)在80%~90%的時(shí)間里執(zhí)行被優(yōu)化過(guò)的本地代碼,而只需要編譯10%~20%的對(duì)性能有影響的代碼。

當(dāng)Java虛擬機(jī)是由主機(jī)操作系統(tǒng)上的軟件實(shí)現(xiàn)的時(shí)候,Java程序通過(guò)調(diào)用本地方法(nativemethod)和主機(jī)交互。Java中有兩種方法:Java方法和本地方法。Java方法是由Java語(yǔ)言編寫(xiě),編譯成字節(jié)碼文件,存儲(chǔ)在class文件中的。本地方法是由其他語(yǔ)言(比如c,c++或匯編語(yǔ)言)編寫(xiě)的,編譯成何處理器相關(guān)的機(jī)器代碼。本地方法保存在動(dòng)態(tài)鏈接庫(kù)中,格式是各個(gè)平臺(tái)專有的。運(yùn)行中Java程序調(diào)用本地方法時(shí),虛擬機(jī)裝載包含這個(gè)本地方法的動(dòng)態(tài)庫(kù),并調(diào)用這個(gè)方法。本地方法是聯(lián)系Java程序和底層主機(jī)操作系統(tǒng)的連接方法。圖1Java虛擬機(jī)工作原理

通過(guò)本地方法,Java程序可以直接訪問(wèn)底層操作系統(tǒng)的資源。一個(gè)本地方法接口(JavaNativeInterface,JNI)-使得本地方法可以在特定主機(jī)系統(tǒng)的任何一個(gè)Java平臺(tái)實(shí)現(xiàn)上運(yùn)行。

如果希望使用特定主機(jī)上的資源,它們又無(wú)法從JavaAPI訪問(wèn),那么可以寫(xiě)一個(gè)平臺(tái)相關(guān)的Java程序來(lái)調(diào)用本地方法。如果希望保證程序的平臺(tái)無(wú)關(guān)性,那么只能通過(guò)JavaAPI來(lái)訪問(wèn)底層系統(tǒng)資源。3類裝載器的體系結(jié)構(gòu)

一個(gè)Java應(yīng)用程序可以使用兩種類裝載器:"啟動(dòng)(bootstrap)"類裝載器和用戶定義的類裝載器。啟動(dòng)類裝載器(這是系統(tǒng)中唯一的)是Java虛擬機(jī)實(shí)現(xiàn)的一部分。啟動(dòng)類裝載器通常使用某種默認(rèn)方式從本地磁盤中裝載類,包括JavaAPI類(啟動(dòng)類裝載器也被稱為原始類器、系統(tǒng)類裝載器或者默認(rèn)類裝載器)。

Java應(yīng)用程序能夠在運(yùn)行時(shí)安裝用戶定義的類裝載器,這種類裝載器能夠使用自定義的方式來(lái)裝載類。例如,從網(wǎng)絡(luò)下載class文件。盡管啟動(dòng)類裝載器是虛擬機(jī)實(shí)現(xiàn)的本質(zhì)部分,而用戶定義的類裝載器不是,但用戶定義的類裝載器能夠用Java來(lái)編寫(xiě),能夠被編譯成class文件,能夠被虛擬機(jī)裝載,還能夠像其它對(duì)象一樣實(shí)例化。

由于有用戶定義類裝載器,所以不必再編譯的時(shí)候就知道運(yùn)行中的Java應(yīng)用程序中最終會(huì)加入的所有的類。用戶定義的類裝載器使得在運(yùn)行擴(kuò)展Java應(yīng)用程序成為可能。當(dāng)它運(yùn)行時(shí),應(yīng)用程序能夠解決它需要哪些額外的類,能夠決定是使用一個(gè)或是更多的用戶定義的類裝載器來(lái)裝載。由于類裝載器是用Java編寫(xiě)的,所以用任何在Java代碼中可以表述的風(fēng)格來(lái)進(jìn)行類裝載。這些類可以通過(guò)網(wǎng)絡(luò)下載,可以從某些數(shù)據(jù)庫(kù)中獲取,甚至可以動(dòng)態(tài)生成。

每一個(gè)類被裝載的時(shí)候,Java虛擬機(jī)都監(jiān)視這個(gè)類,看到它到底是被啟動(dòng)類裝載器還是被用戶定義類裝載器裝載。當(dāng)被裝載的類引用了另外一個(gè)類時(shí),虛擬機(jī)就會(huì)使用裝載第一個(gè)類的類裝載器裝載引用的類。例如,如果虛擬機(jī)使用一個(gè)特定的類裝載器裝載Volcano這個(gè)類,它就會(huì)使用這個(gè)類裝載器裝載Volcano類使用的所有類。

由于Java虛擬機(jī)采取這種方式進(jìn)行類的裝載,所以被裝載的類默認(rèn)情況下只能看到被同一個(gè)類裝載器裝載的別的類。通過(guò)這種方法,Java的體系結(jié)構(gòu)允許在一個(gè)Java應(yīng)用程序中建立多個(gè)命名空間。運(yùn)行時(shí)的Java程序中的每一個(gè)類裝載器都有自己的命名空間。

Java應(yīng)用程序可以創(chuàng)建多少個(gè)(或多少種)被不同的類裝載器裝載的類存放在不同的命名空間中,它們不能相互訪問(wèn),除非應(yīng)用程序顯示地允許這么做。當(dāng)編寫(xiě)一個(gè)Java應(yīng)用程序的時(shí)候,從不同源文件裝載的類可以分隔在不同的命名空間中。通過(guò)這種方法,就能夠使用Java類裝載器的體系結(jié)構(gòu)來(lái)控制任何不同源文件中裝載的代碼之間的相互影響,特別是能夠阻止惡意代碼獲取訪問(wèn)或破壞善意代碼的權(quán)限。

Web瀏覽器是一個(gè)動(dòng)態(tài)擴(kuò)展的例子,Web瀏覽器使用用戶定義的類裝載器從網(wǎng)絡(luò)下載用于Javaapplet的class文件。Web瀏覽器使用一個(gè)用來(lái)安裝用戶定義類裝載器的Java應(yīng)用程序。這個(gè)用戶定義的類裝載器通常被稱為JavaApplet類裝載器,它知道如何向HTTP服務(wù)器請(qǐng)求class文件。JavaApplet可以作為動(dòng)態(tài)擴(kuò)展的例子,因?yàn)镴ava應(yīng)用程序并不知道它什么時(shí)候會(huì)開(kāi)始從網(wǎng)絡(luò)下載瀏覽器請(qǐng)求的class文件。只有當(dāng)瀏覽器遇到有Javaapplet的頁(yè)面時(shí),才決定是否需要下載class文件。

Web瀏覽器啟動(dòng)的Java應(yīng)用程序通常為每個(gè)提供class文件的網(wǎng)絡(luò)地址分別創(chuàng)建不同的用戶定義類裝載器,因此,不同的用戶定義類裝載器裝載不同來(lái)源的class文件。這就可以把它們分別放置在Java主機(jī)應(yīng)用程序的不同命名空間之下。由于不同來(lái)源的Javaapplet文件放置在不同的命名空間中,惡意的Javaapplet代碼就不會(huì)直接訪問(wèn)從別的地方下載的class文件。這就能夠限制或阻止不同來(lái)源的代碼之間的相互訪問(wèn)。圖2類裝載器的體系結(jié)構(gòu)4Javaclass文件

Javaclass文件主要在平臺(tái)無(wú)關(guān)性和網(wǎng)絡(luò)移動(dòng)性方面使Java更適合網(wǎng)絡(luò)。它在平臺(tái)無(wú)關(guān)性方面的任務(wù)是:為Java程序提供獨(dú)立于底層主機(jī)平臺(tái)的二進(jìn)制形式的服務(wù)。這種途徑途徑打破了C或者C++等語(yǔ)言所遵循的傳統(tǒng),使用這些傳統(tǒng)語(yǔ)言寫(xiě)的程序通常首先被編譯,然后被連接成單獨(dú)的、專門支持特定硬件平臺(tái)和操作系統(tǒng)的二進(jìn)制文件。通常情況下,一個(gè)平臺(tái)上的二進(jìn)制可執(zhí)行文件不能在其他平臺(tái)上工作。而Javaclass文件時(shí)可以運(yùn)行在任何支持Java虛擬機(jī)的硬件平臺(tái)和操作系統(tǒng)上的二進(jìn)制文件。圖3Java類文件

當(dāng)編譯和連接一個(gè)C++程序時(shí),所獲得的可執(zhí)行二進(jìn)制文件只能在指定的硬件平臺(tái)和操作系統(tǒng)上運(yùn)行,因?yàn)檫@個(gè)二進(jìn)制文件包含了對(duì)目標(biāo)處理器的機(jī)器語(yǔ)言。而Java編譯器把Java源文件的指令翻譯成字節(jié)碼,這種字節(jié)碼就是Java虛擬機(jī)的"機(jī)器語(yǔ)言"。

class文件設(shè)計(jì)得緊湊,因此它們可以快速地在網(wǎng)絡(luò)上傳送。其次,由于Java程序是動(dòng)態(tài)連接和動(dòng)態(tài)擴(kuò)展的,class文件可以在需要的時(shí)候才下載。這個(gè)特點(diǎn)使得Java應(yīng)用程序能夠安排從網(wǎng)絡(luò)上下載class文件的時(shí)間,從而可以最大限度地減少終端用戶的等待時(shí)間。圖4JavaAPI5JavaAPI

A

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論