




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度雇主免责协议书:航空航天领域雇主责任界定合同
- 2025年度产业转型升级信息咨询服务合同
- 2025年度农产品质量安全监管与风险评估合作协议
- 2025年度国际会展中心招商合作合同协议
- 2025年度临时工临时性数据录入与处理合同
- 2025年度出租房屋装修改造及租赁纠纷解决协议
- 2025年度区块链技术应用合伙投资合同
- 2025年度城市老旧建筑拆除劳务合作合同
- 2025年度教师聘用的教育教学改革与创新合同
- 亲子乐园装修合同样板
- 丝绸之路上的民族学习通超星期末考试答案章节答案2024年
- 四年级语文下册第六单元【集体备课】(教材解读+教学设计)
- 二年级剪窗花
- 分子生物学在医药中的研究进展及应用
- 《对折剪纸》)ppt
- 03SG520-1实腹式钢吊车梁(中轻级工作制A1~A5_Q235钢_跨度6.0m、7.5m、9.0m)
- 以虚报注册资本、虚假出资、抽逃出资为由对实行认缴资本登记制的公司进行处罚无法律依据
- 风电场生产运营准备大纲11.14
- 人教版八年级语文下册教材研说
- 《机械制造装备设计》ppt课件
- 中学家访记录大全100篇 关于中学家访随笔
评论
0/150
提交评论