|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
有了这样一个呼声:让java代替C语言成为基本语言。这些足以说明java简单易学的这个优点。其次,java的功能强大,前面我也提到了,EJB3.0的推出使java成为了大型项目的首选。4)LanguageFundamentals
Objective1)
Identifycorrectlyconstructedpackagedeclarationsimportstatementsclassdeclarations(ofallformsincludinginnerclasses)interfacedeclarationsandimplementations(forjava.lang.Runnableorotherinterfacedescribedinthetest)methoddeclarations(includingthemainmethodthatisusedtostartexecutionofaclass)variabledeclarationsandidentifiers.
1.Sourcefile’selements(inorder)
a.Packagedeclaration
b.Importstatements
c.Classdefinitions
2.Importingpackagesdoesn’trecursivelyimportsub-packages.
3.Sub-packagesarereallydifferentpackages,happentolivewithinanenclosingpackage.Classesinsub-packagescannotaccessclassesinenclosingpackagewithdefaultaccess.
4.Commentscanappearanywhere.Can’tbenested.(Nomatterwhattypeofcomments)
5.Atmostonepublicclassdefinitionperfile.Thisclassnameshouldmatchthefilename.Iftherearemorethanonepublicclassdefinitions,compilerwillaccepttheclasswiththefile’snameandgiveanerroratthelinewheretheotherclassisdefined.
6.It’snotrequiredhavingapublicclassdefinitioninafile.Strange,buttrue.JInthiscase,thefile’snameshouldbedifferentfromthenamesofclassesandinterfaces(notpublicobviously).
7.Afilecancontainmultiplenonpublicclasses,butbearinmindthatthiswillproduceseparate.classoutputfilesforeachclass.
8.Evenanemptyfileisavalidsourcefile.
9.InordertoberunbyJVM,aclassshouldhaveamainmethodwiththefollowingsignature.
publicstaticvoidmain(Stringargs[])
staticpublicvoidmain(String[]s)
10.argsarray’snameisnotimportant.args[0]isthefirstargument.args.lengthgivesno.ofarguments.
11.mainmethodcanbeoverloaded.
12.mainmethodcanbefinal.
13.Aclasswithadifferentmainsignatureorw/omainmethodwillcompile.Butthrowsaruntimeerror.
14.AclasswithoutamainmethodcanberunbyJVM,ifitsancestorclasshasamainmethod.(mainisjustamethodandisinherited)
15.Anidentifiermustbeginwithaletter,dollarsign($)orunderscore(_).Subsequentcharactersmaybeletters,$,_ordigits.
16.Currencysymbolsaretreatedasanyotheralphabeticcharacterforthesakeofnamingidentifiers(e.g., |
|