Java学习笔记(必看经典)_New - 共33页

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

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

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

资源描述

java1JAVA--------EVERYTHINGISOBJECTOOPclassStudent{}java2Newnullpublicint/voidaddNumber()throwExcepion{}publicintaddNumber(inta,intb){}inta,intbpublicStudents=newStudent()StudentStudent“Student()”()StudentsStudentpublicstudent(stringname,inta){}publicstudent(inta,stringname){}java3staticvoidchangename(studentstu){stu.setName“LUCY”}overloadingoverridingJAVAoverridingoverloadingOverloadingoverloadingoverloadingoverloadingpublicvoidteach(){};publicvoidteach(inta){};publicvoidteach(Stringa){}OverloadingByte—short—float—int—long—doublethisstudent(){};student(stringn){this();//student()}student(inta)this(inta)thisthisThisPublicvoidprintNum(){Intnumber=40System.out.println(this.number);}This.numberthis.number(this)numberprivatejava4PublicPrivateprivatesetgetthisthis11.29SuperClassSonClassClassSonextendsFather{}JAVAJAVAJAVAoverridingoverloadingpublicprivateprivatedefaultProtectedPublicSuper()java5Super()thisThis()super()Animala=newDog()Dogd=(Dog)aAnimala=newDog()AnimaldogDogd=(Dog)aDog()instanceofainstanceofAnimal;()AnimalAnimaltruefalseainstanceofAnimalTrueainstanceofDogTrueinstanceofInstanceofAnimala=newAnimal()Dogd=Dog()a;Animala=newDog()Animala=getAnimal()PublicstaticAnimal.getAnimal;ReturnnewDog()java6OverloadingshapecirclerectShapezhouchang()area()squrectrectcha()privatepublic11.29Module6Module6-7static:StaticintdatadataIntdatastaticintdata;m1.data=0;m1.data++1,m2.dataStaticPublicstaticvoidprintData(){}This.datastaticjava7StaticSingletonSingleton11.30finalfinalfinalfinalfinalJAVAfinalJAVAFinalintAGE=10FinalstaticStaticfinalintage=10JAVApublicstaticfinalfinalFinalintx=3finalPublicfinalvoidprint(){}finalfinalprivatestaticfinalprivatestaticfinalfinalprivatedefaultprotectedpublicAbstract(abstractAbstractAbstractjava8Finalabstractabstractprivatevoidprint(){}Abstractvoidprint()abstractAbstractstaticstaticabstract\CODING\abstract\TestClass.javapublicclassTestClass{publicstaticvoidmain(String[]args){SuperClasssc=newSubClass();Sc.print();}AbstractclassSuperClass{Abstractvoidprint();}}classSubClassextendsSuperClass(){voidprint(){System.out.println(“print”);}}JAVAinterface:interfaceIA{}java9publicinterfacepublicpublicpublicclassIAImpleimplementsIA{};publicpublicpublicclassIAImplextendsjava.util.ArrylistimplementIA{}ImplementsIA,IBinterfaceICextendsIA,IB{};IAI=newIAImpl();IAImpleextendsAimplementIA,IBIBI=newIAImple();IinstanceofIAImple;IinstanceofA;IinstanceofIA;IinstanceofIB;true.JAVAXXwriteonceasanywhere.java10JAVAJDBCJAVAObjectJAVAObject:(1)finalize(2)toString():toString()toString()toString()toString()(3)equalStringA=newString(“hello”);StringA=newString(“hello”);A==B(FALSE)ABJAVAStringfinalJAVAVMStringa=”hello”NEW”hello””hello””hello”Stringb=”hello”“hello”Stringa=”hello”;System.out.println(a==”hello”);trueequal:System.out.println(a.equal(b));equala.equal(b)studenta=newstudent(“LUCY”,20);studentb=newstudent(“LUCY”,20);System.out.println(a==b);java11System.out.println(a.equal(b));falseequalturefalsepublicbooleanequals(Objecto){students=(student)o;if(s.name.equals(this.name)&&s.age==this.age)elsereturnfalse;equals()equalspublicbooleanequals(Objecto){if(this==o)returntrun;//if(o==null)returnfalse;if(!oinstanceofstrudent)returnfalse;//studengs=(student)o;//if(s.name.equals(this.name)&&s.age==this.age)returntrue;elsereturnfalse;}equalsemployeeStringname,intid,doublesalary.getsettoStringequalsJAVAObjectintcharintI=10;Strings=I+””;Strings1=String.valueOf(i);IntI=10;IntergerI_class=newinteger(I);javadoc“==”JDKJDKJDKdouble\interger\string12.01java12PROTECTEDPRIVATEPUBLICDEFAULTthis..this.PRIVATEprivateouterinnerouter.classouter$inner.classTestOuter.javaclass.out.inner.inners=newinner();innernewOuter.Innerin=Outer.new.Inner()Outer.Innerin=newOuter.Inner()Outerprivatejava13publicprivatefinalstaticnewOuter.Innerin=newOuter.Inner()privatePeople{run();}Machine{run();}robotclassRobotextendsPeopleimplementMachine.run()IAIAI=newIA(){};newOut$1.classExceptionMODEL7java14JAVAThrowableThrowableErrorExceptionErrorErrorThrowableExceptionExceptionRuntimeexceptionRuntimeexceptionExceptionthrowthrowstryJDKthrowpublicvoidprint()throwsException.throwsExceptionthrownewException()JAVAtry……catchtry{}catch(exceptione){}catchjava15exceptionexceptionexceptioncatchTrytrycatchtrytrycatchtrycatchcatchexceptionexcepitonJAVAtrycatchfinallyfinallyexceptiontrycatchAPIExceptionmessagecatchCatch(IOExceptione){System.out.println(e.message())};Catch(IOExceptione){e.printStackTrace()};trytrythrow(trycatchtrycatchexcepitonRuntimeExceptionThrowthrowsThrowsassertassertAssertassertjava16throwsthrowstrycatchintadd(inta,intb){returna+b}a+b=100;10012.02APIjava.util.*NEWJAVA1.5JAVA1.4collectionmapCollectionMapListSetSortedMapSortedSetJAVACollectionListListSetListSortedSetMapKey-ValueKey-Valuekeyvaluekeyvaluekey1—value1;key2—value2;key3—value3.SortedMapMapkeySortedMap!!CollectionMapjava17ListArrayListLinkedListArrayListArrayListArrayListArrayListadd(Objecto)ArrayListimportjava.util.*ArrayListArrayListListgetsizeSetCollectionIterator()SetListIteratorit=c.iterator();interat

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

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

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

×
保存成功