




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
4:JDK1.5--1.8--XML--XML類Class 2PropertyDescriptor什么叫3:BeanUtls--對(duì)于JavaBean來說,使用反射操作一個(gè)Studstud=new//通過反射來調(diào)用Methodmethod=Stud.class.getMethod("setName",String.class);method.invoke(stud,"Jerry");Studstud=newPropertyDescriptorpd=newPropertyDescriptor("name",Stud.class);Methodmethod=pd.getWriteMethod();method.invoke(stud,"使用BeanUtils(BeanUtils不是Jdk的一部分,必須要獨(dú)立的去它是apache)
packagesintheJDKJavadocs).However,thesecanbequitecomplextounderstandandutilize.TheBeanUtilscomponentprovideseasy-to-usewrappersaroundthesecapabilities.將完成以后的Jar包,放到項(xiàng)目中buildBeanUtils中的類:兩個(gè)類BeanUtils用于設(shè)置JavaBean的屬性,JavaBean的屬性ConvertUtils上面的異常,ClassNotFoundBeanUtils運(yùn)行要依賴于一個(gè)日志所以,必須要添加日Studstud=newStud();BeanUtils.setProperty(stud,"name","");BeanUtilsStringStudstud=newStud();BeanUtils.setProperty(stud,"age","199");BeanUtils.setProperty(stud,"married","true");BeanUtils.setProperty(stud,"name",newString[]{"Jack","Mary"});BeanUtils.setProperty(stud,"age","199");BeanUtils.setProperty(stud,"married","true");4mapcopypublicvoidtest4()throwsException{Studstud=newStud();Map<StringObjectmapnewHashMap<>();map.put("name","同學(xué)");map.put("age",map.put(" //將map中的所有值,copy到studBeanUtils.BeanUtils.populate(stud,}5:Stringnm=BeanUtils.getProperty(stud,"name");System.err.println("nmis:"+nm);publicDemo04()//只要是在執(zhí)行設(shè)置屬性之前,過類型轉(zhuǎn)換,就可以ConvertUtils.register(newConverter(){public<T>Tconvert(Class<T>dateClass,Objectval)將valSimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");Datedd=null;trydd=sdf.parse(""+}catch(ParseExceptione){}return(T)}},}在Javapublicvoidtest1()1:獲取StudClassLoaderloader1=Stud.class.getClassLoader();System.err.println(loader1);//sun.misc.Launcher$AppClassLoader@1f96302ClassLoaderloader2=.class.getClassLoader();System.err.println(loader2.getParent().getParent());//nullClassLoaderloader3=String.class.getClassLoader();}packagecn.publicclassDog{publicStringtoString()return"Thisis}}上面的類由AppClassLoader如果希望這個(gè)類由Ext加載器加載,則應(yīng)該打包放到ext擴(kuò) 下自定義類加載器,就是類的二進(jìn)制文件的過程packageimportimportimport*自定義類加載器,就是類的字節(jié)碼的過程publicclassMyClassLoaderextendsClassLoader{publicClass<?>findClass(Stringname)throwsClassNotFoundException{Classcls=null;Filefile=newFile(" InputStreamin=newFileInputStream(file);byte[]bs=newbyte[in.available()];intlen=in.read(bs);cls=defineClass("cn..Dog",bs,0,}catch(Exceptionthrownew}return}}publicvoidtest2()throwsExceptionClasscls=newMyClassLoader().findClass(null);Objectobj=cls.newInstance();}-packageimportimportimport*自定義類加載器,就是類的字節(jié)碼的過程publicclassMyClassLoaderextendsClassLoaderpublicClass<?>findClass(Stringname)throwsClassNotFoundException{Classcls=null;StringfileName=name.rece(".","/");fileName=fileName+".class";InputStreamin=byte[]bs=newbyte[in.available()];intlen=in.read(bs);cls=defineClass(name,bs,0,}catch(Exceptionthrownew}return}} 下的文publicvoidtest3()throwsException{Stringpath= }2: 下的文publicvoidtest4()throwsException{Stringpath= /bin/aa.txtclasspath}5:JDKEnhanced(增強(qiáng))forLoop(循環(huán)String[]names=int[]ages=for(inti=0;i<names.length;i++){System.err.println(names[i]+"ageis:"+ages[i]);}intanewInteger(30);//Integeraa45;//StaticimportstaticpublicclassDemo01{publicvoidtest1()inta=abs(-TypesafeEnums枚舉Enum定義類publicstaticfinal靜態(tài)常量packagepublicenumGender//1:兩個(gè)變FEMALE,}Genderg1=Gender.FEMALE;Genderg2=使用@interfacepackagepublic@interfaceMyTest}publicclassDemo01{publicDemo01()}publicvoidtest1()public@interfaceMyTest}3:通過反射來注解-重如果通過反射來,必須要注解在運(yùn)行時(shí)存在編譯器將把注釋記錄在類文件中,但在運(yùn)行時(shí)VM。@Retention(Retention.RUNTIME)public@interfaceMyTest{}自己定義一個(gè)主類里面有main方法,一個(gè)注解在主類判斷是否有這個(gè)注解packageimportjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.Retention;importjava.lang.annotation.Target;public@interfaceMyRunTest{}packageimportimportpublicclassMyUnitpublicstaticvoidmain(Stringargs)throwsExceptionScannersc=newScanner(System.in);StringclassName=Classcls=Class.forName(className);Objectobj=cls.newInstance();Method[]ms=for(Method}}}}--packageimportorg.junit.After;importorg.junit.Before;importorg.junit.Test;publicclassDemo06{publicvoid}publicvoid}publicvoidtest11(){}publicvoidtest22(){ }}7:1.7BinaryLilsinta=0b1111;UnderscoresinNumericLiinta=inta2=9_3_89_4384;Stringsinswitch在switch里面使用Stringname=switch(name)case}Thetry-with-resourcesStatement//不用調(diào)用in.closetry(InputStreamin=new}//不用調(diào)用in.closetry(InputStreamin=new}catch(NullPointerException|IOException}1.8ladmapublicvoidtest11()throwsException{List<String>list=newArrayList<>();list.forEach(newConsumer<String>(){publicvoidaccept(Stringt){} 以下是使用ladmalist.forEach((Stringt)->{}使用ladmabtn.setOnAction((ActionEventevent)->newAddStud(newAddStud.ICallback(){publicvoidback(Studstud)}publicvoidlongs=Syst
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 備戰(zhàn)2025高考物理3年高考2年模擬1年原創(chuàng)專題5.8宇宙探測含解析
- 福建2025年02月福州市鼓樓區(qū)東街街道公開招考1名營商環(huán)境辦(財(cái)政所)工作人員筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 跨界融合教育領(lǐng)域營銷團(tuán)隊(duì)的創(chuàng)新教育模式
- 餐飲行業(yè)中的品牌建設(shè)與市場推廣策略研究
- 購物中心的特色定位與市場細(xì)分策略
- 高端商業(yè)空間茶館墻面的裝飾風(fēng)格趨勢
- 高效時(shí)間管理提升個(gè)人和團(tuán)隊(duì)績效的秘訣
- 河南2025年01月河南省新鄉(xiāng)市市直機(jī)關(guān)(單位)2025年度公開遴選12名公務(wù)員筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 河南2025年01月河南省林州市部分市直單位2025年公開選調(diào)10名工作人員筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 跨學(xué)科合作下的超聲科醫(yī)學(xué)教育新模式
- 四川輕化工大學(xué)
- 六西格瑪質(zhì)量管理在口腔科器械管理中的作用
- 高中心理健康教育-認(rèn)識(shí)自我悅納自我教學(xué)課件設(shè)計(jì)
- 素材合集-扁平化圖標(biāo)素材(彩色)
- (全)電梯安全風(fēng)險(xiǎn)管控清單
- 中國思想史 馬工程329P
- 《網(wǎng)店美工》教案-商品詳情頁設(shè)計(jì)
- 原始狩獵圖哀郢楚商
- 新版冀教版(冀人版)科學(xué)五年級(jí)下冊全冊教案
- 烏茲別克斯坦
- “雙減”下初中道德與法治分層作業(yè)設(shè)計(jì)研究 論文
評(píng)論
0/150
提交評(píng)論