版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
4:JDK1.5--1.8--XML--XML类Class 2PropertyDescriptor什么叫3:BeanUtls--对于JavaBean来说,使用反射操作一个Studstud=new//通过反射来调用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的一部分,必须要独立的去它是apache)
packagesintheJDKJavadocs).However,thesecanbequitecomplextounderstandandutilize.TheBeanUtilscomponentprovideseasy-to-usewrappersaroundthesecapabilities.将完成以后的Jar包,放到项目中buildBeanUtils中的类:两个类BeanUtils用于设置JavaBean的属性,JavaBean的属性ConvertUtils上面的异常,ClassNotFoundBeanUtils运行要依赖于一个日志所以,必须要添加日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","同学");map.put("age",map.put(" //将map中的所有值,copy到studBeanUtils.BeanUtils.populate(stud,}5:Stringnm=BeanUtils.getProperty(stud,"name");System.err.println("nmis:"+nm);publicDemo04()//只要是在执行设置属性之前,过类型转换,就可以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如果希望这个类由Ext加载器加载,则应该打包放到ext扩 下自定义类加载器,就是类的二进制文件的过程packageimportimportimport*自定义类加载器,就是类的字节码的过程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*自定义类加载器,就是类的字节码的过程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(增强)forLoop(循环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静态常量packagepublicenumGender//1:两个变FEMALE,}Genderg1=Gender.FEMALE;Genderg2=使用@interfacepackagepublic@interfaceMyTest}publicclassDemo01{publicDemo01()}publicvoidtest1()public@interfaceMyTest}3:通过反射来注解-重如果通过反射来,必须要注解在运行时存在编译器将把注释记录在类文件中,但在运行时VM。@Retention(Retention.RUNTIME)public@interfaceMyTest{}自己定义一个主类里面有main方法,一个注解在主类判断是否有这个注解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//不用调用in.closetry(InputStreamin=new}//不用调用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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年医疗机构医疗设备管理规范
- 会议室开会制度
- 物流配送中心运营管理优化方案(标准版)
- 人力资源管理信息化建设与实施(标准版)
- 车站客运服务设施维护与管理制度
- 北宋中央制度
- 办公室员工离职原因分析制度
- 安全生产制度
- 2026年湖南省演出公司公开招聘备考题库及参考答案详解
- 2026年长郡中学国际部诚聘全球精英教师备考题库及一套完整答案详解
- 2026年济南工程职业技术学院单招综合素质考试参考题库带答案解析
- 甘肃省酒泉市普通高中2025~2026学年度第一学期期末考试物理(含答案)
- 2026 年高职应用化工技术(化工设计)试题及答案
- 2026年山西供销物流产业集团面向社会招聘备考题库及一套完整答案详解
- 城管执法文书培训课件
- 2026元旦主题班会:马年猜猜乐新春祝福版 教学课件
- 人工智能对中国新能源汽车出口技术复杂度的影响研究
- 小学食堂食品安全培训记录
- 《基础护理学》-卧有病人床更换床单法(操作流程+评分标准)
- 加气站施工安全培训课件
- GB/T 45305.2-2025声学建筑构件隔声的实验室测量第2部分:空气声隔声测量
评论
0/150
提交评论