ORACLE 官方教材 java7-java8新特性

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

InsertPictureHereJDK7andBeyondModularityandClosureLeeChukMunnchuk-munn.lee@oracle.comInsertPictureHereAgenda•ProjectCoin•Modularity•ClosuresInsertPictureHereSectionDividerSmallSmall(Language)(Language)ChangesChangesProjectCoinProjectCoinBetterIntegerLiteral•Binaryliterals•Withunderscoresforclarityintmask=0b101010101010;intmask=0b1010_1010_1010;longbig=9_223_783_036_967_937L;StringSwitchStatement•Todaycaselabelincludesintegerconstantsandenumconstants•StringsareconstantstooDiscriminatingStringsTodayintmonthNameToDays(Strings,intyear){if(April.equals(s)||June.equals(s)||September.equals(s)||November.equals(s))return30;if(January.equals(s)||March.equals(s)||May.equals(s)||July.equals(s)||August.equals(s)||December.equals(s))return31;if(February.equals(s))...WithStringSwitchintmonthNameToDays(Strings,intyear){switch(s){caseApril:caseJune:caseSeptember:caseNovember:return30;caseJanuary:caseMarch:caseMay:caseJuly:caseAugust:caseDecember:return31;caseFebruary:...default:...InferringTypeswith•Pregenerics•Withgenerics•Withdiamond()toinferthetypeListstrList=newArrayList();ListStringstrList=newArrayListString();ListMapString,ListStringstrList=newArrayListMapString,ListString();ListStringstrList=newArrayList();ListMapString,ListStringstrList=newArrayList();ExceptionsGaloretry{...}catch(ClassNotFoundExceptioncnfe){log(cnfe);throwcnfe;}catch(InstantiationExceptionie){log(ie);throwie;}catch(NoSuchMethodExceptionnsme){log(nsme);thrownsme;}catch(InvocationTargetExceptionite){log(ite);throwite;}Multi-Catchtry{//ReflectiveoperationscallingClass.forName,//Class.newInstance,Class.getMethod,//Method.invoke,etc.}catch(finalClassNotFoundException|InstantiationException|NoSuchMethodException|InvocationTargetExceptione){log(e);throwe;}CopyingStreamsInputStreamin=newFileInputStream(src);OutputStreamout=newFileOutputStream(dest);byte[]buf=newbyte[8192];intn;while((n=in.read(buf))=0)out.write(buf,0,n);•Howtomakethispieceofcoderobust?InputStreamin=null;OutputStreamout=null;try{in=newFileInputStream(src);}catch(FileNotFoundExceptionfne){return;}try{out=newFileOutputStream(dst);try{byte[]buf=newbyte[8192];intn;while((n=in.read(buf))=0)out.write(buf,0,n);}catch(IOExceptionioe){//Dosomething}finally{try{out.flush();out.close();}catch(IOExceptionioe){}}}catch(FileNoutFoundExceptionfne){}finally{try{in.close();}catch(IOExceptionioe){}}AutomaticResourceManagement•APIsupport–Newinterfacejava.lang.AutoClosable–java.io.Closable–JDBC4.1retrofittedtouseAutoClosabletry(InputStreamin=newFileInputStream(src);OutputStreamout=newFileOutputStream(ds)){byte[]buf=newbyte[8192];intn;while((n=in.read(buf))=0)out.write(buf,0,n);}ModularityModularityProjectJigsawProjectJigsawModularity–theSolution•“JARhell”–Eliminatesclasspath–Packagemodulesforautomaticdownload&install–Generatenativepackages–deb,rpm,ips,etc•Performance–downloadtime,startuptime–Incrementaldownload→fastclassloading–Rememberingstartupclasses•Platformscalability–downtosmalldevices–SEsubsetcanfitintosmalldevicesModularityGoals•Grouping•Dependencies•Versioning•Encapsulation•Optionalmodules•VirtualmodulesPackagespackagecom.foo.apppublicclassMain{publicclassOther{packagecom.foo.app.uipublicclassShell{com.foo.app.Maincom.foo.app.Othercom.foo.app.ui.Shellcom.foo.appmodule-info.javamodulecom.foo.app@1.0.0{classcom.foo.app.Mainprovidescom.foo.app.lib@1.0.0;}EntrypointModulenameVersionVirtualmodulecom.foo.app.Maincom.foo.app.Othercom.foo.app.ui.Shellcom.foo.appmodule-info.javacom.foo.apporg.bar.libcom.foo.libedu.baz.utilmodulecom.foo.app@1.0.0{classcom.foo.app.Mainrequirescom.foo.lib@2.1-alpha;providescom.foo.app.lib@1.0.0;}Dependencyimportcom.foo.lib.*;publicclassMain{module-info.javacom.foo.apporg.bar.libcom.foo.libedu.baz.utilcom.foo.extraOptionalmodulesmodulecom.foo@1.0.0{classcom.foo.app.Mainrequirescom.foo.lib@2.1-alpha;providescom.foo.app.lib@1.0.0;requiresoptionalcom.foo.extra;}module-info.javacom.foo.appcom.foo.secretorg.bar.libcom.foo.libedu.baz.utilcom.foo.extramodulecom.foo.secret@1{permitscom.foo.lib;}EncapsulatingmodulesPackaging$javac-modulepathmodssrc/com.foo.app/...$lsmodscom.foo.app/com.foo.extra/com.foo.lib/Packaging$javac-modulepathmodssrc/com.foo.app/...$lsmodscom.foo.app/com.foo.extra/com.foo.lib/$ls-Rmods/com.foo.appmods/com.foo.app/com/foo/app/Main.classmods/com.foo.app/com/foo/app/Other.classmods/com.foo.app/com/foo/ui/Shell.classPackaging$javac-modulepathmodssrc/com.foo.app/...$lsmodscom.foo.app/com.foo.extra/com.foo.lib/$jpkg-modulepathmodsjmod\com.foo.appcom.foo.extracom.foo.lib$ls*.jmodcom.foo.app@1.0.0.jmodcom.foo.extra@0.9a.jmodcom.foo.lib@1.0.2.jmodLibrary$ls*.jmodcom.foo.app@1.0.0.jmodcom.foo.extra@0.9a.jmodcom.foo.lib@1.0.2.jmod$jmod-Lmlibcreate./mlibLibraryorg.bar.libedu.baz.util./mlib$ls*.jmodcom.foo.app@1.0.0.jmodcom.foo.extra@0.9a.jmodcom.foo.lib@1.0.2.jmod$jmod-Lmlibinstall\$EXT/edu.baz.util@*.jmod\$EXT/org.bar.lib@*.jmodLibrary$ls*.jmodcom.foo.app@1.0.0.jmodcom.foo.extra@0.9a.jmodcom.foo.lib@1.0.2.jmod$jmod-Lmlibinstall\*.jmod$jmo

1 / 45
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功