Java学习笔记(基础部分)

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

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

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

资源描述

Java学习笔记作者:hyanqing1视频,做的简单笔记,主要是代码。还有一些是转载网上的东西。页本书由JavaEye提供的电子书DIY功能自动生成于2009-06-12目录1.Java学习笔记1.1我对String池和==的理解............................................................41.2正则表达式的简单例子..............................................................51.3企业面试关于同步问题的经典例子....................................................101.4模拟死锁.........................................................................121.5synchronized关键字的使用.........................................................141.6sleep()&yield()&join()&优先级......................................................151.7线程的创建和一些小例子............................................................191.8BufferStream....................................................................241.9Print流..........................................................................251.10FileReader&FileWriter...........................................................261.11FileInputStream&FileOutputStream...............................................281.12从控制台上计算每个单词出现重复的次数.............................................301.13自动打包(auto-boxing)和自动解包(un-boxing).......................................311.14基本泛型的简单例子..............................................................331.15面向方面的Annotation............................................................351.16JavaAnnotation入门.............................................................491.17Tiger中的注释,第2部分:定制注释................................................591.18Tiger中的注释,第1部分:向Java代码中添加元数据..................................711.19java枚举类型入门................................................................83页1.20File的简单例子...................................................................941.21接口的用法......................................................................951.22多态的学习(动态绑定)..........................................................971.23对象转型的简单例子.............................................................1001.24重写Equals()方法...............................................................1021.25一个简单的递归方法的调用........................................................1041.26MD5..........................................................................105页1.1我对String池和==的理解发表时间:2007-11-28publicclassTest{publicstaticvoidmain(String[]args)...{Strings1=newString(abc);Strings2=abc;//放入String池里Strings3=newString(abc);System.out.println(s1==s2);//falseSystem.out.println(s1==s3);//falseSystem.out.println(s3==s2);//falseSystem.out.println(s1==s1.intern());//s1.intern()到String池里找,而s1是在堆中所以返回falseSystem.out.println(s2==s2.intern());//trueSystem.out.println(s1.intern()==s3.intern());//两个字符串同时到String里查找,返回true//以下三个都放到String池Stringhello=hello;Stringhel=hel;Stringlo=lo;System.out.println(hello==hel+lo);//字符串相加以后,会到String池里找,有不产生,所以返回trueSystem.out.println(hello==hello);//直接到String池里找,返回trueSystem.out.println(hello==hel+lo);//字符串加一个引用,将产生一个新的对象,所以返回falseSystem.out.println(hello==(hel+lo));//类似上面,返回falseSystem.out.println(hello==(hel+lo).intern());//产生新的对象,但是有intern()方法,将到String池中找,返回true}}那只是我的个人理解,看了一些资料,大家帮帮我找出错误或不一致的意见,请指出。上面那种理解,我比较清晰。池和==的理解第4/106页1.2正则表达式的简单例子发表时间:2007-08-30importjava.util.regex.Matcher;importjava.util.regex.Pattern;publicclassTest{publicstaticvoidmain(String[]args){//简单认识正则表达式的概念/*p(abc.matches(...));p(a8729a.replaceAll(\\d,-));Patternp=Pattern.compile([a-z]{3});Matcherm=p.matcher(fgh);p(m.matches());p(fgha.matches([a-z]{3}));*///初步认识.*+?/*p(a.matches(.));p(aa.matches(aa));p(aaaa.matches(a*));p(aaaa.matches(a+));p(.matches(a*));p(aaaa.matches(a?));p(.matches(a?));p(a.matches(a?));p(214523145234532.matches(\\d{3,100}));p(192.168.0.aaa.matches(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}));p(192.matches([0-2][0-9][0-9]));*///范围页/*p(a.matches([abc]));p(a.matches([^abc]));p(A.matches([a-zA-Z]));p(A.matches([a-z]|[A-Z]));p(A.matches([a-z[A-Z]]));p(R.matches([A-Z&&[RFG]]));*///认识\s\w\d\/*p(\n\r\t.matches(\\s{4}));p(.matches(\\S));p(a_8.matches(\\w{3}));p(abc888&^%.matches([a-z]{1,3}\\d+[&^#%]+));p(\\.matches(\\\\));*///POSIXStyle,不推荐使用//p(a.matches(\\p{Lower}));//boundary边界处理/*p(hellosir.matches(^h.*));p(hellosir.matches(.*ir$));p(hellosir.matches(^h[a-z]{1,3}o\\b.*));p(hellosir.matches(^h[a-z]{1,3}o\\b.*));//whiltelinesp(\n.matches(^[\\s&&[^\\n]]*\\n$));p(aaa8888c.matches(.*\\d{4}.));p(aaa8888c.matches(.*\\b\\d{4}.));p(aaa8888c.matches(.*\\d{4}.));p(aaa8888c.matches(.*\\b\\d{4}.));*///email页//p(asdfasdfsafsf@dsdfsdf.com.matches([\\w[.-]]+@[\\w[.-]]+\\.[\\w]+));//matchesfindlookingAt/*Patternp=Pattern.compile(\\d{3,5});Strings=123-34345-234-00;Matcherm=p.matcher(s);p(m.matches());//此行输出false,但是会截掉前面匹配的字符串m.reset();//恢复前面的截掉的p(m.find());//找字串,但是前面有matches()会影响结果p(m.start()+-+m.end());p(m.find());p(m.start()+-+m.end());p(m.find());p(m.start()+-+m.end());p(m.find());//p(m.s

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

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

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

×
保存成功