




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、Good is good, but better carries it.精益求精,善益求善。SCJP14高效率復習提綱Englishversion-SECTION1:DECLARATIONSANDACCESSCONTROL1.Anidentifierinjavamustbeginwithaletter,adollarsign($),oranunderscore(_);subsequentcharactersmaybeletters,dollarsigns,underscores,ordigits.2.Allthekeywordsinjavaarecomprisedoflowercasechar
2、actersonly.3.Therearethreetop-levelelementsthatmayappearinafile.Noneoftheseelementsisrequired.Iftheyarepresent,thentheymustappearinthefollowingorder:-packagedeclaration-importstatements-classdefinitions4.AJavasourcefile(Javafile)cannothavemorethanonepublicclass,interfaceorcombinationofboth.5.Thevari
3、ablesinaninterfaceareimplicitlypublic,finalandstatic.Iftheinterface,itself,isdeclaredaspublicthemethodsandvariablesareimplicitlypublic.6.Variablescannotbesynchronized.7.ThevariablesinJavacanhavethesamenameasmethodorclass.8.Atransientvariablemaynotbeserialized.9.Thetransientkeywordisapplicabletovaria
4、blesonly.10.Thenativekeywordisapplicabletomethodsonly.11.Thefinalkeywordisapplicabletomethods,variablesandclasses.12.Theabstractkeywordisapplicabletomethodsandclasses.13.Thestatickeywordisapplicabletovariables,methodsorablockofcodecalledstaticinitializers.14.Anativemethodcannotbeabstractbutitcanthro
5、wexception(s).15.Afinalclasscannothaveabstractmethods.16.Anabstractclassmightnothaveanyfinalmethods.17.Allmethodsofafinalclassareautomaticallyfinal.18.Interfacescannotbefinalandshouldnotbedeclaredabstract.19.Thevisibilityoftheclassisnotlimitedbythevisibilityofitsmembers.I.e.Aclasswiththeentiremember
6、sdeclaredprivatecanstillbedeclaredpublic.20.Interfacemethodscannotbenative,static,synchronized,final,private,protectedorabstract.Theyareimplicitlypublic,abstractandnon-static.21.Thestatementfloatf=5.0;willgivecompilationerrorasdefaulttypeforfloatingvaluesisdoubleanddoublecannotbedirectlyassignedtofl
7、oatwithoutcasting.Butf=5.0fisok.22.Aconstructorcannotbenative,abstract,static,synchronizedorfinal.23.Becarefulforstaticandabstractkeywordintheprogram.24.Alsobecarefulforprivatekeywordinfrontofaclassastoplevelclassesorinterfacescannotbeprivate.25.friendlyisnotajavakeyword.Thisisoftenusedasanalternate
8、wordinjavaliteraturetoindicatethedefaultaccesslevelbyplacingnomodifierlikepublic,privateorprotectedinfrontofmembersofclassesandinterfaces.26.Alocalvariable,alreadydeclaredinanenclosingblockandthereforevisibleinanestedblock,cannotberedeclaredinthenestedblock.27.ArrayinJavacanbedeclaredanddefinedlike-
9、intcount=null;intcount=null;intcount=null;intcount=newint50;intcount=5,10,15,20,25SECTION2:FLOWCONTROL,ASSERTIONS,ANDEXCEPTIONHANDLING28.ThreetypesofstatementsregardingflowcontrolsareusedinJava:*Selectionstatementsifelse,switchcase,trycatchfinally*Iterationstatementwhile,dowhile,for*Transferstatemen
10、treturn,break,continue29.Theargumenttoswitchcanbeeitherbyte,short,charorint.Becarefulaboutlong,float,doubleorbooleanasargumenttoswitch.30.TheexpressionforanifandwhilestatementinJavamustbeaboolean.31.Breakingtoalabel(usingbreak;)meansthattheloopatthelabelwillbeterminatedandanyouterloopwillkeepiterati
11、ng.Whileacontinuetoalabel(usingcontinue;)continuesexecutionwiththenextiterationofthelabeledloop.32.Theif()statementinJavatakesonlybooleanasanargument.Notethatif(a=true),providedaisoftypebooleanisavalidstatementthencodeinsidetheifblockwillbeexecutedotherwiseskipped.33.The(-0.0=0.0)willreturntrue,whil
12、e(5.0=-5.0)willreturnfalse.34.Anassertionisaconditionalexpressionthatshouldevaluatetotrueifandonlyifyourcodeisworkingcorrectly.Iftheexpressionevaluatestofalse,anerrorissignaled.Assertionsarelikeerrorchecks,exceptthattheycanbeturnedcompletelyoff,andtheyhaveasimplersyntax.34.AssertionErroristheimmedia
13、tesubclassofjava.lang.Error.35.assertisajavakeywordfromJDK1.4.SoitcannotbeusedasanidentifierfromJDK1.4orlater.ButasotherJDKversions(JDK1.3orearlier)hadnokeywordnamedassert,aninterestingbackwardcompatibilityproblemarisesforthoseprogramsthatusedassertasajavaidentifier.36.Assertioncheckscanbeturnedonan
14、doffatruntime.Bydefault,assertionmechanismisturnedoff.Whenassertionsareoff,theydontusesystemresources.37.ThecommandforcompilingasourceusingJavasnewassertionfeatureisjavac-source1.4filename.java.Butif-sourceargumentisnotmentionedlikejavacfilename.java,itwillbeassumedlikejavac-source1.3filename.javaso
15、thatexistingcodecompilescorrectlyevenifitusesassertasaregularidentifier.38.RememberthatAssertionscanbeenabledanddisabledforspecificpackagesaswellasspecificclasses.Forexample,assertionscanbeenabledingeneralbutdisabledforaparticularpackage.39.Oneofthemostcommonusesofassertionsistoensurethattheprogramr
16、emainsinaconsistentstate.Assertionsarenotalternativetoexceptionhandlingrathercomplementarymechanismtoimprovedisciplineduringdevelopmentphase.40.Assertionsmaybeusedinthesituationslike:*toenforceinternalassumptionsaboutaspectsofdatastructures.*toenforceconstraintsonargumentstoprivatemethods.*tocheckco
17、nditionsattheendofanykindofmethod.*tocheckforconditionalcasesthatshouldneverhappen.*tocheckrelatedconditionsatthestartofanymethod.*tocheckthingsinthemiddleofalong-livedloop.41.Assertionsmaynotbeusedinthesituationslike:*toenforcecommand-lineusage.*toenforceconstraintsonargumentstopublicmethods.*toenf
18、orcepublicusagepatternsorprotocols.*toenforceapropertyofapieceofusersuppliedinformation.*asashorthandforif(something)error();*asanexternallycontrollableconditional.*asacheckonthecorrectnessofyourcompiler,operatingsystem,orhardware,unlessyouhaveaspecific42.reasontobelievethereissomethingwrongwithitan
19、disintheprocessofdebuggingit.43.Anoverridingmethodmaynotthrowacheckedexceptionunlesstheoverriddenmethodalsothrowsthatexceptionorasuperclassofthatexception.44.Thejava.lang.Throwableclasshastwosubclasses:ExceptionandError.45.AnErrorindicatesseriousproblemsthatareasonableapplicationshouldnottrytocatch.
20、Mostsucherrorsareabnormalconditions.46.ThetwokindsofexceptionsinJavaare:Compiletime(Checked)andRuntime(Unchecked)exceptions.AllsubclassesofExceptionexcepttheRunTimeExceptionanditssubclassesarecheckedexceptions.ExamplesofCheckedexception:IOException,ClassNotFoundException.ExamplesofRuntimeexception:A
21、rrayIndexOutOfBoundsException,NullPointerException,ClassCastException,ArithmeticException,NumberFormatException.47.Theuncheckedexceptionsdonothavetobecaught.48.Atryblockmaynotbefollowedbyacatchbutinthatcase,finallyblockmustfollowtry.49.Whileusingmultiplecatchblocks,thetypeofexceptioncaughtmustprogre
22、ssfromthemostspecificexceptiontocatchtothesuperclass(es)oftheseexceptions.50.Morethanoneexceptioncanbelistedinthethrowsclauseofamethodusingcommas.e.g.publicvoidmyMethod()throwsIOException,ArithmeticException.51.Dividinganintegerby0inJavawillthrowArithmeticException.SECTION3:GARBAGECOLLECTION52.Setti
23、ngtheobjectreferencetonullmakestheobjectacandidate(oreligible)forgarbagecollection.53.Garbagecollectionmechanisminjavaisimplementedthroughalowprioritythread,thebehaviorofwhichmaydifferfromoneimplementationtoanother.Nothingcanbeguaranteedaboutgarbagecollectionexcepttheexecutionoffinalize().54.Garbage
24、collectioninJavacannotbeforced.ThemethodsusedtocallgarbagecollectionthreadareSystem.gc()andRuntime.gc().55.Toperformsometaskwhenanobjectisabouttobegarbagecollected,youcanoverridethefinalize()methodoftheObjectclass.TheJVMonlyinvokesfinalize()methodonceperobject.Thesignatureoffinalize()methodofObjectc
25、lassis:protectedvoidfinalize()throwsThrowable.SECTION4:LANGUAGEFUNDAMENTALS56.constandgotoaretwokeywordsinJavathatarenotcurrentlyinuse.57.null,true,falsearereservedliteralsinJava.58.nullstatementmaybeusedafteranystatementinanynumber,inJavaifthestatementisnotunreachable(likeafterreturnstatement)witho
26、utanyeffectintheprogram.Like-if(i50)i+=5;59.NULLisnotareserved-word,butnullisareserved-wordinJava.Javaisacase-sensitivelanguage.60.TheinitializationvaluesfordifferentdatatypesinJavaisasfollowsbyte=0,int=0,short=0,char=u0000,long=0L,float=0.0f,double=0.0d,boolean=false,objectdeference(ofanyobject)=nu
27、ll.61.Astaticmethodcannotrefertothisorsuper.62.Afinalvariableisaconstantandastaticvariableislikeaglobalvariable.63.Astaticmethodcanonlycallstaticvariablesorotherstaticmethods,withoutusingtheinstanceoftheclass.e.g.main()methodcannotdirectlyaccessanynonstaticmethodorvariable,butusingtheinstanceofthecl
28、assitcan.64.instanceofisaJavakeywordnotinstanceOf.65.Thefollowingdefinitionofmainmethodisvalid:staticpublicvoidmain(Stringargs)66.Themain()methodcanbedeclaredfinal.67.this()andsuper()mustbethefirststatementinanyconstructorandsobothcannotbeusedtogetherinthesameconstructor.68.Theexampleofarraydeclarat
29、ionalongwithinitialization-intk=newint1,2,3,4,9;69.Thesizeofanarrayisgivenbyarrayname.length.70.Thelocalvariables(variablesdeclaredinsidemethod)arenotinitializedbydefault.Butthearrayelementsarealwaysinitializedwherevertheyaredefinedbeitclasslevelormethodlevel.71.Inanarray,thefirstelementisatindex0an
30、dthelastatlength-1.Pleasenotethatlengthisaspecialarrayvariableandnotamethod.72.TheoctalnumberinJavaisprecededby0whilethehexadecimalby0 x(xmaybeinsmallcaseoruppercase)e.g.octal:022andhexadecimal:0 x12SECTION5:OPERATORSANDASSIGNMENTS73.Bit-wiseoperators-&,and|operateonnumericandbooleanoperands.74.Thes
31、hortcircuitlogicaloperators&and|providelogicalANDandORoperationsonbooleantypesandunlike&and|,thesearenotapplicabletointegraltypes.Thevaluableadditionalfeatureprovidedbytheseoperatorsistherightoperandisnotevaluatediftheresultoftheoperationcanbedeterminedafterevaluatingonlytheleftoperand.75.Understand
32、thedifferencebetweenx=+y;andx=y+;Inthefirstcaseywillbeincrementedfirstandthenassignedtox.Inthesecondcasefirstywillbeassignedtoxthenitwillbeincremented.76.Pleasemakesureyouknowthedifferencebetweenand(unsignedrightshift)operators.SECTION6:OVERLOADING,OVERRIDING,RUNTIMETYPEANDOBJECTORIENTATION77.Astati
33、cmethodcannotbeoverriddentonon-staticandviceversa.78.Afinalclasscannotbesubclassed.79.Afinalmethodcannotbeoverriddenbutanonfinalmethodcanbeoverriddentofinalmethod.80.Allthestaticvariablesareinitializedwhentheclassisloaded.81.Aninterfacecanextendmorethanoneinterface,whileaclasscanextendonlyoneclass.8
34、2.Instancevariablesofaclassareautomaticallyinitialized,butlocalvariablesofafunctionneedtobeinitializedexplicitly.83.Anabstractmethodcannotbestaticbecausethestaticmethodscannotbeoverridden.84.Anabstractclassmaynothaveevenasingleabstractmethodbutifaclasshasanabstractmethodithastobedeclaredasabstract.8
35、5.Amethodcannotbeoverriddentobemoreprivate.E.g.apublicmethodcanonlybeoverriddentobepublic.86.Whilecastingoneclasstoanothersubclasstosuperclassisallowedwithoutanytypecasting.e.g.AextendsB,Bb=newA();isvalidbutnotthereverse.87.Abstractclassescannotbeinstantiatedandshouldbesubclassed.88.Abstractclassesc
36、anhaveconstructors,anditcanbecalledbysuper()whenitssubclassed.89.Bothprimitivesandobjectreferencescanbecast.90.Polymorphismistheabilityofasuperclassreferencetodenoteobjectsofitsownclassanditssubclassesatruntime.ThisisalsoknownasDynamicMethodLookup.91.AccordingtoMethodOverloadingResolution,mostspecif
37、icormatchingmethodischosenamongtheavailablealternativemethodsthatdonotdirectlymatchtheargumentlistsbutmatchesafterautomaticcasting.Ambiguityisshownwhencompilercannotdeterminewhichonetochoosebetweentwooverloadedmethods.92.Constructorsarenotinheritedsoitisnotpossibletooverridethem.93.Aconstructorbodyc
38、anincludeareturnstatementprovidednovalueisreturned.94.Aconstructorneverreturnsavalue.Ifyouspecifyareturnvalue,theJVM(Javavirtualmachine)willinterpretitasamethod.95.Ifaclasscontainsnoconstructordeclarations,thenadefaultconstructorthattakesnoargumentsissupplied.Thisdefaultconstructorinvokestheno-argum
39、entconstructorofthesuperclassviasuper()call(ifthereisanysuperclass,exceptjava.lang.Object).96.Ifinnerclassisdeclaredinamethodthenitcanaccessonlyfinalvariablesoftheparticularmethodbutcanaccessallvariablesoftheenclosingclass.97.Torefertoafieldormethodintheouterclassinstancefromwithintheinnerclass,useO
40、uter.this.fieldname.98.Innerclassesmaynotdeclarestaticinitializersorstaticmembersunlesstheyarecompiletimeconstantsi.e.staticfinalvar=value;99.Anestedclasscannothavethesamenameasanyofitsenclosingclasses.100.Innerclassmaybeprivate,protected,final,abstractorstatic.101.Anexampleofcreationofinstanceofani
41、nnerclassfromsomeotherclass:classOuterpublicclassInnerclassAnotherpublicvoidamethod()Outer.Inneri=newOuter().newInner();102.Classesdefinedinmethodscanbeanonymous,inwhichcasetheymustbeinstantiatedatthesamepointtheyaredefined.Theseclassescannothaveexplicitconstructorandmayimplementinterfaceorextendoth
42、erclasses.103.OneclassinJavacannotresideundertwopackages.Ifnopackagedeclarationismade,aclassisassumedtobethememberofdefaultorunnamedpackage.SECTION7:THREADS104.TheThreadclassresidesinjava.langpackageandsoneednotbeimported.105.AJavathreadschedulercanbepreemptiveortime-sliced,dependingonthedesignofthe
43、JVM.106.ThesleepandyieldmethodsofThreadclassarestaticmethods.107.TherangeofThreadpriorityinJavais1-10.Theminimumpriorityis1andthemaximumis10.ThedefaultpriorityofanythreadinJavais5.108.TherearetwowaystoprovidethebehaviorofathreadinJava:extendingtheThreadclassorimplementingtheRunnableinterface.109.The
44、onlymethodofRunnableinterfaceispublicvoidrun();.110.Newthreadtakesonthepriorityofthethreadthatspawnedit.111.Usingthesynchronizedkeywordinthemethoddeclaration,requiresathreadobtainthelockforthisobjectbeforeitcanexecutethemethod.112.Asynchronizedmethodcanbeoverriddentobenotsynchronizedandviceversa.113
45、.InJavaterminology,amonitor(orsemaphore)isanyobjectthathassomesynchronizedcode.114.Bothwait()andnotify()methodsmustbecalledinsynchronizedcode.115.Thenotify()methodmovesonethread,thatiswaitingonthisobjectsmonitor,intotheReadystate.Thiscouldbeanyofthewaitingthreads.116.ThenotifyAll()methodmovesallthre
46、ads,waitingonthisobjectsmonitorintotheReadystate.117.Everyobjecthasalockandatanymoment,thatlockiscontrolledbyatmostonesinglethread.118.Therearetwowaystomarkcodeassynchronized:a.)Synchronizeanentiremethodbyputtingthesynchronizedmodifierinthemethodsdeclaration.b.)Synchronizeasubsetofamethodbysurroundi
47、ngthedesiredlinesofcodewithcurlybrackets().119.Deadlockaspecialsituationthatmightpreventathreadfromexecuting.Ingeneralterms,ifathreadblocksbecauseitiswaitingforaconditiontoariseandsomethingelseintheprogrammakesitimpossibleforthatconditiontoarise,thenthethreadissaidtobedeadlocked.SECTION8:FUNDAMENTAL
48、CLASSESINTHEJAVA.LANGPACKAGE120.java.langpackageisautomaticallyimportedineveryjavasourcefileregardlessofexplicitimportstatement.121.TheStringclassisafinalclass,itcannotbesubclassed.122.TheMathclasshasaprivateconstructor,itcannotbeinstantiated.123.Therandom()methodofMathclassinJavareturnsarandomnumbe
49、r,adouble,greaterthanorequalto0.0andlessthan1.0.124.TheStringclassinJavaisimmutable.Onceaninstanceiscreated,thestringitcontainscannotbechanged.e.g.Strings1=newString(test);s1.concat(test1);Evenaftercallingconcat()methodons1,thevalueofs1willremaintobetest.Whatactuallyhappensisanewinstanceiscreated.Bu
50、ttheStringBufferclassismutable.125.The+and+=operatorsaretheonlycasesofoperatoroverloadinginJavaandisapplicabletoStrings.126.Thevariousmethodsofjava.lang.Objectareclone,equals,finalize,getClass,hashCode,notify,notifyAll,toStringandwait.127.TheJava.lang.Systemisafinalclassandcannotbesubclassed.128.AStringinJavaisinitializedtonull,notemptystringandanemptystringisnotsameasanullstring.129.Theequals()methodinStringclasscomparesthevaluesoftwoStringswhile=comparesthememoryaddressoftheobjectsbeingcompared.e.g.Strings=newString(test
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 地板磚采購合同協(xié)議
- 工程場地保潔合同協(xié)議
- 工程代建代銷合同協(xié)議
- 大型設備回收合同協(xié)議
- 工地轉讓板房合同協(xié)議
- 大蒜包畝合同協(xié)議
- 辦公材料采購的透明化-區(qū)塊鏈技術的應用
- AI技術在健康管理中道德邊界的思考
- 為醫(yī)護人員提供支持談智能化在辦公領域的應用
- 企業(yè)信息安全的新防線基于區(qū)塊鏈的加密技術探討
- 比亞迪銷售模式分析報告
- 2024年魚子醬項目營銷策劃方案
- 非洲自然災害
- 2023詩詞大會知識競賽200題題庫(含答案)
- TL226 大眾試驗測試標準
- 2023借款協(xié)議書Word模板
- 生產設備拆除工程施工方案
- (完整版)年產30萬噸合成氨合成工段工藝設計畢業(yè)論文
- 無障礙公共設施建設的問題及其對策研究
- 臨床醫(yī)學(專科)畢業(yè)綜合考復習題
- 石家莊市存量房買賣合同
評論
0/150
提交評論