资源描述:
《scjp_ch01 declaration and access control》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、SCJPStudyNotes:Chapter1DeclarationsandAccessControlChapter1DeclarationsandAccessControl1.IdentifiersandJavaBean1.1LegalIdentifiersMuststartwithaletter,$or_,CAN’TstartwithnumberLegal:_a,$c,__2_w,_$Illegal::b,-d,e#,.f,7gJavaKeywordabstractbooleanbreakb
2、ytecasecatchcharclassconstcontinuedefaultdodoubleelseextendsfinalfinallyfloatforgotoifimplementsimportinstanceofintinterfacelongnativenewpackageprivateprotectedpublicreturnshortstaticstrictfpsuperswitchsynchronizedthisthrowthrowstransienttryvoidvolat
3、ilewhileassertenum1.2JavaBeansStandardsJavaBeans=>helpJavadevelopercreatecomponent=>classthathaveproperties1.JavaBeanPropertyNamingRule-ifnotBoolean,gettermethodprefixmustbe‘get’,e.g.getSize()-ifboolean,getStopped()orisStopped()-settermethodprefixmus
4、tbe‘set’,e.g.setSize()-settermethodmustmarked‘public’withvoidreturntype,witharg.Representpropertyvalue-gettermethodmustmarked‘public’withnoarg,returntypematchargtypeofsettermethod2.JavaBeanListenerNamingRule-registerlistenerprefixwith‘add’,eg.AddActi
5、onListener()-unreg=>‘remove’-Listenermethodnamemustendwith“Listener”E.g.validJavaBeanSignature:publicvoidsetMyValue(intv)publicintgetMyValue()publicBooleanisMyStatus()publicvoidaddMyListener(MyListenerm)publicvoidremoveMyListener(MyListenerm)E.g.Inva
6、lidJavaBeanSignature:voidsetCustomer(Strings)//mustbepublicpublicvoidmodfiyMyValue(intv)//can’tuse‘modify’publicvoidaddXListener(MyListenserm)//MismatchPage8of8SCJPStudyNotes:Chapter1DeclarationsandAccessControl2.DeclareClasses2.1SourceFileDeclaratio
7、nRules-therecanbeONLYONEpublicclasspersrc.file-package,import,class-afilecanhavemorethan1non-publicclass2.2ClassDeclarationandModifiersAccessmodifier:public,protected,private,default(packageaccess)Non–accessmodifier:strictfp,final,abstractPublic=>all
8、packagecanaccess,stillneedtoimportitFinal=>can’tbesubclassedAbstractclass=>can’tbeinstantiatedabstractclassCar{privatedoubleprice;publicabstractvoidgoFast();//endwith‘;’insteadof{}}3.DeclareInterfaceInterface=>acontractforwhataclasscandow/osayinghowi