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

下載本文檔

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

文檔簡介

參考文獻(xiàn)[1]百度百科.Java語言的特點和優(yōu)勢[EB/OL]./view/edd3e74ffe4733687e21aac9.html[2]榮欽科技.Java2游戲設(shè)計[M].北京.清華大學(xué)出版社.2004.[3]程成.軟件工程[M].北京.機械工業(yè)出版社.2003.[4]袁海燕,王文濤.Java實用程序設(shè)計100例[M].北京.人民郵電出版社.2005.[5]王伯欣.J2ME無線.Java[M].北京.應(yīng)用開發(fā)電子工業(yè)出版社.2004.[6]曹瑩,苗志剛,趙秀明.淺談Java優(yōu)勢[J].中國科技信息,2006.[7]邵敏敏,陳德平.解析Java的多線程機制[J].電腦知識與技術(shù).2006.[8]朱平.Java程序設(shè)計教學(xué)[J].湖北教育學(xué)院學(xué)報.2006.[9]猛偉君.李龍海.付少鋒.周利華.基于VC++和JAVA的多線程設(shè)計和實現(xiàn)[J].2006.[10]秦琴.Java語言的異常處理設(shè)計[J].中國科技信息.2006.[11]倪道義.手機游戲架構(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.

致謝花有重開日,人無再少年。隨著畢業(yè)論文的提交,大學(xué)生活畫上了完美的句號。但這同時也象征著新的開始,自己將獨自走向新的臺階,邁向人生征程新的開始。回想大學(xué)四年的學(xué)習(xí)生活,許多事情浮現(xiàn)腦海,仿佛前不久才發(fā)生。剛進(jìn)入大學(xué)校園時與父母歡樂和興奮的場景還歷歷在目。一切都是那么新鮮,那么富有吸引力。有快樂也有艱辛,有收獲也有失落。感謝軟件學(xué)院給予幫助過我的所有老師。18班的友情也同樣終身難忘難忘,是你們陪我共同度過了人生重要的一段路程,無論將來走到哪里,你們都是我人身中珍貴的回憶。我要感謝指導(dǎo)教師和杰普老師。這個論文是在她們的悉心指導(dǎo)和熱情幫助下完成的,老師們認(rèn)真負(fù)責(zé)的工作態(tài)度,精益求精的工作作風(fēng)以及平易近人的人格魅力都使我受益匪淺。對于在畢業(yè)設(shè)計完成過程中遇到的問題,她們無論在理論上還是在實踐中,都對我進(jìn)行了認(rèn)真的指導(dǎo),使我的專業(yè)實踐能力得到很大提高,這對于我以后的學(xué)習(xí)和工作都有幫助。在此,特別向指導(dǎo)老師表示衷心的感謝,請兩位老師接受我最誠摯的敬意!謝謝你們認(rèn)真輔導(dǎo),使我能夠順利完成畢業(yè)設(shè)計的開發(fā)工作。同時也要感謝幫助過我的同學(xué)們,在略微乏味的學(xué)海中,讓我體會到友情的無價。同時,我也想感謝我的家人,他們不僅幫助我茁壯成長、給予我關(guān)懷和照顧,而且,是他們培養(yǎng)了我對科學(xué)文化知識的興趣。沒有他們,就沒有我今天的成績。在今后的日子里,我想說,我會一如既往的認(rèn)真下去,將自己在學(xué)生階段所學(xué)知識運用到社會實踐當(dāng)中,我會不忘初心,用自己的努力報答你們!由于本人水平有限以及時間緊湊,本文可能會出現(xiàn)一些不足之處,這這里,我懇請各位老師給予指正和幫助。附錄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編寫電腦游戲摘要Java已經(jīng)成為一個龐大而復(fù)雜的技術(shù)平臺,對于開發(fā)人員而言,要想更好的掌握J(rèn)ava技術(shù),深入理解底層的技術(shù)處理細(xì)節(jié)必不可少。對核心概念和思想的掌握可以幫助我們舉一反三、觸類旁通,有助于提升我們對整個Java平臺的理解力。這里所介紹的是Java技術(shù)平臺的幾個核心概念,其中所蘊含的思想有助于我們更深刻的理解Java技術(shù)。關(guān)鍵字:Java;虛擬機;Class文件;API;1引言Java是一門面向?qū)ο缶幊陶Z言,不僅吸收了C++語言的各種優(yōu)點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特征。Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程[1]。Java具有簡單性、面向?qū)ο?、分布式、健壯性、安全性、平臺獨立與可移植性、多線程、動態(tài)性等特點[2]。Java可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等[3]。2Java虛擬機Java虛擬機的主要任務(wù)是裝在class文件并且執(zhí)行其中的字節(jié)碼。Java虛擬機包含一個類裝載器,它可以從程序和API中裝載class文件。JavaAPI中只有程序執(zhí)行時需要的那些類才會被裝載。字節(jié)碼由執(zhí)行引擎來執(zhí)行。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A

溫馨提示

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

評論

0/150

提交評論