Java

1.import static鏄疛ava 5澧炲姞鐨勫姛鑳�,灏辨槸灏咺mport绫讳腑鐨勯潤鎬佹柟娉曪紝鍙互浣滀负鏈被鐨勯潤鎬佹柟娉曟潵鐢ㄣ��

2.String鍜孲tringBuffer浠栦滑閮藉彲浠ュ瓨鍌ㄥ拰鎿嶄綔瀛楃涓诧紝鍗冲寘鍚涓瓧绗︾殑瀛楃涓叉暟鎹��

String绫绘槸瀛楃涓插父閲忥紝鏄笉鍙洿鏀圭殑甯搁噺銆傝�孲tringBuffer鏄瓧绗︿覆鍙橀噺锛屽畠鐨勫璞℃槸鍙互鎵╁厖鍜屼慨鏀圭殑銆�

3.break:璺冲嚭璇彞鍧�,鎵ц涓嬮潰鐨勮鍙�;continue:璺冲嚭褰撳墠寰幆,涓嶆墽琛屽惊鐜腑continue涓嬮潰鐨勬墍鏈夎鍙�,寮�濮嬩笅涓�娆″惊鐜�

4.(1)銆佷竴涓猼ry鍙搴斿涓猚atch銆�

(2)銆佹湁try蹇呴』鑷冲皯鏈変竴涓猚atch鎴栬�協inally銆�

(3)銆乫inally鍧椾笉鏄繀椤荤殑锛屽彲鏈夊彲鏃犮��

(4)銆佷竴鑸儏鍐典笅锛屽綋寮傚父鍙戠敓鏃讹紝浼氭墽琛宑atch鍧椾腑鐨勮鍙ワ紝鐗规畩鎯呭喌锛氬綋main鏂规硶涓姏鍑哄紓甯告椂锛屽鏋滅▼搴忓0鏄庝簡璇ヂ� 聽 聽 寮傚父澶勭悊鍣紝鍒欐墽琛岀浉搴旂殑catch鍧椾腑鐨勮鍙ワ紝濡傛灉绋嬪簭娌℃湁澹版槑鐩稿簲鐨勫紓甯稿鐞嗗櫒锛屽垯涓嶆墽琛宑atch鍧椾腑鐨勮鍙ヂ� 聽 聽 锛岀洿鎺ユ姏鍑哄紓甯�,寮傚父琚洿鎺ヤ涪缁橨VM锛岃�孞VM鐨勫鐞嗘柟寮忓氨鏄細鐩存帴涓柇浣犵殑绋嬪簭.

5.绫荤殑鍒濆鍖栭『搴忥細

1). 鐖剁被static锛堥『搴忔寜鐓т唬鐮佷功鍐欓『搴忚繘琛岋級

2). 瀛愮被static锛堥『搴忔寜鐓т唬鐮佷功鍐欓『搴忚繘琛岋級

3). 鐖剁被闈瀞tatic鍩熴�佹瀯閫犲櫒锛堥『搴忔寜鐓т唬鐮佷功鍐欓『搴忚繘琛岋級

4). 瀛愮被闈瀞tatic鍩熴�佹瀯閫犲櫒锛堥『搴忔寜鐓т唬鐮佷功鍐欓『搴忚繘琛岋級

6.闈欐�佸彉閲忓拰鏂规硶涓嶄緷璧栧璞″疄渚嬶紝鐢辩被鍚嶇洿鎺ヨ皟鐢ㄣ��


JAVA鐨勯潰鍚戝璞$紪绋�

闈㈠悜瀵硅薄涓昏閽堝闈㈠悜杩囩▼銆�

闈㈠悜杩囩▼鐨勫熀鏈崟鍏冩槸鍑芥暟銆�

浠�涔堟槸瀵硅薄锛�EVERYTHING IS OBJECT锛堜竾鐗╃殕瀵硅薄锛�

鎵�鏈夌殑浜嬬墿閮芥湁涓や釜鏂归潰锛�

鏈変粈涔堬紙灞炴�э級锛氱敤鏉ユ弿杩板璞°��

鑳藉鍋氫粈涔堬紙鏂规硶锛夛細鍛婅瘔澶栫晫瀵硅薄鏈夐偅浜涘姛鑳姐��

鍚庤�呬互鍓嶈�呬负鍩虹銆�

澶х殑瀵硅薄鐨勫睘鎬т篃鍙互鏄竴涓璞°��

涓轰粈涔堣浣跨敤闈㈠悜瀵硅薄锛�

棣栧厛锛岄潰鍚戝璞$鍚堜汉绫荤湅寰呬簨鐗╃殑涓�鑸寰嬨��

瀵硅薄鐨勬柟娉曠殑瀹炵幇缁嗚妭鏄睆钄界殑锛屽彧鏈夊璞℃柟娉曠殑瀹炵幇鑰呬簡瑙g粏鑺傘��

鏂规硶鐨勫畾涔夐潪甯搁噸瑕併�傛柟娉曟湁鍙傛暟锛屼篃鍙兘鏈夎繑鍥炲�笺��

娉ㄦ剰鍖哄垎锛氬璞★紙鏈韩锛夈�佸璞$殑瀹炵幇鑰呫�佸璞$殑璋冪敤鑰呫��

鍒嗘瀽瀵硅薄涓昏浠庢柟娉曞紑濮嬨��

鎴戜滑閫氳繃绫绘潵鐪嬪緟瀵硅薄锛岀被鏄璞$殑鎶借薄銆�

鍏舵锛岄噰鐢ㄩ潰鍚戝璞℃柟娉曞彲浠ヤ娇绯荤粺鍚勯儴鍒嗗悇鍙稿叾鑱屻�佸悇灏芥墍鑳姐��

瀵硅薄涔嬮棿鐨勮�﹀悎鎬т竴瀹氳浣庯紙姣斿涓嶅悓纭洏鍜屼笉鍚屼富鏉夸箣闂寸殑鍏崇郴锛夈�傝繖鏍锋墠鑳戒娇姣忎釜瀵硅薄鏈韩鍋氭垚鏈�濂界殑銆�

瀵逛簬瀵硅薄鐨勮姹傦細楂樺唴鑱氥�佷綆鑰﹀悎锛岃繖鏍峰鏄撴嫾瑁呮垚涓轰竴涓郴缁熴��

瀹炵幇楂樺唴鑱氬氨鏄鏈�澶ч檺搴︿綆鎻愰珮澶嶇敤鎬э紙澶嶇敤鎬уソ鏄洜涓洪珮鍐呰仛锛夈��

鍙鐢ㄦ�ф槸OOP鐨勫熀纭�銆�

姣旇緝闈㈠悜杩囩▼鐨勬�濇兂鍜岄潰鍚戝璞$殑鎬濇兂锛�

闈㈠悜杩囩▼鐨勬�濇兂锛氱敱杩囩▼銆佹楠ゃ�佸嚱鏁扮粍鎴愶紝浠ヨ繃绋嬩负鏍稿績锛�

闈㈠悜瀵硅薄鐨勬�濇兂锛氫互瀵硅薄涓轰腑蹇冿紝鍏堝紑鍙戠被锛屽緱鍒板璞★紝閫氳繃瀵硅薄涔嬮棿鐩镐簰閫氫俊瀹炵幇鍔熻兘銆�

闈㈠悜杩囩▼鏄厛鏈夌畻娉曪紝鍚庢湁鏁版嵁缁撴瀯銆�

闈㈠悜瀵硅薄鏄厛鏈夋暟鎹粨鏋勶紝鐒跺悗鍐嶆湁绠楁硶銆�

鍦ㄧ敤闈㈠悜瀵硅薄鎬濇兂寮�鍙戠殑杩囩▼涓紝鍙互澶嶇敤瀵硅薄灏辫繘琛屽鐢紝濡傛棤娉曡繘琛屽鐢ㄥ垯寮�鍙戞柊鐨勫璞°��

寮�鍙戣繃绋嬫槸鐢ㄥ涓畝鍗曠殑瀵硅薄鐨勫涓畝鍗曠殑鏂规硶锛屾潵瀹炵幇澶嶆潅鐨勫姛鑳�銆�

浠庤娉曚笂鏉ョ湅锛屼竴涓被鏄竴涓柊鐨勬暟鎹被鍨嬨��

鍦ㄩ潰鍚戝璞$紪绋嬩腑锛岄櫎浜嗙畝鍗曟暟鎹被鍨嬶紝灏辨槸瀵硅薄绫诲瀷銆�

瀹氫箟绫荤殑鏍煎紡锛�

classStudent{

浠g爜

}

娉ㄦ剰绫诲悕涓崟璇嶇殑棣栧瓧姣嶅ぇ鍐欍��

瀹炰緥鍙橀噺锛氬畾涔夊湪绫讳腑浣嗗湪浠讳綍鏂规硶涔嬪銆傦紙New鍑烘潵鐨勫潎鏈夊垵鍊硷級

灞�閮ㄥ彉閲忥細瀹氫箟鍦ㄦ柟娉曚箣涓殑鍙橀噺銆�

灞�閮ㄥ彉閲忚鍏堣祴鍊硷紝鍐嶈繘琛岃繍绠楋紝鑰屽疄渚嬪彉閲忓潎宸茬粡璧嬪垵鍊笺�傝繖鏄眬閮ㄥ彉閲忓拰瀹炰緥鍙橀噺鐨勪竴澶у尯鍒��

瀹炰緥鍙橀噺鐨勫璞¤祴鍊间负null銆�

灞�閮ㄥ彉閲忎笉鍏佽鑼冨洿鍐呭畾涔変袱涓悓鍚嶅彉閲忋�傚疄渚嬪彉閲忕殑浣滅敤鍩熷湪鏈被涓畬鍏ㄦ湁鏁堬紝褰撹鍏朵粬鐨勭被璋冪敤鐨勬椂鍊欎篃鍙兘鏈夋晥銆�

瀹炰緥鍙橀噺鍜屽眬閮ㄥ彉閲忓厑璁稿懡鍚嶅啿绐併��

涔﹀啓鏂规硶鐨勬牸寮忥細

淇グ绗�杩斿洖鍊�鏂规硶鍚�璋冪敤杩囩▼涓�鏂规硶浣�

鍙兘鍑虹幇鐨勪緥澶�

publicint/voidaddNumber(鍙傛暟)throw Excepion{}

渚嬶細

publicintaddNumber(int a,int b){

}

娉細鏂规硶鍚嶄腑鐨勫弬鏁�int a,int b涓哄眬閮ㄥ彉閲�

绫绘柟娉曚腑鐨勪竴绫荤壒娈婃柟娉曪細鏋勯�犳柟娉曘��

鏋勯�犳柟娉曟槸褰撶敤绫荤敓鎴愬璞℃椂锛岀郴缁熷湪鐢熸垚瀵硅薄鐨勮繃绋嬩腑鍒╃敤鐨勬柟娉曘��

娉ㄦ剰锛氭瀯閫犳柟娉曞湪鐢熸垚瀵硅薄鐨勬椂鍊欎細琚皟鐢紝浣嗗苟涓嶆槸鏋勯�犳柟娉曠敓鎴愪簡瀵硅薄銆�

鏋勯�犳柟娉曟病鏈夎繑鍥炲�笺�傛牸寮忎负锛�public鏂规硶鍚嶃��

鏋勯�犳柟娉曠殑鏂规硶鍚嶄笌绫诲悕鐩稿悓銆�

鏋勯�犳柟娉曟槸鍦ㄥ璞$敓鎴愮殑杩囩▼涓嚜鍔ㄨ皟鐢紝涓嶅彲鑳藉埄鐢ㄦ寚浠ゅ幓璋冪敤銆�

鍦ㄤ竴涓璞$殑鐢熸垚鍛ㄦ湡涓瀯閫犳柟娉曞彧鐢ㄤ竴娆★紝涓�鏃﹁繖涓璞$敓鎴愶紝閭d箞杩欎釜鏋勯�犳柟娉曞け鏁堛��

鐢ㄧ被鏉ョ敓鎴愬璞$殑璇彞锛�

Students=new Student()銆�

绗竴涓�Student琛ㄧず杩欐槸鐢�Student绫昏繘琛屽畾涔夈��鈥淪tudent()鈥�琛ㄧず璋冪敤涓�涓棤鍙傛暟鐨勬瀯閫犳柟娉曘��

濡傛灉()涓湁鍙傛暟锛屽垯绯荤粺鏋勯�犲璞$殑杩囩▼涓皟鐢ㄦ湁鍙傜殑鏂规硶銆�

姝ゆ椂S绉颁负涓�涓璞″彉閲忋��

Students鐨勫瓨鍌ㄥ尯鍩熷瓨鏀剧殑鏄湴鍧�锛氫竴涓璞″湪纭洏涓婂崰鏈変竴涓繛缁湴鍧�锛岄鍦板潃璧嬩簣s绌洪棿銆�

S绉颁负瀵硅薄Student鐨勫紩鐢ㄣ��

娉ㄦ剰锛氬湪瀵硅薄鍙橀噺涓瓨鏀剧殑鏄紩鐢紙鍦板潃锛夛紱鍦ㄧ畝鍗曞彉閲忎腑瀛樻斁鐨勬槸鏁板�笺��

鍙互鏋勯�犲涓瀯閫犳柟娉曪紝浣嗗涓瀯閫犳柟娉曠殑鍙傛暟琛ㄤ竴瀹氫笉鍚岋紝鍙傛暟椤哄簭涓嶅悓鍗冲睘浜庝笉鍚岀殑鏋勯�犳柟娉曪細

public student(string name,int a){

}

public student(int a,string name){

}

涓轰袱涓笉鍚岀殑鏋勯�犳柟娉曘��

濡傛灉鎴戜滑鏈粰绯荤粺鎻愪緵涓�涓瀯閫犳柟娉曪紝閭d箞绯荤粺浼氳嚜鍔ㄦ彁渚涗竴涓负绌虹殑鏋勯�犳柟娉曘��

缁冧範锛氬啓涓�涓被锛屽畾涔変竴涓璞★紝瀹氫箟涓や釜鏋勯�犳柟娉曪細涓�涓湁鍙傦紝涓�涓棤鍙傘��

锛堢紪鍐欎竴涓▼搴忛獙璇佸璞$殑浼犻�掔殑鍊间负鍦板潃锛�

娉ㄦ剰涓嬮潰杩欑褰㈠紡锛�

static void changename(student stu){stu.setName 鈥淟UCY鈥潁

娉ㄦ剰鐢熸垚鏂扮殑瀵硅薄涓庢棫瀵硅薄鎸囧悜鏃犲叧锛岀敓鎴愭柊瀵硅薄鐢熷懡娑堜骸涓庢棫瀵硅薄鏃犲叧銆�

闈㈠悜瀵硅薄鏂规硶鐨勯噸杞斤紙overloading锛夊拰瑕嗙洊锛�overriding锛夈��

鍦ㄦ湁浜�JAVA涔︾睄涓皢overriding绉颁负閲嶈浇锛�overloading绉颁负杩囪浇銆�

Overloading鍦ㄤ竴涓被涓彲浠ュ畾涔夊涓悓鍚嶆柟娉曪紝鍚勪釜鏂规硶鐨�鍙傛暟琛�涓�瀹氫笉鍚屻�備絾淇グ璇嶅彲鑳界浉鍚岋紝杩斿洖鍊间篃鍙兘鐩稿悓銆�

鍦ㄧ▼搴忕殑缂栬瘧杩囩▼涓牴鎹彉閲忕被鍨嬫潵鎵剧浉搴旂殑鏂规硶銆傚洜姝や篃鏈変汉璁や负overloading鏄紪璇戞椂鐨勫鎬侊紝浠ュ悗鎴戜滑杩樹細瀛﹀埌杩愯鏃跺鎬併��

涓轰粈涔堜細瀛樺湪overloading鎶�鏈憿锛熶綔涓哄簲瀵规柟娉曠殑缁嗚妭銆�

鍒╃敤绫诲瀷鐨勫樊寮傛潵褰卞搷瀵规柟娉曠殑璋冪敤銆�

鍚冿紙锛夊彲浠ュ垎涓哄悆鑲夛紝鍚冭彍锛屽悆鑽紝鍦ㄤ竴涓被涓彲浠ュ畾涔夊涓悆鏂规硶銆�

鏋勯�犳柟娉曚篃鍙互瀹炵幇overloading銆備緥锛�

publicvoidteach(){};

publicvoidteach(int a){};

publicvoidteach(String a){}涓轰笁绉嶄笉鍚岀殑鏂规硶銆�

Overloading鏂规硶鏄粠浣庡悜楂樿浆銆�

Byte鈥攕hort鈥攆loat鈥攊nt鈥攍ong鈥攄ouble銆�

鍦ㄦ瀯閫犳柟娉曚腑锛�this琛ㄧず鏈被鐨勫叾浠栨瀯閫犳柟娉曪細

student(){};

student(string n){

this();//琛ㄧず璋冪敤student()

}

濡傛灉璋冪敤student(int a)鍒欎负this(int a)銆�

鐗瑰埆娉ㄦ剰锛氱敤this璋冪敤鍏朵粬鏋勯�犳柟娉曟椂锛�this蹇呴』涓虹涓�鏉¤鍙ワ紝鐒跺悗鎵嶆槸鍏朵粬璇彞銆�

This琛ㄧず褰撳墠瀵硅薄銆�

PublicvoidprintNum(){

Int number=40锛�

System.out.println(this.number);

}

姝ゆ椂鎵撳嵃鐨勬槸瀹炰緥鍙橀噺锛岃�岄潪灞�閮ㄥ彉閲忥紝鍗冲畾涔夊湪绫讳腑鑰岄潪鏂规硶涓殑鍙橀噺銆�

This.number琛ㄧず瀹炰緥鍙橀噺銆�

璋佽皟鐢�this.number閭d箞璋佸嵆涓哄綋鍓�(this)瀵硅薄鐨�number鏂规硶銆�

灏佽锛氫娇瀵硅薄鐨勫睘鎬у敖鍙兘绉佹湁锛屽璞$殑鏂规硶灏藉彲鑳界殑鍏紑銆傜敤private琛ㄧず姝ゆ垚鍛樺睘鎬т负璇ョ被鐨勭鏈夊睘鎬с��

Public琛ㄧず璇ュ睘鎬э紙鏂规硶锛夊叕寮�锛�

Private琛ㄧず璇ュ睘鎬э紙鏂规硶锛変负鍙湁鏈被鍐呴儴鍙互璁块棶锛堢被鍐呴儴鍙锛夈��

锛堟兂鐢�private杩樿鐢�set鍜�get鏂规硶渚涘叾浠栨柟娉曡皟鐢紝杩欐牱鍙互淇濊瘉瀵瑰睘鎬х殑璁块棶鏂瑰紡缁熶竴锛屽苟涓斾究浜庣淮鎶よ闂潈闄愪互鍙婂睘鎬ф暟鎹悎娉曟�э級

濡傛灉娌℃湁鐗规畩鎯呭喌锛屽睘鎬т竴瀹氱鏈夛紝鏂规硶璇ュ叕寮�鐨勫叕寮�銆�

濡傛灉涓嶆寚鏄庤皝璋冪敤鏂规硶锛屽垯榛樿涓�this銆�

鍖哄垎瀹炰緥鍙橀噺鍜屽眬閮ㄥ彉閲忔椂涓�瀹氳鍐�this銆�

11.29

缁ф壙锛�

鐖剁被锛�SuperClass锛夊拰瀛愮被锛�SonClass锛夈��

鐖剁被鐨勯潪绉佹湁鍖栧睘鎬у拰鏂规硶鍙互榛樿缁ф壙鍒板瓙绫汇��

Class Son extends Father{

}

鑰屽鏋滅埗绫讳腑鐨勭鏈夋柟娉曡瀛愮被璋冪敤鐨勮瘽锛屽垯缂栬瘧鎶ラ敊銆�

鐖剁被鐨勬瀯閫犳柟娉曞瓙绫讳笉鍙互缁ф壙锛屾洿涓嶅瓨鍦ㄨ鐩栫殑闂銆傦紙闈炴瀯閫犳柟娉曞彲浠ワ級

濡傛灉瀛愮被璁块棶鐖剁被鐨勬瀯閫犳柟娉曪紝鍒欏湪缂栬瘧鐨勬椂鍊欐彁绀鸿闂笉鍒拌鏂规硶銆�

JAVA涓笉鍏佽澶氱户鎵匡紝涓�涓被鏈変笖鍙湁涓�涓埗绫伙紙鍗曠户鎵匡級銆�

JAVA鐨勬暟鎹粨鏋勪负鏍戝瀷缁撴瀯锛岃�岄潪缃戠姸銆傦紙JAVA閫氳繃鎺ュ彛鍜屽唴閮ㄧ被瀹炵幇澶氱户鎵匡級

鏂规硶鐨勮鐩栵紙overriding锛�

鏂规硶鐨勯噸杞藉苟涓嶄竴瀹氭槸鍦ㄤ竴涓被涓細瀛愮被鍙互浠庣埗绫荤户鎵夸竴涓柟娉曪紝涔熷彲浠ュ畾涔変竴涓悓鍚嶅紓鍙傜殑鏂规硶锛屼篃绉颁负overloading銆�

褰撳瓙绫讳粠鐖剁被缁ф壙涓�涓棤鍙傛柟娉曪紝鑰屽張瀹氫箟浜嗕竴涓悓鏍风殑鏃犲弬鏂规硶锛屽垯瀛愮被鏂板啓鐨勬柟娉曡鐩栫埗绫荤殑鏂规硶锛岀О涓鸿鐩栥�傦紙娉ㄦ剰杩斿洖鍊肩被鍨嬩篃蹇呴』鐩稿悓锛屽惁鍒欑紪璇戝嚭閿欍�傦級

濡傛灉鏂规硶涓嶅悓锛屽垯鎴愰噸杞姐��

瀵逛簬鏂规硶鐨勪慨楗拌瘝锛屽瓙绫绘柟娉曡姣旂埗绫荤殑鏂规硶鑼冨洿鏇村姞鐨勫娉涖��

鐖剁被涓�public锛岄偅涔堝瓙绫讳负private鍒欏嚭鐜伴敊璇��

涔嬫墍浠ユ瀯閫犳柟娉曞厛杩愯鐖剁被鍐嶈繍琛屽瓙绫绘槸鍥犱负鏋勯�犳柟娉曟槸鏃犳硶瑕嗙洊鐨勩��

浠ヤ笅鑼冨洿渚濇鐢变弗鍒板锛�

private锛氭湰绫昏闂紱

default锛氳〃绀洪粯璁わ紝涓嶄粎鏈被璁块棶锛岃�屼笖鏄悓鍖呭彲瑙併��

Protected锛氬悓鍖呭彲瑙�+涓嶅悓鍖呯殑瀛愮被鍙

Public锛氳〃绀烘墍鏈夌殑鍦版柟鍧囧彲瑙併��

褰撴瀯閫犱竴涓璞$殑鏃跺�欙紝绯荤粺鍏堟瀯閫犵埗绫诲璞★紝鍐嶆瀯閫犲瓙绫诲璞°��

鏋勯�犱竴涓璞$殑椤哄簭锛氾紙娉ㄦ剰锛氭瀯閫犵埗绫诲璞$殑鏃跺�欎篃鏄繖鍑犳锛�

閫掑綊鍦版瀯閫犵埗绫诲璞★紱

椤哄簭鍦拌皟鐢ㄦ湰绫绘垚鍛樺睘鎬ц祴鍒濆�艰鍙ワ紱

鏈被鐨勬瀯閫犳柟娉曘��

Super()琛ㄧず璋冪敤鐖剁被鐨勬瀯閫犳柟娉曘��

Super()涔熷拰this涓�鏍峰繀椤绘斁鍦ㄧ涓�琛屻��

This()鐢ㄤ簬璋冪敤鏈被鐨勬瀯閫犳柟娉曘��

濡傛灉娌℃湁瀹氫箟鏋勯�犳柟娉曪紝閭d箞灏变細璋冪敤鐖剁被鐨勬棤鍙傛瀯閫犳柟娉曪紝鍗�super()銆�

瑕佸吇鎴愯壇濂界殑缂栫▼涔犳儻锛氬氨鏄鍔犱笂榛樿鐨勭埗绫绘棤鍙傜殑鏋勯�犳柟娉曘��

鎬濊�冿細鍙槸濡傛灉鎴戜滑娌℃湁瀹氫箟鏃犲弬鐨勬瀯閫犳柟娉曪紝鑰屽湪绋嬪簭涓瀯閫犱簡鏈夊弬鐨勬瀯閫犳柟娉曪紝閭d箞濡傛灉鏂规硶涓病鏈夊弬鏁帮紝閭d箞绯荤粺杩樹細璋冪敤鏈夊弬鐨勬瀯閫犳柟娉曚箞锛熷簲璇ヤ笉浼氥��

澶氭�侊細澶氭�佹寚鐨勬槸缂栬瘧鏃剁被鍨嬪彉鍖栵紝鑰岃繍琛屾椂绫诲瀷涓嶅彉銆�

澶氭�佸垎涓ょ锛�

缂栬瘧鏃跺鎬侊細缂栬瘧鏃跺姩鎬侀噸杞斤紱

杩愯鏃跺鎬侊細鎸囦竴涓璞″彲浠ュ叿鏈夊涓被鍨嬨��

瀵硅薄鏄瑙傜殑锛屼汉瀵瑰璞$殑璁よ瘑鏄富瑙傜殑銆�

渚嬶細

Animal a=new Dog()锛涙煡鐪嬫牸寮忓悕绉帮紱

Dog d=(Dog)a銆傚0鏄庣埗绫绘潵寮曠敤瀛愮被銆�

锛堟�濊�冧笂闈㈢殑鏍煎紡锛�

杩愯鏃跺鎬佺殑涓夊師鍒欙細锛堝簲鐢ㄦ椂涓鸿鐩栵級

瀵硅薄涓嶅彉锛涳紙鏀瑰彉鐨勬槸涓昏璁よ瘑锛�

瀵逛簬瀵硅薄鐨勮皟鐢ㄥ彧鑳介檺浜庣紪璇戞椂绫诲瀷鐨勬柟娉曪紝濡傝皟鐢ㄨ繍琛屾椂绫诲瀷鏂规硶鎶ラ敊銆�

鍦ㄤ笂闈㈢殑渚嬪瓙涓細Animal a=new Dog()锛涘璞�a鐨勭紪璇戞椂绫诲瀷涓�Animal锛岃繍琛屾椂绫诲瀷涓�dog銆�

娉ㄦ剰锛氱紪璇戞椂绫诲瀷涓�瀹氳涓鸿繍琛屾椂绫诲瀷鐨勭埗绫伙紙鎴栬�呭悓绫诲瀷锛夈��

瀵逛簬璇彞锛�Dog d=(Dog)a銆傚皢d寮哄埗澹版槑涓�a绫诲瀷锛屾鏃�d涓�Dog()锛屾鏃�d灏卞彲浠ヨ皟鐢ㄨ繍琛屾椂绫诲瀷銆傛敞鎰忥細a鍜�d鎸囧悜鍚屼竴瀵硅薄銆�

鍦ㄧ▼搴忕殑杩愯鏃讹紝鍔ㄦ�佺被鍨嬪垽瀹氥�傝繍琛屾椂璋冪敤杩愯鏃剁被鍨嬶紝鍗冲畠璋冪敤瑕嗙洊鍚庣殑鏂规硶銆�

鍏崇郴杩愮畻绗︼細instanceof

ainstanceof Animal;(杩欎釜寮忓瓙鐨勭粨鏋滄槸涓�涓竷灏旇〃杈惧紡)

a涓哄璞″彉閲忥紝Animal鏄被鍚嶃��

涓婇潰璇彞鏄垽瀹�a鏄惁鍙互璐�Animal鏍囩銆傚鏋滃彲浠ヨ创鍒欒繑鍥�true锛屽惁鍒欒繑鍥�false銆�

鍦ㄤ笂闈㈢殑棰樼洰涓細a instanceof Animal杩斿洖True锛�

a instanceof Dog涔熻繑鍥�True锛�

instanceof鐢ㄤ簬鍒ゅ畾鏄惁灏嗗墠闈㈢殑瀵硅薄鍙橀噺璧嬪�煎悗杈圭殑绫诲悕銆�

Instanceof涓�鑸敤浜庡湪寮哄埗绫诲瀷杞崲涔嬪墠鍒ゅ畾鍙橀噺鏄惁鍙互寮哄埗杞崲銆�

濡傛灉Animal a=new Animal()锛�

Dog d=Dog()a;

姝ゆ椂缂栬瘧鏃犺锛屼絾杩愯鍒欎細鎶ラ敊銆�

Animal a=new Dog()鐩稿綋浜庝笅闈㈣鍙ョ殑鍔熻兘锛�

Animal a=getAnimal()锛�

Public static Animal.getAnimal;

Return new Dog()锛�

灏佽銆佺户鎵裤�佸鎬佷负闈㈠悜瀵硅薄鐨勪笁澶у熀鐭筹紙鐗规�э級銆�

杩愯鏃剁殑鍔ㄦ�佺被鍨嬪垽瀹氶拡瀵圭殑鏄柟娉曘�傝繍琛岀▼搴忚闂殑灞炴�т粛涓虹紪璇戞椂灞炴�с��

Overloading閽堝鐨勬槸缂栬瘧鏃剁被鍨嬶紝涓嶅瓨鍦ㄨ繍琛屾椂鐨勫鎬併��

涔犻锛氬缓绔嬩竴涓�shape绫伙紝鏈�circle鍜�rect瀛愮被銆�

Shape绫绘湁zhouchang()鍜�area()涓ょ鏂规硶銆�

锛堟鏂瑰舰锛�squ涓�rect瀛愮被锛�rect鏈�cha()鐢ㄤ簬姣旇緝闀垮鐨勫樊銆�

瑕嗙洊鏃惰�冭檻瀛愮被鐨�private鍙婄埗绫荤殑public锛堣�冭檻澶氭�侊級锛屼箣鎵�浠ヨ繖鏍锋槸閬垮厤璋冪敤A鏃跺嚭鐜板疄闄呰皟鐢�B鐨勬儏鍐点�傝�屽嚭鐜伴敊璇��

11.29涓嬪崍璁茬殑鏄暀绋嬩笂鐨�Module6

Module6-7鍖呮嫭锛氶潰鍚戝璞¢珮绾с�佸唴閮ㄧ被銆侀泦鍚堛�佸弽灏勶紙鏆傛椂涓嶈锛夈�佷緥澶栥��

闈㈠悜瀵硅薄楂樼骇銆侀泦鍚堝拰渚嬪閮芥槸闈㈠悜瀵硅薄鐨勬牳蹇冨唴瀹广��

闈㈠悜瀵硅薄楂樼骇锛�淇グ绗︼細

static:鈶犲彲淇グ鍙橀噺锛堝睘鎬э級锛涒憽鍙慨楗版柟娉曪紱鈶㈠彲淇グ浠g爜鍧椼��

Static int data璇彞璇存槑data涓虹被鍙橀噺锛屼负涓�涓被鐨勫叡浜彉閲忥紝灞炰簬鏁翠釜绫汇��

Int data涓哄疄渚嬪彉閲忋��

渚嬶細

static int data;

m1.data=0;

m1.data++鐨勭粨鏋滀负1,姝ゆ椂m2.data鐨勭粨鏋滀篃涓�1銆�

Static瀹氫箟鐨勬槸涓�鍧椾负鏁翠釜绫诲叡鏈夌殑涓�鍧楀瓨鍌ㄥ尯鍩燂紝鍏跺彂鐢熷彉鍖栨椂璁块棶鍒扮殑鏁版嵁閮芥椂缁忚繃鍙樺寲鐨勩��

鍏跺彉閲忓彲浠ラ�氳繃绫诲悕鍘昏闂細绫诲悕.鍙橀噺鍚嶃�備笌閫氳繃璁块棶瀵硅薄鐨勭紪璇戞椂绫诲瀷璁块棶绫诲彉閲忎负绛変环鐨勩��

Public static voidprintData(){}

琛ㄦ槑姝ょ被鏂规硶涓虹被鏂规硶锛堥潤鎬佹柟娉曪級

闈欐�佹柟娉曚笉闇�瑕佹湁瀵硅薄锛屽彲浠ヤ娇鐢ㄧ被鍚嶈皟鐢ㄣ��

闈欐�佹柟娉曚腑涓嶅厑璁歌闂被鐨勯潪闈欐�佹垚鍛橈紝鍖呮嫭鎴愬憳鐨勫彉閲忓拰鏂规硶锛屽洜涓烘鏃舵槸閫氳繃绫昏皟鐢ㄧ殑锛屾病鏈夊璞$殑姒傚康銆�This.data鏄笉鍙敤鐨勩��

涓�鑸儏鍐典笅锛屼富鏂规硶鏄潤鎬佹柟娉曪紝鎵�浠ュ彲璋冪敤闈欐�佹柟娉曪紝涓绘柟娉曚负闈欐�佹柟娉曟槸鍥犱负瀹冩槸鏁翠釜杞欢绯荤粺鐨勫叆鍙o紝鑰岃繘鍏ュ叆鍙f椂绯荤粺涓病鏈変换浣曞璞★紝鍙兘浣跨敤绫昏皟鐢ㄣ��

瑕嗙洊涓嶉�傜敤浜庨潤鎬佹柟娉曘��

闈欐�佹柟娉曚笉鍙瑕嗙洊銆傦紙鍏佽鍦ㄥ瓙绫讳腑瀹氫箟鍚屽悕闈欐�佹柟娉曪紝浣嗘槸娌℃湁澶氭�侊紝涓ユ牸鐨勮锛屾柟娉曢棿娌℃湁澶氭�佸氨涓嶈兘绉颁负瑕嗙洊锛�

褰�static淇グ浠g爜鍧楁椂锛堟敞锛氭浠g爜鍧楄鍦ㄦ绫荤殑浠讳綍涓�涓柟娉曚箣澶栵級锛岄偅涔堣繖涓唬鐮佸潡鍦ㄤ唬鐮佽瑁呰浇杩涜櫄鎷熸満鐢熸垚瀵硅薄鐨勬椂鍊欏彲琚杞戒竴娆★紝浠ュ悗鍐嶄篃涓嶆墽琛屼簡銆�

涓�鑸潤鎬佷唬鐮佸潡琚敤鏉ュ垵濮嬪寲闈欐�佹垚鍛樸��

Static閫氬父鐢ㄤ簬Singleton妯″紡寮�鍙戯細

Singleton鏄竴绉嶈璁℃ā寮忥紝楂樹簬璇硶锛屽彲浠ヤ繚璇佷竴涓被鍦ㄦ暣涓郴缁熶腑浠呮湁涓�涓璞°��

11.30

final鍙互淇グ绫汇�佸睘鎬с�佹柟娉曘��

褰撶敤final淇グ绫荤殑鏃跺�欙紝姝ょ被涓嶅彲琚户鎵匡紝鍗�final绫绘病鏈夊瓙绫汇�傝繖鏍峰彲浠ョ敤final淇濊瘉鐢ㄦ埛璋冪敤鏃跺姩浣滅殑涓�鑷存�э紝鍙互闃叉瀛愮被瑕嗙洊鎯呭喌鐨勫彂鐢熴��

褰撳埄鐢�final淇グ涓�涓睘鎬э紙鍙橀噺锛夌殑鏃跺�欙紝姝ゆ椂鐨勫睘鎬ф垚涓哄父閲忋��

JAVA鍒╃敤final瀹氫箟甯搁噺锛堟敞鎰忓湪JAVA鍛藉悕瑙勮寖涓父閲忛渶瑕佸叏閮ㄥ瓧姣嶉兘澶у啓锛夛細

Final int AGE=10锛�

甯搁噺鐨勫湴鍧�涓嶅彲鏀瑰彉锛屼絾鍦ㄥ湴鍧�涓繚瀛樼殑鍊硷紙鍗冲璞$殑灞炴�э級鏄彲浠ユ敼鍙樼殑銆�

Final鍙互閰嶅悎static浣跨敤銆�锛�

Static final int age=10锛�

鍦�JAVA涓埄鐢�public static final鐨勭粍鍚堟柟寮忓甯搁噺杩涜鏍囪瘑锛堝浐瀹氭牸寮忥級銆�

瀵逛簬鍦ㄦ瀯閫犳柟娉曚腑鍒╃敤final杩涜璧嬪�肩殑鏃跺�欙紝姝ゆ椂鍦ㄦ瀯閫犱箣鍓嶇郴缁熻缃殑榛樿鍊肩浉瀵逛簬鏋勯�犳柟娉曞け鏁堛��

甯搁噺锛堣繖閲岀殑甯搁噺鎸囩殑鏄疄渚嬪父閲忥細鍗虫垚鍛樺彉閲忥級璧嬪�硷細

鈶犲湪鍒濆鍖栫殑鏃跺�欓�氳繃鏄惧紡澹版槑璧嬪�笺��Final int x=3锛�

鈶″湪鏋勯�犵殑鏃跺�欒祴鍊笺��

灞�閮ㄥ彉閲忓彲浠ラ殢鏃惰祴鍊笺��

鍒╃敤final瀹氫箟鏂规硶锛氳繖鏍风殑鏂规硶涓轰竴涓笉鍙鐩栫殑鏂规硶銆�

Public final void print(){}锛�

涓轰簡淇濊瘉鏂规硶鐨勪竴鑷存�э紙鍗充笉琚敼鍙橈級锛屽彲灏嗘柟娉曠敤final瀹氫箟銆�

濡傛灉鍦ㄧ埗绫讳腑鏈�final瀹氫箟鐨勬柟娉曪紝閭d箞鍦ㄥ瓙绫讳腑缁ф壙鍚屼竴涓柟娉曘��

濡傛灉涓�涓柟娉曞墠鏈変慨楗拌瘝private鎴�static锛屽垯绯荤粺浼氳嚜鍔ㄥ湪鍓嶉潰鍔犱笂final銆傚嵆private鍜�static鏂规硶榛樿鍧囦负final鏂规硶銆�

娉細final骞朵笉娑夊強缁ф壙锛岀户鎵垮彇鍐充簬绫荤殑淇グ绗︽槸鍚︿负private銆�default銆�protected杩樻槸public銆備篃灏辨槸璇达紝鏄惁缁ф壙鍙栧喅浜庤繖涓柟娉曞浜庡瓙绫绘槸鍚﹀彲瑙併��

Abstract(鎶借薄)鍙互淇グ绫汇�佹柟娉�

濡傛灉灏嗕竴涓被璁剧疆涓�abstract锛屽垯姝ょ被蹇呴』琚户鎵夸娇鐢ㄣ�傛绫讳笉鍙敓鎴愬璞★紝蹇呴』琚户鎵夸娇鐢ㄣ��

Abstract鍙互灏嗗瓙绫荤殑鍏辨�ф渶澶ч檺搴︾殑鎶藉彇鍑烘潵锛屾斁鍦ㄧ埗绫讳腑锛屼互鎻愰珮绋嬪簭鐨勭畝娲佹�с��

Abstract铏界劧涓嶈兘鐢熸垚瀵硅薄锛屼絾鏄彲浠ュ0鏄庯紝浣滀负缂栬瘧鏃剁被鍨嬶紝浣嗕笉鑳戒綔涓鸿繍琛屾椂绫诲瀷銆�

Final鍜�abstract姘歌繙涓嶄細鍚屾椂鍑虹幇銆�

褰�abstract鐢ㄤ簬淇グ鏂规硶鏃讹紝姝ゆ椂璇ユ柟娉曚负鎶借薄鏂规硶锛屾鏃舵柟娉曚笉闇�瑕佸疄鐜帮紝瀹炵幇鐣欑粰瀛愮被瑕嗙洊锛屽瓙绫昏鐩栬鏂规硶涔嬪悗鏂规硶鎵嶈兘澶熺敓鏁堛��

娉ㄦ剰姣旇緝锛�

private void print(){}锛涙璇彞琛ㄧず鏂规硶鐨勭┖瀹炵幇銆�

Abstract void print()锛�姝よ鍙ヨ〃绀烘柟娉曠殑鎶借薄锛屾棤瀹炵幇銆�

濡傛灉涓�涓被涓湁涓�涓娊璞℃柟娉曪紝閭d箞杩欎釜绫讳竴瀹氫负涓�涓娊璞$被銆�

鍙嶄箣锛屽鏋滀竴涓被涓烘娊璞$被锛岄偅涔堝叾涓彲鑳芥湁闈炴娊璞$殑鏂规硶銆�

濡傛灉璁╀竴涓潪鎶借薄绫荤户鎵夸竴涓惈鎶借薄鏂规硶鐨勬娊璞$被锛屽垯缂栬瘧鏃朵細鍙戠敓閿欒銆傚洜涓哄綋涓�涓潪鎶借薄绫荤户鎵夸竴涓娊璞℃柟娉曠殑鏃跺�欙紝鏈潃鍙湁涓�涓被涓湁涓�涓娊璞℃柟娉曪紝閭d箞杩欎釜绫诲繀椤讳负鎶借薄绫荤殑鍘熷垯銆傝繖涓被蹇呴』涓烘娊璞$被锛岃繖涓庢绫讳负闈炴娊璞″啿绐侊紝鎵�浠ユ姤閿欍��

鎵�浠ュ瓙绫荤殑鏂规硶蹇呴』瑕嗙洊鐖剁被鐨勬娊璞℃柟娉曘�傛柟娉曟墠鑳藉璧蜂綔鐢ㄣ��

鍙湁灏嗙悊璁鸿鐔熺粌杩愮敤鍦ㄥ疄闄呯殑绋嬪簭璁捐鐨勮繃绋嬩腑涔嬪悗锛屾墠鑳借鐞嗚琚畬鍏ㄦ帉鎻★紒

涓轰簡瀹炵幇澶氭�侊紝閭d箞鐖剁被蹇呴』鏈夊畾涔夈�傝�岀埗绫诲苟涓嶅疄鐜帮紝鐣欑粰瀛愮被鍘诲疄鐜般�傛鏃跺彲灏嗙埗绫诲畾涔夋垚abstract绫汇�傚鏋滄病鏈夊畾涔夋娊璞$殑鐖剁被锛岄偅涔堢紪璇戜細鍑虹幇閿欒銆�

Abstract鍜�static涓嶈兘鏀惧湪涓�璧凤紝鍚﹀垯渚夸細鍑虹幇閿欒銆傦紙杩欐槸鍥犱负static涓嶅彲琚鐩栵紝鑰�abstract涓轰簡鐢熸晥蹇呴』琚鐩栥�傦級

渚嬶細锛堟湰渚嬪凡瀛樺湪\CODING\abstract\TestClass.java鏂囦欢涓級

public class TestClass{

public static void main(String[] args){

SuperClass sc=new SubClass();

Sc.print();

}

Abstract class SuperClass{

Abstract void print();}

}

class SubClass extends SuperClass(){

void print(){

System.out.println(鈥減rint鈥�);}

}

JAVA鐨勬牳蹇冩蹇碉細鎺ュ彛锛�interface锛�

鎺ュ彛涓庣被灞炰簬鍚屼竴灞傛锛屽疄闄呬笂锛屾帴鍙f槸涓�绉嶇壒娈婄殑鎶借薄绫汇��

濡�:

interface IA{

}

public interface锛氬叕寮�鎺ュ彛

涓庣被鐩镐技锛屼竴涓枃浠跺彧鑳芥湁涓�涓�public鎺ュ彛锛屼笖涓庢枃浠跺悕鐩稿悓銆�

鍦ㄤ竴涓枃浠朵腑涓嶅彲鍚屾椂瀹氫箟涓�涓�public鎺ュ彛鍜屼竴涓�public绫汇��

涓�涓帴鍙d腑锛屾墍鏈夋柟娉曚负鍏紑銆佹娊璞℃柟娉曪紱鎵�鏈夌殑灞炴�ч兘鏄叕寮�銆侀潤鎬併�佸父閲忋��

涓�涓被瀹炵幇涓�涓帴鍙g殑鏍煎紡锛�

class IAImple implements IA{

};

涓�涓被瀹炵幇鎺ュ彛锛岀浉褰撲簬瀹冪户鎵夸竴涓娊璞$被銆�

绫诲繀椤诲疄鐜版帴鍙d腑鐨勬柟娉曪紝鍚﹀垯鍏朵负涓�鎶借薄绫汇��

瀹炵幇涓帴鍙e拰绫荤浉鍚屻��

鎺ュ彛涓彲涓嶅啓public锛屼絾鍦ㄥ瓙绫讳腑瀹炵幇鎺ュ彛鐨勮繃绋嬩腑public涓嶅彲鐪併��

锛堝鏋滃墿鍘�public鍒欏湪缂栬瘧鐨勬椂鍊欐彁绀哄嚭閿欙細瀵硅薄鏃犳硶浠庢帴鍙d腑瀹炵幇鏂规硶銆傦級

娉細

涓�涓被闄ょ户鎵垮彟澶栦竴涓被锛岃繕鍙互瀹炵幇鎺ュ彛锛�

class IAImplextends java.util.Arrylistimplement IA{}

缁ф壙绫�瀹炵幇鎺ュ彛

杩欐牱鍙互瀹炵幇鍙樼浉鐨勫缁ф壙銆�

涓�涓被鍙兘缁ф壙鍙﹀涓�涓被锛屼絾鏄畠鍙互缁ф壙澶氫釜鎺ュ彛锛屼腑闂寸敤鈥�锛�鈥�闅斿紑銆�

Implements IA,IB

鎵�璋撳疄鐜颁竴涓帴鍙o紝灏辨槸鎸囧疄鐜版帴鍙d腑鐨勬柟娉曘��

鎺ュ彛鍜屾帴鍙d箣闂村彲浠ュ畾涔夌户鎵垮叧绯伙紝骞朵笖鎺ュ彛涔嬮棿鍏佽瀹炵幇澶氱户鎵裤��

渚嬶細interface IC extends IA,IB{};

鎺ュ彛涔熷彲浠ョ敤浜庡畾涔夊璞�

IA I=new IAImpl();

瀹炵幇鐨勭被浠庣埗绫诲拰鎺ュ彛缁ф壙鐨勯兘鍙仛杩愯鏃剁被鍨嬨��

IAImple extends A implement IA,IB

IB I=new IAImple();

I instance of IAImple;

I instance of A;

I instance of IA;

I instance of IB;

杩斿洖鐨勭粨鏋滃潎涓�true.

鎺ュ彛鍜屽鎬侀兘涓�JAVA鎶�鏈殑鏍稿績銆�

鎺ュ彛寰�寰�琚垜浠畾涔夋垚涓�绫�XX鐨勪笢瑗裤��

鎺ュ彛瀹為檯涓婃槸瀹氫箟涓�涓鑼冦�佹爣鍑嗐��

閫氳繃鎺ュ彛鍙互瀹炵幇涓嶅悓灞傛銆佷笉鍚屼綋绯诲璞$殑鍏卞悓灞炴�э紱

閫氳繃鎺ュ彛瀹炵幇write once as anywhere.

浠�JAVA鏁版嵁搴撹繛鎺ヤ负渚嬪瓙锛�JDBC鍒跺畾鏍囧噯锛涙暟鎹巶鍟嗗疄鐜版爣鍑嗭紱鐢ㄦ埛浣跨敤鏍囧噯銆�

鎺ュ彛閫氬父鐢ㄦ潵灞忚斀搴曞眰鐨勫樊寮傘��

鈶℃帴鍙d篃鍥犱负涓婅堪鍘熷洜琚敤鏉ヤ繚鎸佹灦鏋勭殑绋冲畾鎬с��

JAVA涓湁涓�涓壒娈婄殑绫伙細Object銆傚畠鏄�JAVA浣撶郴涓墍鏈夌被鐨勭埗绫伙紙鐩存帴鐖剁被鎴栬�呴棿鎺ョ埗绫伙級銆�

姝ょ被涓殑鏂规硶鍙互浣挎墍鐨勭被鍧囩户鎵裤��

浠ヤ笅浠嬬粛鐨勪笁绉嶆柟娉曞睘浜�Object:

finalize鏂规硶锛氬綋涓�涓璞¤鍨冨溇鍥炴敹鐨勬椂鍊欒皟鐢ㄧ殑鏂规硶銆�

toString():鏄埄鐢ㄥ瓧绗︿覆鏉ヨ〃绀哄璞°��

褰撴垜浠洿鎺ユ墦鍗板畾涔夌殑瀵硅薄鐨勬椂鍊欙紝闅愬惈鐨勬槸鎵撳嵃toString()鐨勮繑鍥炲�笺��

鍙互閫氳繃瀛愮被浣滀负涓�涓�toString()鏉ヨ鐩栫埗绫荤殑toString()銆�

浠ュ彇寰楁垜浠兂寰楀埌鐨勮〃鐜板舰寮忥紝鍗冲綋鎴戜滑鎯冲埄鐢ㄤ竴涓嚜瀹氫箟鐨勬柟寮忔弿杩板璞$殑鏃跺�欙紝鎴戜滑搴旇瑕嗙洊toString()銆�

(3)equal

棣栧厛璇曟瘮杈冧笅渚嬶細

String A=new String(鈥渉ello鈥�);

String A=new String(鈥渉ello鈥�);

A==B(姝ゆ椂绋嬪簭杩斿洖涓�FALSE)

鍥犱负姝ゆ椂AB涓瓨鐨勬槸鍦板潃锛屽洜涓哄垱寤轰簡鏂扮殑瀵硅薄锛屾墍浠ュ瓨鏀剧殑鏄笉鍚岀殑鍦板潃銆�

闄勫姞鐭ヨ瘑锛�

瀛楃涓茬被涓�JAVA涓殑鐗规畩绫伙紝String涓负final绫伙紝涓�涓瓧绗︿覆鐨勫�间笉鍙噸澶嶃�傚洜姝ゅ湪JAVA VM锛堣櫄鎷熸満锛変腑鏈変竴涓瓧绗︿覆姹狅紝涓撻棬鐢ㄦ潵瀛樺偍瀛楃涓层�傚鏋滈亣鍒�String a=鈥漢ello鈥�鏃讹紙娉ㄦ剰娌℃湁NEW锛屼笉鏄垱寤烘柊涓诧級锛岀郴缁熷湪瀛楃涓叉睜涓鎵炬槸鍚︽湁鈥漢ello鈥�锛屾鏃跺瓧绗︿覆姹犱腑娌℃湁鈥漢ello鈥�锛岄偅涔堢郴缁熷皢姝ゅ瓧绗︿覆瀛樺埌瀛楃涓叉睜涓紝鐒跺悗灏�鈥漢ello鈥�鍦ㄥ瓧绗︿覆姹犱腑鐨勫湴鍧�杩斿洖a銆傚鏋滅郴缁熷啀閬囧埌String b=鈥漢ello鈥�锛屾鏃剁郴缁熷彲浠ュ湪瀛楃涓叉睜涓壘鍒�鈥渉ello鈥�銆傚垯浼氭妸鍦板潃杩斿洖b锛屾鏃�a涓�b涓虹浉鍚屻��

String a=鈥漢ello鈥�;

System.out.println(a==鈥漢ello鈥�);

绯荤粺鐨勮繑鍥炲�间负true銆�

鏁呭鏋滆姣旇緝涓や釜瀛楃涓叉槸鍚︾浉鍚岋紙鑰屼笉鏄粬浠殑鍦板潃鏄惁鐩稿悓锛夈�傚彲浠ュa璋冪敤equal:

System.out.println(a.equal(b));

equal鐢ㄦ潵姣旇緝涓や釜瀵硅薄涓瓧绗︿覆鐨勯『搴忋��

a.equal(b)鏄�a涓�b鐨勫�肩殑姣旇緝銆�

娉ㄦ剰涓嬮潰绋嬪簭锛�

student a=new student(鈥淟UCY鈥�,20);

student b=new student(鈥淟UCY鈥�,20);

System.out.println(a==b);

System.out.println(a.equal(b));

姝ゆ椂杩斿洖鐨勭粨鏋滃潎涓�false銆�

浠ヤ笅涓哄畾涔�equal锛堝姞涓婅繖涓畾涔夛紝杩斿洖ture鎴�false锛�

public boolean equals(Object o){

student s=(student)o;

if (s.name.equals(this.name)&&s.age==this.age)

else return false;

}濡傛灉equals()杩斿洖鐨勫�间负

浠ヤ笅涓哄疄鐜版爣鍑�equals鐨勬祦绋嬶細

public boolean equals(Object o){

if (this==o) return trun;//姝ゆ椂涓よ�呯浉鍚�

if (o==null) return false;

if (! o instanceof strudent) return false;//涓嶅悓绫�

studeng s=(student)o; //寮哄埗杞崲

if (s.name.equals(this.name)&&s.age==this.age) return true;

else return false;

}

浠ヤ笂杩囩▼涓哄疄鐜�equals鐨勬爣鍑嗚繃绋嬨��

缁冧範锛氬缓绔嬩竴涓�employee绫伙紝鏈�String name,int id,double salary.杩愮敤get鍜�set鏂规硶锛屼娇鐢�toString锛屼娇鐢�equals銆�

灏佽绫伙細

JAVA涓烘瘡涓�涓畝鍗曟暟鎹被鍨嬫彁渚涗簡涓�涓皝瑁呯被锛屼娇姣忎釜绠�鍗曟暟鎹被鍨嬪彲浠ヨObject鏉ヨ杞姐��

闄や簡int鍜�char锛屽叾浣欑被鍨嬮瀛楁瘝澶у啓鍗虫垚灏佽绫汇��

杞崲瀛楃鐨勬柟寮忥細

int I=10;

String s=I+鈥� 鈥�;

String s1=String.valueOf(i);

Int I=10;

Interger I_class=new integer(I);

鐪�javadoc鐨勫府鍔╂枃妗c��

闄勫姞鍐呭锛�

鈥�==鈥�鍦ㄤ换浣曟椂鍊欓兘鏄瘮杈冨湴鍧�锛岃繖绉嶆瘮杈冩案杩滀笉浼氳瑕嗙洊銆�

绋嬪簭鍛樿嚜宸辩紪鍐欑殑绫诲拰JDK绫绘槸涓�绉嶅悎浣滃叧绯汇�傦紙鍥犱负澶氭�佺殑瀛樺湪锛屽彲鑳藉瓨鍦ㄦ垜浠皟鐢�JDK绫荤殑鎯呭喌锛屼篃鍙兘瀛樺湪JDK鑷姩璋冪敤鎴戜滑鐨勭被鐨勬儏鍐点�傦級

娉ㄦ剰锛氱被鍨嬭浆鎹腑double\interger\string涔嬮棿鐨勮浆鎹㈡渶澶氥��

12.01

鍐呴儴绫伙細

锛堟敞锛氭墍鏈変娇鐢ㄥ唴閮ㄧ被鐨勫湴鏂归兘鍙互涓嶇敤鍐呴儴绫伙紝浣跨敤鍐呴儴绫诲彲浠ヤ娇绋嬪簭鏇村姞鐨勭畝娲侊紝渚夸簬鍛藉悕瑙勮寖鍜屽垝鍒嗗眰娆$粨鏋勶級銆�

鍐呴儴绫绘槸鎸囧湪涓�涓閮ㄧ被鐨勫唴閮ㄥ啀瀹氫箟涓�涓被銆�

鍐呴儴绫讳綔涓哄閮ㄧ被鐨勪竴涓垚鍛橈紝骞朵笖渚濋檮浜庡閮ㄧ被鑰屽瓨鍦ㄧ殑銆�

鍐呴儴绫诲彲涓洪潤鎬侊紝鍙敤PROTECTED鍜�PRIVATE淇グ銆傦紙鑰屽閮ㄧ被涓嶅彲浠ワ細澶栭儴绫诲彧鑳戒娇鐢�PUBLIC鍜�DEFAULT锛夈��

鍐呴儴绫荤殑鍒嗙被锛�

鎴愬憳鍐呴儴绫汇��

灞�閮ㄥ唴閮ㄧ被銆�

闈欐�佸唴閮ㄧ被銆�

鍖垮悕鍐呴儴绫伙紙鍥惧舰鏄鐢ㄥ埌锛屽繀椤绘帉鎻★級銆�

鎴愬憳鍐呴儴绫伙細浣滀负澶栭儴绫荤殑涓�涓垚鍛樺瓨鍦紝涓庡閮ㄧ被鐨勫睘鎬с�佹柟娉曞苟鍒椼��

鍐呴儴绫诲拰澶栭儴绫荤殑瀹炰緥鍙橀噺鍙互鍏卞瓨銆�

鍦ㄥ唴閮ㄧ被涓闂疄渚嬪彉閲忥細this.灞炴��

鍦ㄥ唴閮ㄧ被璁块棶澶栭儴绫荤殑瀹炰緥鍙橀噺锛氬閮ㄧ被鍚�.this.灞炴�с��

鎴愬憳鍐呴儴绫荤殑浼樼偣锛�

鈶村唴閮ㄧ被浣滀负澶栭儴绫荤殑鎴愬憳锛屽彲浠ヨ闂閮ㄧ被鐨勭鏈夋垚鍛樻垨灞炴�с�傦紙鍗充娇灏嗗閮ㄧ被澹版槑涓�PRIVATE锛屼絾鏄浜庡浜庡叾鍐呴儴鐨勫唴閮ㄧ被杩樻槸鍙鐨勩�傦級

鈶电敤鍐呴儴绫诲畾涔夊湪澶栭儴绫讳腑涓嶅彲璁块棶鐨勫睘鎬с�傝繖鏍峰氨鍦ㄥ閮ㄧ被涓疄鐜颁簡姣斿閮ㄧ被鐨�private杩樿灏忕殑璁块棶鏉冮檺銆�

娉ㄦ剰锛氬唴閮ㄧ被鏄竴涓紪璇戞椂鐨勬蹇碉紝涓�鏃︾紪璇戞垚鍔燂紝灏变細鎴愪负瀹屽叏涓嶅悓鐨勪袱绫汇��

瀵逛簬涓�涓悕涓�outer鐨勫閮ㄧ被鍜屽叾鍐呴儴瀹氫箟鐨勫悕涓�inner鐨勫唴閮ㄧ被銆傜紪璇戝畬鎴愬悗鍑虹幇outer.class鍜�outer$inner.class涓ょ被銆�

锛堢紪鍐欎竴涓▼搴忔楠岋細鍦ㄤ竴涓�TestOuter.java绋嬪簭涓獙璇佸唴閮ㄧ被鍦ㄧ紪璇戝畬鎴愪箣鍚庯紝浼氬嚭鐜板嚑涓�class.锛�

鎴愬憳鍐呴儴绫讳笉鍙互鏈夐潤鎬佸睘鎬с��锛堜负浠�涔堬紵锛�

濡傛灉鍦ㄥ閮ㄧ被鐨勫閮ㄨ闂唴閮ㄧ被锛屼娇鐢�out.inner.

寤虹珛鍐呴儴绫诲璞℃椂搴旀敞鎰忥細

鍦ㄥ閮ㄧ被鐨勫唴閮ㄥ彲浠ョ洿鎺ヤ娇鐢�inner s=new inner();锛堝洜涓哄閮ㄧ被鐭ラ亾inner鏄摢涓被锛屾墍浠ュ彲浠ョ敓鎴愬璞°�傦級

鑰屽湪澶栭儴绫荤殑澶栭儴锛岃鐢熸垚锛�new锛変竴涓唴閮ㄧ被瀵硅薄锛岄渶瑕侀鍏堝缓绔嬩竴涓閮ㄧ被瀵硅薄锛堝閮ㄧ被鍙敤锛夛紝鐒跺悗鍦ㄧ敓鎴愪竴涓唴閮ㄧ被瀵硅薄銆�

Outer.Inner in=Outer.new.Inner()銆�

閿欒鐨勫畾涔夋柟寮忥細

Outer.Inner in=new Outer.Inner()銆�

娉ㄦ剰锛氬綋Outer鏄竴涓�private绫绘椂锛屽閮ㄧ被瀵逛簬鍏跺閮ㄨ闂槸绉佹湁鐨勶紝鎵�浠ュ氨鏃犳硶寤虹珛澶栭儴绫诲璞★紝杩涜�屼篃鏃犳硶寤虹珛鍐呴儴绫诲璞°��

灞�閮ㄥ唴閮ㄧ被锛氬湪鏂规硶涓畾涔夌殑鍐呴儴绫荤О涓哄眬閮ㄥ唴閮ㄧ被銆�

涓庡眬閮ㄥ彉閲忕被浼硷紝鍦ㄥ眬閮ㄥ唴閮ㄧ被鍓嶄笉鍔犱慨楗扮public鍜�private锛屽叾鑼冨洿涓哄畾涔夊畠鐨勪唬鐮佸潡銆�

娉ㄦ剰锛氬眬閮ㄥ唴閮ㄧ被涓嶄粎鍙互璁块棶澶栭儴绫诲疄渚嬪彉閲忥紝杩樺彲浠ヨ闂閮ㄧ被鐨勫眬閮ㄥ彉閲忥紙浣嗘鏃惰姹傚閮ㄧ被鐨勫眬閮ㄥ彉閲忓繀椤讳负final锛�锛燂紵

鍦ㄧ被澶栦笉鍙洿鎺ョ敓鎴愬眬閮ㄥ唴閮ㄧ被锛堜繚璇佸眬閮ㄥ唴閮ㄧ被瀵瑰鏄笉鍙鐨勶級銆�

瑕佹兂浣跨敤灞�閮ㄥ唴閮ㄧ被鏃堕渶瑕佺敓鎴愬璞★紝瀵硅薄璋冪敤鏂规硶锛屽湪鏂规硶涓墠鑳借皟鐢ㄥ叾灞�閮ㄥ唴閮ㄧ被銆�

闈欐�佸唴閮ㄧ被锛氾紙娉ㄦ剰锛氬墠涓夌鍐呴儴绫讳笌鍙橀噺绫讳技锛屾墍浠ュ彲浠ュ鐓у弬鑰冨彉閲忥級

闈欐�佸唴閮ㄧ被瀹氫箟鍦ㄧ被涓紝浠讳綍鏂规硶澶栵紝鐢�static瀹氫箟銆�

闈欐�佸唴閮ㄧ被鍙兘璁块棶澶栭儴绫荤殑闈欐�佹垚鍛樸��

鐢熸垚锛�new锛変竴涓潤鎬佸唴閮ㄧ被涓嶉渶瑕佸閮ㄧ被鎴愬憳锛氳繖鏄潤鎬佸唴閮ㄧ被鍜屾垚鍛樺唴閮ㄧ被鐨勫尯鍒�傞潤鎬佸唴閮ㄧ被鐨勫璞″彲浠ョ洿鎺ョ敓鎴愶細

Outer.Inner in=new Outer.Inner()锛�

鑰屼笉闇�瑕侀�氳繃鐢熸垚澶栭儴绫诲璞℃潵鐢熸垚銆傝繖鏍峰疄闄呬笂浣块潤鎬佸唴閮ㄧ被鎴愪负浜嗕竴涓《绾х被銆�

闈欐�佸唴閮ㄧ被涓嶅彲鐢�private鏉ヨ繘琛屽畾涔夈�備緥瀛愶細

瀵逛簬涓や釜绫伙紝鎷ユ湁鐩稿悓鐨勬柟娉曪細

People

{

run();

}

Machine{

run();

}

姝ゆ椂鏈変竴涓�robot绫伙細

class Robot extends People implement Machine.

姝ゆ椂run()涓嶅彲鐩存帴瀹炵幇銆�

娉ㄦ剰锛氬綋绫讳笌鎺ュ彛锛堟垨鑰呮槸鎺ュ彛涓庢帴鍙o級鍙戠敓鏂规硶鍛藉悕鍐茬獊鐨勬椂鍊欙紝姝ゆ椂蹇呴』浣跨敤鍐呴儴绫绘潵瀹炵幇銆�

鐢ㄦ帴鍙d笉鑳藉畬鍏ㄥ湴瀹炵幇澶氱户鎵匡紝鐢ㄦ帴鍙i厤鍚堝唴閮ㄧ被鎵嶈兘瀹炵幇鐪熸鐨勫缁ф壙銆�

鍖垮悕鍐呴儴绫伙紙蹇呴』鎺屾彙锛夛細

鍖垮悕鍐呴儴绫绘槸涓�绉嶇壒娈婄殑灞�閮ㄥ唴閮ㄧ被锛屽畠鏄�氳繃鍖垮悕绫诲疄鐜版帴鍙c��

IA琚畾涔変负鎺ュ彛銆�

IA I=new IA(){};

娉細涓�涓尶鍚嶅唴閮ㄧ被涓�瀹氭槸鍦�new鐨勫悗闈紝鐢ㄥ叾闅愬惈瀹炵幇涓�涓帴鍙f垨瀹炵幇涓�涓被锛屾病鏈夌被鍚嶏紝鏍规嵁澶氭�侊紝鎴戜滑浣跨敤鍏剁埗绫诲悕銆�

鍥犲叾涓哄眬閮ㄥ唴閮ㄧ被锛岄偅涔堝眬閮ㄥ唴閮ㄧ被鐨勬墍鏈夐檺鍒堕兘瀵瑰叾鐢熸晥銆�

鍖垮悕鍐呴儴绫绘槸鍞竴涓�绉嶆棤鏋勯�犳柟娉曠被銆�

鍖垮悕鍐呴儴绫诲湪缂栬瘧鐨勬椂鍊欑敱绯荤粺鑷姩璧峰悕Out$1.class銆�

濡傛灉涓�涓璞$紪璇戞椂鐨勭被鍨嬫槸鎺ュ彛锛岄偅涔堝叾杩愯鐨勭被鍨嬩负瀹炵幇杩欎釜鎺ュ彛鐨勭被銆�

鍥犲尶鍚嶅唴閮ㄧ被鏃犳瀯閫犳柟娉曪紝鎵�浠ュ叾浣跨敤鑼冨洿闈炲父鐨勬湁闄愩��

锛堜笅鍗堬細锛�Exception锛堜緥澶�/寮傚父锛夛紙鏁欑▼涓婄殑MODEL7锛�

瀵逛簬绋嬪簭鍙兘鍑虹幇鐨勯敊璇簲璇ュ仛鍑洪妗堛��

渚嬪鏄▼搴忎腑鎵�鏈夊嚭涔庢剰鏂欑殑缁撴灉銆傦紙鍏崇郴鍒扮郴缁熺殑鍋ュ.鎬э級

JAVA浼氬皢鎵�鏈夌殑閿欒灏佽鎴愪负涓�涓璞★紝鍏舵牴鏈埗绫讳负Throwable銆�

Throwable鏈変袱涓瓙绫伙細Error鍜�Exception銆�

涓�涓�Error瀵硅薄琛ㄧず涓�涓▼搴忛敊璇紝鎸囩殑鏄簳灞傜殑銆佷綆绾х殑銆佷笉鍙仮澶嶇殑涓ラ噸閿欒銆傛鏃剁▼搴忎竴瀹氫細閫�鍑猴紝鍥犱负宸茬粡澶卞幓浜嗚繍琛屾墍蹇呴』鐨勭墿鐞嗙幆澧冦��

瀵逛簬Error閿欒鎴戜滑鏃犳硶杩涜澶勭悊锛屽洜涓烘垜浠槸閫氳繃绋嬪簭鏉ュ簲瀵归敊璇紝鍙槸绋嬪簭宸茬粡閫�鍑轰簡銆�

鎴戜滑鍙互澶勭悊鐨�Throwable瀵硅薄涓彧鏈�Exception瀵硅薄锛堜緥澶�/寮傚父锛夈��

Exception鏈変袱涓瓙绫伙細Runtime exception锛堟湭妫�鏌ュ紓甯革級

闈�Runtime exception锛堝凡妫�鏌ュ紓甯革級

锛堟敞鎰忥細鏃犺鏄湭妫�鏌ュ紓甯歌繕鏄凡妫�鏌ュ紓甯稿湪缂栬瘧鐨勬椂鍊欓兘涓嶄細琚彂鐜帮紝鍦ㄧ紪璇戠殑杩囩▼涓鏌ョ殑鏄▼搴忕殑璇硶閿欒锛岃�屽紓甯告槸涓�涓繍琛屾椂绋嬪簭鍑洪敊鐨勬蹇点�傦級

鍦�Exception涓紝鎵�鏈夌殑闈炴湭妫�鏌ュ紓甯搁兘鏄凡妫�鏌ュ紓甯革紝娌℃湁鍙﹀鐨勫紓甯革紒锛�

鏈鏌ュ紓甯告槸鍥犱负绋嬪簭鍛樻病鏈夎繘琛屽繀瑕佺殑妫�鏌ワ紝鍥犱负浠栫殑鐤忓拷鍜岄敊璇�屽紩璧风殑寮傚父銆備竴瀹氭槸灞炰簬铏氭嫙鏈哄唴閮ㄧ殑寮傚父锛堟瘮濡傜┖鎸囬拡锛夈��

搴斿鏈鏌ュ紓甯稿氨鏄吇鎴愯壇濂界殑妫�鏌ヤ範鎯��

宸叉鏌ュ紓甯告槸涓嶅彲閬垮厤鐨勶紝瀵逛簬宸叉鏌ュ紓甯稿繀椤诲疄鐜板畾涔夊ソ搴斿鐨勬柟娉曘��

宸叉鏌ュ紓甯歌偗瀹氳法瓒婂嚭浜嗚櫄鎷熸満鐨勮寖鍥淬�傦紙姣斿鈥�鏈壘鍒版枃浠�鈥�锛�

濡備綍澶勭悊宸叉鏌ュ紓甯革紙瀵逛簬鎵�鏈夌殑宸叉鏌ュ紓甯搁兘瑕佽繘琛屽鐞嗭級锛�

棣栧厛浜嗚В寮傚父褰㈡垚鐨勬満鍒讹細

褰撲竴涓柟娉曚腑鏈変竴鏉¤鍙ュ嚭鐜颁簡寮傚父锛屽畠灏变細throw锛堟姏鍑猴級涓�涓緥澶栧璞★紝鐒跺悗鍚庨潰鐨勮鍙ヤ笉浼氭墽琛岃繑鍥炰笂涓�绾ф柟娉曪紝鍏朵笂涓�绾ф柟娉曟帴鍙楀埌浜嗕緥澶栧璞′箣鍚庯紝鏈夊彲鑳藉杩欎釜寮傚父杩涜澶勭悊锛屼篃鍙兘灏嗚繖涓紓甯歌浆鍒板畠鐨勪笂涓�绾с��

瀵逛簬鎺ユ敹鍒扮殑宸叉鏌ュ紓甯告湁涓ょ澶勭悊鏂瑰紡锛�throws鍜�try鏂规硶銆�

娉ㄦ剰锛氬嚭閿欑殑鏂规硶鏈夊彲鑳芥槸JDK锛屼篃鍙兘鏄▼搴忓憳鍐欑殑绋嬪簭锛屾棤璁鸿皝鍐欑殑锛屾姏鍑轰竴瀹氱敤throw銆�

渚嬶細public void print() throws Exception.

瀵逛簬鏂规硶a锛屽鏋滃畠瀹氫箟浜�throws Exception銆傞偅涔堝綋瀹冭皟鐢ㄧ殑鏂规硶b杩斿洖寮傚父瀵硅薄鏃讹紝鏂规硶a骞朵笉澶勭悊锛岃�屽皢杩欎釜寮傚父瀵硅薄鍚戜笂涓�绾ц繑鍥烇紝濡傛灉鎵�鏈夌殑鏂规硶鍧囦笉杩涜澶勭悊锛岃繑鍥炲埌涓绘柟娉曪紝绋嬪簭涓銆傦紙瑕侀伩鍏嶆墍鏈夌殑鏂规硶閮借繑鍥炵殑浣跨敤鏂规硶锛屽洜涓鸿繖鏍峰嚭鐜颁竴涓緢灏忕殑寮傚父灏变細浠ょ▼搴忎腑姝級銆�

濡傛灉鍦ㄦ柟娉曠殑绋嬪簭涓湁涓�琛�throw new Exception()锛岃繑鍥為敊璇紝閭d箞鍏跺悗鐨勭▼搴忎笉鎵ц銆傚洜涓洪敊璇繑鍥炲悗锛屽悗闈㈢殑绋嬪簭鑲畾娌℃湁鏈轰細鎵ц锛岄偅涔�JAVA璁や负浠ュ悗鐨勭▼搴忔病鏈夊瓨鍦ㄧ殑蹇呰銆�

瀵逛簬try鈥︹�atch鏍煎紡锛�

try{鍙兘鍑虹幇閿欒鐨勪唬鐮佸潡}catch(exception e){杩涜澶勭悊鐨勪唬鐮�}锛�

瀵硅薄鍙橀噺鐨勫0鏄�

鐢ㄨ繖绉嶆柟娉曪紝濡傛灉浠g爜姝g‘锛岄偅涔堢▼搴忎笉缁忚繃catch璇彞鐩存帴鍚戜笅杩愯锛�

濡傛灉浠g爜涓嶆纭紝鍒欏皢杩斿洖鐨勫紓甯稿璞″拰e杩涜鍖归厤锛屽鏋滃尮閰嶆垚鍔燂紝鍒欏鐞嗗叾鍚庨潰鐨勫紓甯稿鐞嗕唬鐮併�傦紙濡傛灉鐢�exception鏉ュ0鏄�e鐨勮瘽锛屽洜涓�exception涓烘墍鏈�exception瀵硅薄鐨勭埗绫伙紝鎵�鏈夎偗瀹氬尮閰嶆垚鍔燂級銆傚鐞嗗畬浠g爜鍚庤繖涓緥澶栧氨瀹屽叏澶勭悊瀹屾瘯锛岀▼搴忎細鎺ョ潃浠庡嚭鐜板紓甯哥殑鍦版柟鍚戜笅鎵ц锛堟槸浠庡嚭鐜板紓甯哥殑鍦版柟杩樻槸鍦�catch鍚庨潰鍛紵鍒╃敤绋嬪簭杩涜楠岃瘉锛夈�傛渶鍚庣▼搴忔甯搁��鍑恒��

Try涓鏋滃彂鐜伴敊璇紝鍗宠烦鍑�try鍘诲尮閰�catch锛岄偅涔�try鍚庨潰鐨勮鍙ュ氨涓嶄細琚墽琛屻��

涓�涓�try鍙互璺熻繘澶氫釜catch璇彞锛岀敤浜庡鐞嗕笉鍚屾儏鍐点�傚綋涓�涓�try鍙兘鍖归厤涓�涓�catch銆�

鎴戜滑鍙互鍐欏涓�catch璇彞锛屼絾鏄笉鑳藉皢鐖剁被鍨嬬殑exception鐨勪綅缃啓鍦ㄥ瓙绫诲瀷鐨�excepiton涔嬪墠锛屽洜涓鸿繖鏍风埗绫诲瀷鑲畾鍏堜簬瀛愮被鍨嬭鍖归厤锛屾墍鏈夊瓙绫诲瀷灏辨垚涓哄簾璇濄��JAVA缂栬瘧鍑洪敊銆�

鍦�try锛�catch鍚庤繕鍙互鍐嶈窡涓�瀛愬彞finally銆傚叾涓殑浠g爜璇彞鏃犺濡備綍閮戒細琚墽琛岋紙鍥犱负finally瀛愬彞鐨勮繖涓壒鎬э紝鎵�浠ヤ竴鑸皢閲婃斁璧勬簮锛屽叧闂繛鎺ョ殑璇彞鍐欏湪閲岄潰锛夈��

濡傛灉鍦ㄧ▼搴忎腑涔﹀啓浜嗘鏌ワ紙鎶涘嚭锛�exception浣嗘槸娌℃湁瀵硅繖涓彲鑳藉嚭鐜扮殑妫�鏌ョ粨鏋滆繘琛屽鐞嗭紝閭d箞绋嬪簭灏变細鎶ラ敊銆�

鑰屽鏋滃彧鏈夊鐞嗘儏鍐碉紙try锛夎�屾病鏈夌浉搴旂殑catch瀛愬彞锛屽垯缂栬瘧杩樻槸閫氫笉杩囥��

濡備綍鐭ラ亾鍦ㄧ紪鍐欑殑绋嬪簭涓細鍑虹幇渚嬪鍛�

璋冪敤鏂规硶锛屾煡鐪�API涓煡鐪嬫柟娉曚腑鏄惁鏈夊凡妫�鏌ラ敊璇��

鍦ㄧ紪璇戠殑杩囩▼涓湅鎻愮ず淇℃伅锛岀劧鍚庡姞涓婄浉搴旂殑澶勭悊銆�

Exception鏈変竴涓�message灞炴�с�傚湪浣跨敤catch鐨勬椂鍊欏彲浠ヨ皟鐢細

Catch(IOException e){System.out.println(e.message())};

Catch(IOException e){e.printStackTrace()};

涓婇潰杩欐潯璇彞鍥炲憡璇夋垜浠嚭閿欑被鍨嬫墍鍘嗙粡鐨勮繃绋嬶紝鍦ㄨ皟璇曠殑涓潪甯告湁鐢ㄣ��

寮�鍙戜腑鐨勪袱涓亾鐞嗭細

鈶犲浣曟帶鍒�try鐨勮寖鍥达細鏍规嵁鎿嶄綔鐨勮繛鍔ㄦ�у拰鐩稿叧鎬э紝濡傛灉鍓嶉潰鐨勭▼搴忎唬鐮佸潡鎶涘嚭鐨勯敊璇奖鍝嶄簡鍚庨潰绋嬪簭浠g爜鐨勮繍琛岋紝閭d箞杩欎釜鎴戜滑灏辫杩欎袱涓▼搴忎唬鐮佸瓨鍦ㄥ叧鑱旓紝搴旇鏀惧湪鍚屼竴涓�try涓��

瀵瑰凡缁忔煡鍑烘潵鐨勪緥澶栵紝鏈�throw(绉瀬)鍜�try catch锛堟秷鏋侊級涓ょ澶勭悊鏂规硶銆�

瀵逛簬try catch鏀惧湪鑳藉寰堝ソ鍦板鐞嗕緥澶栫殑浣嶇疆锛堝嵆鏀惧湪鍏峰瀵逛緥澶栬繘琛屽鐞嗙殑鑳藉姏鐨勪綅缃級銆傚鏋滄病鏈夊鐞嗚兘鍔涘氨缁х画涓婃姏銆�

褰撴垜浠嚜宸卞畾涔変竴涓緥澶栫被鐨勬椂鍊欏繀椤讳娇鍏剁户鎵�excepiton鎴栬��RuntimeException銆�

Throw鏄竴涓鍙ワ紝鐢ㄦ潵鍋氭姏鍑轰緥澶栫殑鍔熻兘銆�

鑰�throws鏄〃绀哄鏋滀笅绾ф柟娉曚腑濡傛灉鏈変緥澶栨姏鍑猴紝閭d箞鏈柟娉曚笉鍋氬鐞嗭紝缁х画鍚戜笂鎶涘嚭銆�

Throws鍚庤窡鐨勬槸渚嬪绫诲瀷銆�

鏂█鏄竴绉嶈皟璇曞伐鍏凤紙assert锛�

鍏跺悗璺熺殑鏄竷灏旂被鍨嬬殑琛ㄨ揪寮忥紝濡傛灉琛ㄨ揪寮忕粨鏋滀负鐪熶笉褰卞搷绋嬪簭杩愯銆傚鏋滀负鍋囩郴缁熷嚭鐜颁綆绾ч敊璇紝鍦ㄥ睆骞曚笂鍑虹幇assert淇℃伅銆�

Assert鍙槸鐢ㄤ簬璋冭瘯銆傚湪浜у搧缂栬瘧瀹屾垚鍚庝笂绾�assert浠g爜灏辫鍒犻櫎浜嗐��

鏂规硶鐨勮鐩栦腑锛屽鏋滃瓙绫荤殑鏂规硶鎶涘嚭鐨勪緥澶栨槸鐖剁被鏂规硶鎶涘嚭鐨勪緥澶栫殑鐖剁被鍨嬶紝閭d箞缂栬瘧灏变細鍑洪敊锛氬瓙绫绘棤娉曡鐩栫埗绫汇��

缁撹锛氬瓙绫绘柟娉曚笉鍙瘮鐖剁被鏂规硶鎶涘嚭鏇村鐨勪緥澶栥�傚瓙绫绘姏鍑虹殑渚嬪鎴栬�呬笌鐖剁被鎶涘嚭鐨勪緥澶栦竴鑷达紝鎴栬�呮槸鐖剁被鎶涘嚭渚嬪鐨勫瓙绫诲瀷銆傛垨鑰呭瓙绫诲瀷涓嶆姏鍑轰緥澶栥��

濡傛灉鐖剁被鍨嬫棤throws鏃讹紝瀛愮被鍨嬩篃涓嶅厑璁稿嚭鐜�throws銆傛鏃跺彧鑳戒娇鐢�try catch銆�

缁冧範锛氬啓涓�涓柟娉曪細int add(int a,int b)

{

return a+b锛�

}

褰�a+b=100;鎶涘嚭100涓哄紓甯稿鐞嗐��

12.02

闆嗗悎锛堜粠鏈儴鍒嗗紑濮嬫秹鍙�API锛�

闆嗗悎鏄寚涓�涓璞″绾充簡澶氫釜瀵硅薄锛岃繖涓泦鍚堝璞′富瑕佺敤鏉ョ鐞嗙淮鎶や竴绯诲垪鐩镐技鐨勫璞°��

鏁扮粍灏辨槸涓�绉嶅璞°��锛堢粌涔狅細濡備綍缂栧啓涓�涓暟缁勭▼搴忥紝骞惰繘琛岄亶鍘嗐�傦級

java.util.*瀹氫箟浜嗕竴绯诲垪鐨勬帴鍙e拰绫伙紝鍛婅瘔鎴戜滑鐢ㄤ粈涔堢被NEW鍑轰竴涓璞★紝鍙互杩涜瓒呰秺鏁扮粍鐨勬搷浣溿��

锛堟敞锛�JAVA1.5瀵�JAVA1.4鐨勬渶澶ф敼杩涘氨鏄鍔犱簡瀵硅寖鍨嬬殑鏀寔锛�

闆嗗悎妗嗘灦鎺ュ彛鐨勫垎绫伙細锛堝垎collection鎺ュ彛鍜�map鎺ュ彛锛�

Collection鎺ュ彛Map鎺ュ彛

List鎺ュ彛Set鎺ュ彛SortedMap鎺ュ彛

SortedSet鎺ュ彛

JAVA涓墍鏈変笌闆嗗悎鏈夊叧鐨勫疄鐜扮被閮芥槸杩欏叚涓帴鍙g殑瀹炵幇绫汇��

Collection鎺ュ彛锛氶泦鍚堜腑姣忎竴涓厓绱犱负涓�涓璞★紝杩欎釜鎺ュ彛灏嗚繖浜涘璞$粍缁囧湪涓�璧凤紝褰㈡垚涓�缁寸粨鏋勩��

List鎺ュ彛浠h〃鎸夌収鍏冪礌涓�瀹氱殑鐩稿叧椤哄簭鏉ョ粍缁囷紙鍦ㄨ繖涓簭鍒椾腑椤哄簭鏄富瑕佺殑锛夛紝List鎺ュ彛涓暟鎹彲閲嶅銆�

Set鎺ュ彛鏄暟瀛︿腑闆嗗悎鐨勬蹇碉細鍏跺厓绱犳棤搴忥紝涓斾笉鍙噸澶嶃�傦紙姝eソ涓�List瀵瑰簲锛�

SortedSet浼氭寜鐓ф暟瀛楀皢鍏冪礌鎺掑垪锛屼负鈥�鍙帓搴忛泦鍚�鈥�銆�

Map鎺ュ彛涓瘡涓�涓厓绱犱笉鏄竴涓璞★紝鑰屾槸涓�涓敭瀵硅薄鍜屽�煎璞$粍鎴愮殑閿�煎锛�Key-Value锛夈��

Key-Value鏄敤涓�涓笉鍙噸澶嶇殑key闆嗗悎瀵瑰簲鍙噸澶嶇殑value闆嗗悎銆傦紙鍏稿瀷鐨勪緥瀛愭槸瀛楀吀锛氶�氳繃椤电爜鐨�key鍊兼壘瀛楃殑value鍊硷級銆�

渚嬪瓙锛�

key1鈥攙alue1;

key2鈥攙alue2;

key3鈥攙alue3.

SortedMap锛氬鏋滀竴涓�Map鍙互鏍规嵁key鍊兼帓搴忥紝鍒欑О鍏朵负SortedMap銆傦紙濡傚瓧鍏革級

!!娉ㄦ剰鏁扮粍鍜岄泦鍚堢殑鍖哄埆锛氭暟缁勪腑鍙兘瀛樼畝鍗曟暟鎹被鍨嬨��Collection鎺ュ彛鍜�Map鎺ュ彛鍙兘瀛樺璞°��

浠ヤ笅浠嬬粛鎺ュ彛锛�

List鎺ュ彛锛氾紙浠嬬粛鍏朵笅鐨勪袱涓疄鐜扮被锛�ArrayList鍜�LinkedList锛�

ArrayList鍜屾暟缁勯潪甯哥被浼硷紝鍏跺簳灞傗憼涔熺敤鏁扮粍缁勭粐鏁版嵁锛�ArrayList鏄姩鎬佸彲鍙樻暟缁勩��

搴曞眰锛氭寚瀛樺偍鏍煎紡銆傝鏄�ArrayList瀵硅薄閮芥槸瀛樺湪浜庢暟缁勪腑銆�

娉細鏁扮粍鍜岄泦鍚堥兘鏄粠涓嬫爣0寮�濮嬨��

ArrayList鏈変竴涓�add(Object o)鏂规硶鐢ㄤ簬鎻掑叆鏁扮粍銆�

ArrayList鐨勪娇鐢細锛堝畬鎴愯繖涓▼搴忥級

鍏�importjava.util.*锛�

鐢�ArrayList鍦ㄤ竴涓暟缁勪腑娣诲姞鏁版嵁锛屽苟閬嶅巻銆�

ArrayList涓暟缁勭殑椤哄簭涓庢坊鍔犻『搴忎竴鑷淬��

鍙湁List鍙敤get鍜�size銆傝��Set鍒欎笉鍙敤锛堝洜鍏舵棤搴忥級銆�

Collection鎺ュ彛閮芥槸閫氳繃Iterator()锛堝嵆杩唬鍣級鏉ュSet鍜�List閬嶅巻銆�

閫氳繃璇彞锛�Iterator it=c.iterator();寰楀埌涓�涓凯浠e櫒锛屽皢闆嗗悎涓墍鏈夊厓绱犻『搴忔帓鍒椼�傜劧鍚庡彲浠ラ�氳繃interator鏂规硶杩涜閬嶅巻锛岃凯浠e櫒鏈変竴涓父鏍囷紙鎸囬拡锛夋寚鍚戦浣嶇疆銆�

Interator鏈�hasNext()锛岀敤浜庡垽鏂厓绱犲彸杈规槸鍚﹁繕鏈夋暟鎹紝杩斿洖True璇存槑鏈夈�傜劧鍚庡氨鍙互璋冪敤next鍔ㄤ綔銆�Next()浼氬皢娓告爣绉诲埌涓嬩竴涓厓绱狅紝骞舵妸瀹冩墍璺ㄨ繃鐨勫厓绱犺繑鍥炪�傦紙杩欐牱灏卞彲浠ュ鍏冪礌杩涜閬嶅巻锛�

缁冧範锛氬啓涓�涓▼搴忥紝杈撳叆瀵硅薄淇℃伅锛屾瘮杈冨熀鏈俊鎭��

闆嗗悎涓瘡涓�涓厓绱犻兘鏈夊璞★紝濡傛湁瀛楃涓茶缁忚繃寮哄埗绫诲瀷杞崲銆�

Collections鏄伐鍏风被锛屾墍鏈夋柟娉曞潎涓烘湁鐢ㄦ柟娉曪紝涓旀柟娉曚负static銆�

鏈�Sort鏂规硶鐢ㄤ簬缁�List鎺掑簭銆�

Collections.Sort()鍒嗕负涓ら儴鍒嗭紝涓�閮ㄥ垎涓烘帓搴忚鍒欙紱涓�閮ㄥ垎涓烘帓搴忕畻娉曘��

瑙勫垯鐢ㄦ潵鍒ゆ柇瀵硅薄锛涚畻娉曟槸鑰冭檻濡備綍鎺掑簭銆�

瀵逛簬鑷畾涔夊璞★紝Sort涓嶇煡閬撹鍒欙紝鎵�浠ユ棤娉曟瘮杈冦�傝繖绉嶆儏鍐典笅涓�瀹氳瀹氫箟鎺掑簭瑙勫垯銆傛柟寮忔湁涓ょ锛�

java.lang涓嬮潰鏈変竴涓帴鍙o細Comparable锛堝彲姣旇緝鐨勶級

鍙互璁╄嚜瀹氫箟瀵硅薄瀹炵幇涓�涓帴鍙o紝杩欎釜鎺ュ彛鍙湁涓�涓柟娉�comparableTo(Object o)

鍏惰鍒欐槸褰撳墠瀵硅薄涓�o瀵硅薄杩涜姣旇緝锛屽叾杩斿洖涓�涓�int鍊硷紝绯荤粺鏍规嵁姝ゅ�兼潵杩涜鎺掑簭銆�

濡�褰撳墠瀵硅薄>o瀵硅薄锛屽垯杩斿洖鍊�>0锛涳紙鍙皢杩斿洖鍊煎畾涔変负1锛�

濡�褰撳墠瀵硅薄=o瀵硅薄锛屽垯杩斿洖鍊�=0锛�

濡�褰撳墠瀵硅薄瀵硅薄锛屽垯杩斿洖鍊笺��0銆傦紙鍙皢杩斿洖鍊煎畾涔変负-1锛�

鐪�TestArraylist鐨�java浠g爜銆�

鎴戜滑閫氳繃杩斿洖鍊�1鍜�-1浣嶇疆鐨勮皟鎹㈡潵瀹炵幇鍗囧簭鍜岄檷搴忔帓鍒楃殑杞崲銆�

java.util涓嬫湁涓�涓�Comparator(姣旇緝鍣�)

瀹冩嫢鏈�compare()锛岀敤鏉ユ瘮杈冧袱涓柟娉曘��

瑕佺敓鎴愭瘮杈冨櫒锛屽垯鐢�Sort涓�Sort锛�List,List(Compate)锛�

绗簩绉嶆柟娉曟洿鐏垫椿锛屼笖鍦ㄨ繍琛岀殑鏃跺�欎笉鐢ㄧ紪璇戙��

娉ㄦ剰锛氳鎯冲疄鐜�comparTo()灏卞繀椤诲湪涓绘柟娉曚腑鍐欎笂implement comparable.

缁冧範锛氱敓鎴愪竴涓�EMPLOYEE绫伙紝鐒跺悗灏嗕竴绯诲垪瀵硅薄鏀惧叆鍒�ArrayList銆傜敤Iterator閬嶅巻锛屾帓搴忎箣鍚庯紝鍐嶈繘琛岄亶鍘嗐��

闆嗗悎鐨勬渶澶х己鐐规槸鏃犳硶杩涜绫诲瀷鍒ゅ畾锛堣繖涓己鐐瑰湪JAVA1.5涓凡缁忚В鍐筹級锛岃繖鏍峰氨鍙兘鍑虹幇鍥犱负绫诲瀷涓嶅悓鑰屽嚭鐜扮被鍨嬮敊璇��

瑙e喅鐨勬柟娉曟槸娣诲姞绫诲瀷鐨勫垽鏂��

LinkedList鎺ュ彛锛堝湪浠g爜鐨勪娇鐢ㄨ繃绋嬩腑鍜�ArrayList娌℃湁浠�涔堝尯鍒級

ArrayList搴曞眰鏄�object鏁扮粍锛屾墍浠�ArrayList鍏锋湁鏁扮粍鐨勬煡璇㈤�熷害蹇殑浼樼偣浠ュ強澧炲垹閫熷害鎱㈢殑缂虹偣銆�

鑰屽湪LinkedList鐨勫簳灞傛槸涓�绉嶅弻鍚戝惊鐜摼琛ㄣ�傚湪姝ら摼琛ㄤ笂姣忎竴涓暟鎹妭鐐归兘鐢变笁閮ㄥ垎缁勬垚锛氬墠鎸囬拡锛堟寚鍚戝墠闈㈢殑鑺傜偣鐨勪綅缃級锛屾暟鎹紝鍚庢寚閽堬紙鎸囧悜鍚庨潰鐨勮妭鐐圭殑浣嶇疆锛夈�傛渶鍚庝竴涓妭鐐圭殑鍚庢寚閽堟寚鍚戠涓�涓妭鐐圭殑鍓嶆寚閽堬紝褰㈡垚涓�涓惊鐜��

鍙屽悜寰幆閾捐〃鐨勬煡璇㈡晥鐜囦綆浣嗘槸澧炲垹鏁堢巼楂樸�傛墍浠�LinkedList鍏锋湁鏌ヨ鏁堢巼浣庝絾澧炲垹鏁堢巼楂樼殑鐗圭偣銆�

ArrayList鍜�LinkedList鍦ㄧ敤娉曚笂娌℃湁鍖哄埆锛屼絾鏄湪鍔熻兘涓婅繕鏄湁鍖哄埆鐨勩��

LinkedList缁忓父鐢ㄥ湪澧炲垹鎿嶄綔杈冨鑰屾煡璇㈡搷浣滃緢灏戠殑鎯呭喌涓嬶細闃熷垪鍜屽爢鏍堛��

闃熷垪锛氬厛杩涘厛鍑虹殑鏁版嵁缁撴瀯銆�

鍫嗘爤锛氬悗杩涘厛鍑虹殑鏁版嵁缁撴瀯銆�

娉ㄦ剰锛氫娇鐢ㄥ爢鏍堢殑鏃跺�欎竴瀹氫笉鑳芥彁渚涙柟娉曡涓嶆槸鏈�鍚庝竴涓厓绱犵殑鍏冪礌鑾峰緱鍑烘爤鐨勬満浼氥��

LinkedList鎻愪緵浠ヤ笅鏂规硶锛氾紙ArrayList鏃犳绫绘柟娉曪級

addFirst();

removeFirst();

addLast();

removeLast();

鍦ㄥ爢鏍堜腑锛�push涓哄叆鏍堟搷浣滐紝pop涓哄嚭鏍堟搷浣溿��

Push鐢�addFirst()锛�pop鐢�removeFirst()锛屽疄鐜板悗杩涘厛鍑恒��

鐢�isEmpty()--鍏剁埗绫荤殑鏂规硶锛屾潵鍒ゆ柇鏍堟槸鍚︿负绌恒��

鍦ㄩ槦鍒椾腑锛�put涓哄叆闃熷垪鎿嶄綔锛�get涓哄嚭闃熷垪鎿嶄綔銆�

Put鐢�addFirst()锛�get鐢�removeLast()瀹炵幇闃熷垪銆�

List鎺ュ彛鐨勫疄鐜扮被锛�Vector锛夛紙涓�ArrayList鐩镐技锛屽尯鍒槸Vector鏄噸閲忕骇鐨勭粍浠讹紝浣跨敤浣挎秷鑰楃殑璧勬簮姣旇緝澶氥�傦級

缁撹锛氬湪鑰冭檻骞跺彂鐨勬儏鍐典笅鐢�Vector锛堜繚璇佺嚎绋嬬殑瀹夊叏锛夈��

鍦ㄤ笉鑰冭檻骞跺彂鐨勬儏鍐典笅鐢�ArrayList锛堜笉鑳戒繚璇佺嚎绋嬬殑瀹夊叏锛夈��

闈㈣瘯缁忛獙锛堢煡璇嗙偣锛夛細

java.util.stack锛�stack鍗充负鍫嗘爤锛夌殑鐖剁被涓�Vector銆傚彲鏄�stack鐨勭埗绫绘槸鏈�涓嶅簲璇ヤ负Vector鐨勩�傚洜涓�Vector鐨勫簳灞傛槸鏁扮粍锛屼笖Vector鏈�get鏂规硶锛堟剰鍛崇潃瀹冨彲鑳借闂埌骞朵笉灞炰簬鏈�鍚庝竴涓綅缃厓绱犵殑鍏朵粬鍏冪礌锛屽緢涓嶅畨鍏級銆�

瀵逛簬鍫嗘爤鍜岄槦鍒楀彧鑳界敤push绫诲拰get绫汇��

Stack绫讳互鍚庝笉瑕佽交鏄撲娇鐢ㄣ��

锛侊紒锛佸疄鐜板爢鏍堜竴瀹氳鐢�LinkedList銆�

锛堝湪JAVA1.5涓紝collection鏈�queue鏉ュ疄鐜伴槦鍒椼�傦級

Set-HashSet瀹炵幇绫伙細

閬嶅巻涓�涓�Set鐨勬柟娉曞彧鏈変竴涓細杩唬鍣紙interator锛夈��

HashSet涓厓绱犳槸鏃犲簭鐨勶紙杩欎釜鏃犲簭鎸囩殑鏄暟鎹殑娣诲姞椤哄簭鍜屽悗鏉ョ殑鎺掑垪椤哄簭涓嶅悓锛夛紝鑰屼笖鍏冪礌涓嶅彲閲嶅銆�

鍦�Object涓櫎浜嗘湁final()锛�toString()锛�equals()锛岃繕鏈�hashCode()銆�

HashSet搴曞眰鐢ㄧ殑涔熸槸鏁扮粍銆�

褰撳悜鏁扮粍涓埄鐢�add(Object o)娣诲姞瀵硅薄鐨勬椂鍊欙紝绯荤粺鍏堟壘瀵硅薄鐨�hashCode锛�

int hc=o.hashCode();杩斿洖鐨�hashCode涓烘暣鏁板�笺��

Int I=hc%n;锛�n涓烘暟缁勭殑闀垮害锛夛紝鍙栧緱浣欐暟鍚庯紝鍒╃敤浣欐暟鍚戞暟缁勪腑鐩稿簲鐨勪綅缃坊鍔犳暟鎹紝浠�n涓�6涓轰緥锛屽鏋�I=0鍒欐斁鍦ㄦ暟缁�a[0]浣嶇疆锛屽鏋�I=1,鍒欐斁鍦ㄦ暟缁�a[1]浣嶇疆銆傚鏋�equals()杩斿洖鐨勫�间负true锛屽垯璇存槑鏁版嵁閲嶅銆傚鏋�equals()杩斿洖鐨勫�间负false锛屽垯鍐嶆壘鍏朵粬鐨勪綅缃繘琛屾瘮杈冦�傝繖鏍风殑鏈哄埗灏卞鑷翠袱涓浉鍚岀殑瀵硅薄鏈夊彲鑳介噸澶嶅湴娣诲姞鍒版暟缁勪腑锛屽洜涓轰粬浠殑hashCode涓嶅悓銆�

濡傛灉鎴戜滑鑳藉浣夸袱涓浉鍚岀殑瀵硅薄鍏锋湁鐩稿悓hashcode锛屾墠鑳藉湪equals()杩斿洖涓虹湡銆�

鍦ㄥ疄渚嬩腑锛屽畾涔�student瀵硅薄鏃惰鐩栧畠鐨�hashcode銆�

鍥犱负String绫绘槸鑷姩瑕嗙洊鐨勶紝鎵�浠ュ綋姣旇緝String绫荤殑瀵硅薄鐨勬椂鍊欙紝灏变笉浼氬嚭鐜版湁涓や釜鐩稿悓鐨�string瀵硅薄鐨勬儏鍐点��

鐜板湪锛屽湪澶ч儴鍒嗙殑JDK涓紝閮藉凡缁忚姹傝鐩栦簡hashCode銆�

缁撹锛氬灏嗚嚜瀹氫箟绫荤敤hashSet鏉ユ坊鍔犲璞★紝涓�瀹氳瑕嗙洊hashcode()鍜�equals()锛岃鐩栫殑鍘熷垯鏄繚璇佸綋涓や釜瀵硅薄hashcode杩斿洖鐩稿悓鐨勬暣鏁帮紝鑰屼笖equals()杩斿洖鍊间负True銆�

濡傛灉鍋锋噿锛屾病鏈夎瀹�equals()锛屽氨浼氶�犳垚杩斿洖hashCode铏界劧缁撴灉鐩稿悓锛屼絾鍦ㄧ▼搴忔墽琛岀殑杩囩▼涓細澶氭鍦拌皟鐢�equals()锛屼粠鑰屽奖鍝嶇▼搴忔墽琛岀殑鏁堢巼銆�

鎴戜滑瑕佷繚璇佺浉鍚屽璞$殑杩斿洖鐨�hashCode涓�瀹氱浉鍚岋紝涔熻淇濊瘉涓嶇浉鍚岀殑瀵硅薄鐨�hashCode灏藉彲鑳戒笉鍚岋紙鍥犱负鏁扮粍鐨勮竟鐣屾�э紝hashCode杩樻槸鍙兘鐩稿悓鐨勶級銆備緥瀛愶細

public int hashCode(){

return name.hashcode()+age;

}

杩欎釜渚嬪瓙淇濊瘉浜嗙浉鍚屽鍚嶅拰骞撮緞鐨勮褰曡繑鍥炵殑hashCode鏄浉鍚岀殑銆�

浣跨敤hashSet鐨勪紭鐐癸細

hashSet鐨勫簳灞傛槸鏁扮粍锛屽叾鏌ヨ鏁堢巼闈炲父楂樸�傝�屼笖鍦ㄥ鍔犲拰鍒犻櫎鐨勬椂鍊欑敱浜庤繍鐢ㄧ殑hashCode鐨勬瘮杈冨紑纭畾娣诲姞鍏冪礌鐨勪綅缃紝鎵�浠ヤ笉瀛樺湪鍏冪礌鐨勫亸绉伙紝鎵�浠ユ晥鐜囦篃闈炲父楂樸�傚洜涓�hashSet鏌ヨ鍜屽垹闄ゅ拰澧炲姞鍏冪礌鐨勬晥鐜囬兘闈炲父楂樸��

浣嗘槸hashSet澧炲垹鐨勯珮鏁堢巼鏄�氳繃鑺辫垂澶ч噺鐨勭┖闂存崲鏉ョ殑锛氬洜涓虹┖闂磋秺澶э紝鍙栦綑鏁扮浉鍚岀殑鎯呭喌灏辫秺灏忋��HashSet杩欑绠楁硶浼氬缓绔嬭澶氭棤鐢ㄧ殑绌洪棿銆�

浣跨敤hashSet鎺ュ彛鏃惰娉ㄦ剰锛屽鏋滃彂鐢熷啿绐侊紝灏变細鍑虹幇閬嶅巻鏁翠釜鏁扮粍鐨勬儏鍐碉紝杩欐牱灏变娇寰楁晥鐜囬潪甯哥殑浣庛��

缁冧範锛�new涓�涓�hashset锛屾彃鍏�employee瀵硅薄锛屼笉鍏佽閲嶅锛屽苟涓旈亶鍘嗗嚭鏉ャ��

娣诲姞鐭ヨ瘑鐐癸細

闆嗗悎瀵硅薄瀛樻斁鐨勬槸涓�绯诲垪瀵硅薄鐨勫紩鐢ㄣ��

渚嬶細

Student S

Al.add(s);

s.setName(鈥渓ucy鈥�);

Student s2=(Student)(al.get(o1));

鍙煡s2涔熸槸s銆�

12.05

SortedSet鍙嚜鍔ㄤ负鍏冪礌鎺掑簭銆�

SortedSet鐨勫疄鐜扮被鏄�TreeSet:瀹冪殑浣滅敤鏄瓧涓烘坊鍔犲埌TreeSet涓殑鍏冪礌鎺掑簭銆�

缁冧範锛氳嚜瀹氫箟绫荤敤TreeSet鎺掑簭銆�

涓�HashSet涓嶅悓锛�TreeSet骞朵笉闇�瑕佸疄鐜�HashCode()鍜�equals()銆�

鍙瀹炵幇compareable鍜�compareTo()鎺ュ彲浠ュ疄鐜拌繃婊ゅ姛鑳姐��

锛堟敞锛�HashSet涓嶈皟鐢�CompareTo()锛夈��

濡傛灉瑕佹煡璇㈤泦鍚堜腑鐨勬暟鎹紝浣跨敤Set蹇呴』鍏ㄩ儴閬嶅巻锛屾墍浠ユ煡璇㈢殑鏁堢巼浣庛�備娇鐢�Map锛屽彲閫氳繃鏌ユ壘key寰楀埌value锛屾煡璇㈡晥鐜囬珮銆�

闆嗗悎涓父鐢ㄧ殑鏄細ArrayList锛�HashSet锛�HashMap銆傚叾涓�ArrayList鍜�HashMap浣跨敤鏈�涓哄箍娉涖��

浣跨敤HashMap锛�put()琛ㄧず鏀剧疆鍏冪礌锛�get()琛ㄧず鍙栧厓绱犮��

閬嶅巻Map锛屼娇鐢�keySet()鍙互杩斿洖set鍊硷紝鐢�keySet()寰楀埌key鍊硷紝浣跨敤杩唬鍣ㄩ亶鍘嗭紝鐒跺悗浣跨敤put()寰楀埌value鍊笺��

涓婇潰杩欎釜绠楁硶鐨勫叧閿鍙ワ細

Set s=m.keySet();

Interator it=new interator();

Object key=it.next();

Object value=m.get(key);

娉ㄦ剰锛�HashMap涓�HashCode鏈夊叧锛岀敤Sort瀵硅薄鎺掑簭銆�

濡傛灉鍦�HashMap涓湁key鍊奸噸澶嶏紝閭d箞鍚庨潰涓�鏉¤褰曠殑value瑕嗙洊鍓嶉潰涓�鏉¤褰曘��

Key鍊兼棦鐒跺彲浠ヤ綔涓哄璞★紝閭d箞涔熷彲浠ョ敤涓�涓嚜瀹氫箟鐨勭被銆傛瘮濡傦細

m.put(new sutdent(鈥淟iucy鈥�,30),鈥漛oss鈥�)

濡傛灉娌℃湁璇彞鏉ュ垽瀹�Student绫诲璞℃槸鍚︾浉鍚岋紝鍒欎細鍏ㄩ儴鎵撳嵃鍑烘潵銆�

褰撴垜浠敤鑷畾涔夌殑绫诲璞′綔涓�key鏃讹紝鎴戜滑蹇呴』鍦ㄧ▼搴忎腑瑕嗙洊HashCode()鍜�equals()銆�

娉細HashMap搴曞眰涔熸槸鐢ㄦ暟缁勶紝HashSet搴曞眰瀹為檯涓婁篃鏄�HashMap锛�HashSet绫讳腑鏈�HashMap灞炴�э紙鎴戜滑濡備綍鍦�API涓煡灞炴�э級銆�HashSet瀹為檯涓婁负(key.null)绫诲瀷鐨�HashMap銆傛湁key鍊艰�屾病鏈�value鍊笺��

姝e洜涓轰互涓婄殑鍘熷洜锛�TreeSet鍜�TreeMap鐨勫疄鐜颁篃鏈変簺绫讳技鐨勫叧绯汇��

娉ㄦ剰锛�TreeSet鍜�TreeMap闈炲父鐨勬秷鑰楁椂闂达紝鍥犳寰堝皯浣跨敤銆�

鎴戜滑搴旇鐔熸倝鍚勭瀹炵幇绫荤殑閫夋嫨鈥斺��闈炲父浣撶幇浣犵殑鍔熷簳銆�

HashSet VS TreeSet锛�HashSet闈炲父鐨勬秷鑰楃┖闂达紝TreeSet鍥犱负鏈夋帓搴忓姛鑳斤紝鍥犳璧勬簮娑堣�楅潪甯哥殑楂橈紝鎴戜滑搴旇灏介噺灏戜娇鐢紝鑰屼笖鏈�濂戒笉瑕侀噸澶嶄娇鐢ㄣ��

鍩轰簬浠ヤ笂鍘熷洜锛屾垜浠敖鍙兘鐨勮繍鐢�HashSet鑰屼笉鐢�TreeSet锛岄櫎闈炲繀椤绘帓搴忋��

鍚岀悊锛�HashMapVSTreeMap:涓�鑸娇鐢�HashMap锛屾帓搴忕殑鏃跺�欎娇鐢�TreeMap銆�

HashMap VS Hashtable锛堟敞鎰忓湪杩欓噷table鐨勭涓�涓瓧姣嶅皬鍐欙級涔嬮棿鐨勫尯鍒湁浜涚被浼间簬ArrayList鍜�Vector锛�Hashtable鏄噸閲忕骇鐨勭粍浠讹紝鍦ㄨ�冭檻骞跺彂鐨勬儏鍐碉紝瀵瑰畨鍏ㄦ�ц姹傛瘮杈冮珮鐨勬椂鍊欎娇鐢ㄣ��

Map鐨勮繍鐢ㄩ潪甯哥殑澶氥��

浣跨敤HashMap()锛屽鏋滀娇鐢ㄨ嚜瀹氫箟绫伙紝涓�瀹氳瑕嗙洊HashCode()鍜�equals()銆�

閲嶇偣鎺屾彙闆嗗悎鐨勫洓绉嶆搷浣滐細澧炲姞銆佸垹闄ゃ�侀亶鍘嗐�佹帓搴忋��

Module8鈥�12鍒╃敤涓ゅぉ鐨勬椂闂村畬鎴愩��

Module8锛氬浘褰㈢晫闈�

Module9锛氫簨浠舵ā鍨嬶紙鍦ㄦ湰閮ㄥ垎鏈�閲嶈锛�

Module10锛�AWT

Module11锛�Swing

Module12锛�Applet锛堣繖涓妧鏈熀鏈凡缁忚娣樻卑锛�

杞欢搴旂敤鐨勪笁涓彂灞曢樁娈碉細

鍗曟満搴旂敤

缃戠粶搴旂敤锛�C/S缁撴瀯锛�

BS缁撴瀯锛�B琛ㄧず娴忚鍣紝S琛ㄧずserver绔�傚嵆鍒╃敤娴忚鍣ㄤ綔涓哄鎴风锛屽洜姝ゅ浜庡浘褰㈢晫闈㈢殑瑕佹眰宸茬粡涓嶉珮锛岀幇鍦ㄧ殑鍙戝睍瓒嬪娍鏄笉浣跨敤瀹夎锛屽嵆涓嶇敤浠讳綍鐨勬湰鍦板簲鐢紝鍥惧舰寰堝揩灏变細琚湇鍔″櫒鏋勪欢寮�鍙戞墍鍙栦唬銆�

缁忛獙涔嬭皥锛�Swing鐨勫紑鍙戝伐浣滀細闈炲父鐨勭疮锛岃�屼笖杩欓」鎶�鏈鍦ㄨ蛋鍚戞病钀姐�傞伩鍏嶄粠浜嬫湁杩欑鐗瑰緛鐨勫伐浣溿��

AWT涔熷嵆灏嗚鍙栦唬銆�

Module8鈥擬odule11鎵�浣跨敤鐨勬妧鏈兘灏嗚JSF鎶�鏈墍鍙栦唬銆�

JSF鏄湇鍔″櫒绔殑Swing锛氱洰鍓嶆妧鏈凡缁忔垚鐔燂紝浣嗘槸寮�鍙戠幆澧冿紙宸ュ叿锛夎繕涓嶆垚鐔熴��

Module12鐨�Applet鎶�鏈篃灏嗚WebStart鎵�鍙栦唬銆�

Module9涓洪噸鐐癸紝鎵�璋撲簨浠舵ā鍨嬫槸鎸囪瀵熻�呰璁℃ā寮忕殑JAVA搴旂敤銆備簨浠舵ā鍨嬫槸閲嶇偣銆�

Module8锛氬浘褰㈢晫闈紙java.awt.*锛�

Awt锛氭娊璞$獥鍙e伐鍏风锛屽畠鐢变笁閮ㄥ垎缁勬垚锛�

鈶犵粍浠讹細鐣岄潰鍏冪礌锛�

鈶″鍣細瑁呰浇缁勪欢鐨勫鍣紙渚嬪绐椾綋锛夛紱

鈶㈠竷灞�绠$悊鍣細璐熻矗鍐冲畾瀹瑰櫒涓粍浠剁殑鎽嗘斁浣嶇疆銆�

鍥惧舰鐣岄潰鐨勫簲鐢ㄥ垎鍥涙锛�

閫夋嫨涓�涓鍣細

鈶�window:甯︽爣棰樼殑瀹瑰櫒锛堝Frame锛夛紱

鈶�Panel:闈㈡澘

閫氳繃add()鎯冲鍣ㄤ腑娣诲姞缁勪欢銆�

Java鐨勫浘褰㈢晫闈緷鐒舵槸璺ㄥ钩鍙扮殑銆備絾鏄湪璋冪敤浜嗕竴涓獥浣撲箣鍚庡彧鐢熸垚涓�涓獥浣擄紝娌℃湁浜嬩欢鐨勫鐞嗭紝鍏抽棴鎸夐挳骞朵笉宸ヤ綔銆傛鏃跺彧鑳戒娇鐢�CTRL+C缁堟绋嬪簭銆�

鈶¤缃竴涓竷灞�绠$悊鍣細鐢�setLayout()锛�

鈶㈠悜瀹瑰櫒涓坊鍔犵粍浠讹紱

娣诲姞缁勪欢鐨勪簨鍔″鐞嗐��P198

P204锛�Panel涔熸槸涓�绉嶅鍣細浣嗘槸涓嶅彲瑙佺殑銆傚湪璁剧疆瀹规槗鐨勬椂鍊欎笉瑕佸繕璁拌缃畠浠殑鍙鎬с��

Panel pan=new Panel;

Fp.setLayout(null);琛ㄧず涓嶈甯冨眬绠$悊鍣ㄣ��

浜旂甯冨眬绠$悊鍣細

P206锛�Flow Layout(娴佸紡甯冨眬)锛氭寜鐓х粍浠舵坊鍔犲埌瀹瑰櫒涓殑椤哄簭锛岄『搴忔帓鏀剧粍浠朵綅缃�傞粯璁や负姘村钩鎺掑垪锛屽鏋滆秺鐣岄偅涔堜細鍚戜笅鎺掑垪銆傛帓鍒楃殑浣嶇疆闅忕潃瀹瑰櫒澶у皬鐨勬敼鍙樿�屾敼鍙樸��

Panel榛樿鐨勫竷灞�绠$悊鍣ㄤ负Flow Layout銆�

Border Layout锛氫細灏嗗鍣ㄩ潪甯镐簲涓尯鍩燂細涓滆タ鍗楀寳涓��

璇彞锛�

Button b1=new Botton(鈥渘orth鈥�);//botton涓婄殑鏂囧瓧

f.add(b1,鈥漀orth鈥�);//琛ㄧずb1杩欎釜botton鏀惧湪north浣嶇疆

娉細涓�涓尯鍩熷彧鑳芥斁缃竴涓粍浠讹紝濡傛灉鎯冲湪涓�涓尯鍩熸斁缃涓粍浠跺氨闇�瑕佷娇鐢�Panel鏉ヨ杞姐��

Frame鍜�Dialog鐨勯粯璁ゅ竷灞�绠$悊鍣ㄦ槸Border Layout銆�

Grid Layout锛氬皢瀹瑰櫒鐢熸垚绛夐暱绛夊ぇ鐨勬潯鍒楁牸锛屾瘡涓潡涓斁缃竴涓粍浠躲��

f.setLayout GridLayout(5,2,10,10)//琛ㄧず鏉″垪鏍间负5琛�2绫伙紝鍚庨潰涓烘牸闂磋窛銆�

CardLayout:涓�涓鍣ㄥ彲浠ユ斁缃涓粍浠讹紝浣嗘瘡娆″彧鏈変竴涓粍浠跺彲瑙侊紙缁勪欢閲嶅彔锛夈��

浣跨敤first()锛�last()锛�next()鍙互鍐冲畾鍝釜缁勪欢鍙銆傚彲浠ョ敤浜庡皢涓�绯诲垪鐨勯潰鏉挎湁椤哄簭鍦板憟鐜扮粰鐢ㄦ埛銆�

閲嶇偣锛�GridBag Layout:鍦�Grid涓彲鎸囧畾涓�涓粍浠跺崰鎹琛屽鍒楋紝GridBag鐨勮缃潪甯哥殑鐑︾悙銆�

Module9:AWT:浜嬩欢妯″瀷

浜嬩欢妯″瀷鎸囩殑鏄璞′箣闂磋繘琛岄�氫俊鐨勮璁℃ā寮忋��

瀵硅薄1缁欏璞�2鍙戦�佷竴涓俊鎭浉褰撲簬瀵硅薄1寮曠敤瀵硅薄2鐨勬柟娉曘��

妯″瀷鍗虫槸涓�绉嶈璁℃ā寮忥紙绾﹀畾淇楁垚锛�

瀵硅薄瀵逛负涓夌锛�

鈶犱簨浠舵簮锛氬彂鍑轰簨浠惰�咃紱

鈶′簨浠跺璞★細鍙戝嚭鐨勪簨浠舵湰韬紱

浜嬩欢鐩戝惉鍣細鎻愪緵澶勭悊浜嬩欢鎸囧畾鐨勬柟娉曘��

Java AWT浜嬩欢妯″瀷涔熺О涓烘巿鏉冧簨浠舵ā鍨嬶紝鎸囦簨浠跺彲浠ュ拰鐩戝惉鍣ㄤ箣闂翠簨鍏堝缓绔嬩竴绉嶅叧绯伙細绾﹀畾閭d簺浜嬩欢濡備綍澶勭悊锛岀敱璋佸幓杩涜澶勭悊銆傝繖绉嶇害瀹氱О涓烘巿鏉冦��

涓�涓簨浠舵簮鍙互鎺堟潈澶氫釜鐩戝惉鑰咃紙鎺堟潈涔熺О涓虹洃鍚�呯殑娉ㄥ唽锛夛紱

澶氫釜浜嬩欢婧愪篃鍙互娉ㄥ唽澶氫釜浜嬩欢鐩戝惉鍣ㄣ��

鐩戝惉鑰呭浜庝簨浠舵簮鐨勫彂鍑虹殑浜嬩欢浣滃嚭鍝嶅簲銆�

鍦�java.util涓湁EventListener鎺ュ彛锛氭墍鏈変簨浠剁洃鍚�呴兘瑕佸疄鐜拌繖涓帴鍙c��

java.util涓湁EventObject绫伙細鎵�鏈夌殑浜嬩欢閮戒负鍏跺瓙绫汇��

浜嬩欢鑼冧緥鍦�\CoreJava\Girl.java鏂囦欢涓��(鏂囦欢宸插姞娉ㄩ噴)

娉ㄦ剰锛氭帴鍙e洜瀵逛笉鍚岀殑浜嬩欢鐩戝惉鍣ㄥ鍏跺鐞嗗彲鑳戒笉鍚岋紝鎵�浠ュ彧鑳藉缓绔嬬洃鍚殑鍔熻兘锛岃�屾棤娉曞疄鐜板鐞嗐��

涓嬮潰绋嬪簭寤虹珛鐩戝惉鍔熻兘锛�

//鐩戝惉鍣ㄦ帴鍙h瀹氫箟鐩戝惉鍣ㄦ墍鍏峰鐨勫姛鑳斤紝瀹氫箟鏂规硶

{

void WhatIdoWhenGirlHappy(EmotionEvent e);

void WhatIdoWhenGirlSad(EmotionEvent e);

}

娉ㄦ剰鏌ョ湅鍙傝�冧功锛氫簨浠剁殑璁剧疆妯″紡锛屽浣曞疄鐜版巿鏉冩ā鍨嬨��

浜嬩欢妯″紡鐨勫疄鐜版楠わ細

寮�鍙戜簨浠跺璞★紙浜嬩欢鍙戦�佽�咃級鈥斺��鎺ュ彛鈥斺��鎺ュ彛瀹炵幇绫�鈥斺��璁剧疆鐩戝惉瀵硅薄

涓�瀹氳鐞嗚В閫忓交Gril.java绋嬪簭銆�

閲嶇偣锛氬浼氬鐞嗗涓�涓簨浠舵簮鏈夊涓簨浠剁殑鐩戝惉鍣紙鍦ㄥ彂閫佹秷鎭椂鐩戝惉鍣ㄦ敹鍒版秷鎭殑鎺掑悕涓嶅垎鍏堝悗锛夈��

浜嬩欢鐩戝惉鐨勫搷搴旈『搴忔槸涓嶅垎鍏堝悗鐨勶紝涓嶆槸璋佸厛娉ㄥ唽璋佸氨鍏堝搷搴斻��

浜嬩欢鐩戝惉鐢变袱涓儴鍒嗙粍鎴愶紙鎺ュ彛鍜屾帴鍙g殑瀹炵幇绫伙級銆�

浜嬩欢婧�浜嬩欢瀵硅薄浜嬩欢鐩戝惉

grilEmotinEventEmotionListener(鎺ュ彛)銆�Boy(鎺ュ彛鐨勫疄鐜扮被)

榧犳爣浜嬩欢锛�MouseEvent锛屾帴鍙o細MouseListener銆�

P235 ActionEvent銆�

娉ㄦ剰鍦ㄥ啓绋嬪簭鐨勬椂鍊欙細import java.awt.*;浠ュ強import java.awt.event.*娉ㄦ剰涓よ�呯殑涓嶅悓銆�

鍦ㄧ敓鎴愪竴涓獥浣撶殑鏃跺�欙紝鐐瑰嚮绐椾綋鐨勫彸涓婅鍏抽棴鎸夐挳婵�鍙戠獥浣撲簨浠剁殑鏂规硶锛氱獥浣�Frame涓轰簨浠舵簮锛�WindowsListener鎺ュ彛璋冪敤Windowsclosing()銆�

涓轰簡閰嶅悎鍚庨潰鐨勫疄鐜帮紝鎴戜滑蹇呴』灏�WindowsListener鎵�鏈夌殑鏂规硶閮藉疄鐜帮紝闄や簡Windowsclosing鏂规硶锛屽叾浣欑殑鏂规硶鍧囦负绌哄疄鐜般��

锛堢粌涔狅細鍐欎竴涓甫button绐椾綋锛岀偣鍏抽棴鎸夐挳閫�鍑恒�傦級

涓婇潰绋嬪簭涓疄鐜颁簡璁稿涓嶅繀瑕佺殑瀹炵幇绫伙紝铏界劧鏄┖瀹炵幇銆�

涓轰簡閬垮厤涓婇潰閭d簺鏃犵敤鐨勫疄鐜帮紝鍙互鍒╃敤WindowEvent鐨勪竴涓�WindowEvent绫伙紝杩樻槸鍒╃敤windowsListener銆傝繕鏈�WindowAdapter绫伙紝瀹冨凡缁忓疄鐜颁簡WindowsListener銆傚畠缁欏嚭鐨勫叏閮ㄩ兘鏄┖瀹炵幇锛岄偅灏卞彲浠ュ彧鍐欐兂瑕佸疄鐜扮殑绫伙紝鍘昏鐩栧叾涓殑绫伙紝灏变笉鐢ㄥ啓绌哄疄鐜般��

娉ㄦ剰锛氱洃鍚繃澶氾紝浼氭姏tooManyListener渚嬪銆�

12.06

Module10

Canvas缁勪欢锛氱敾甯冿紝鍙互瀹炵幇鍔ㄧ敾鎿嶄綔銆�

TextArea锛氭枃鏈煙銆�

鍦ㄥ崟琛屾枃鏈煙涓洖杞︿細婵�鍙�ActionEvent銆�

鐢�CheckBoxGroup瀹炵幇鍗曢�夋鍔熻兘銆�

Java涓紝鍗曢�夋鍜屽閫夋閮芥槸浣跨敤CheckBox瀹炵幇銆�

鑿滃崟锛�new MenuBar()锛�MenuBar琛ㄧず鑿滃崟鏉°��

鑿滃崟涓殑姣忎竴椤逛负MenuItem锛屼竴鑸骇鑱旇彍鍗曚笉搴旇瓒呰繃涓夌骇銆�

缁冧範锛�

璁捐涓�涓绠楀櫒锛氭敞鎰忚缃竴涓�boolean鍊硷紙append锛夋潵鍒ゆ柇杈撳叆鏁板瓧鏄綅浜庣涓�涓暟鐨勫悗闈㈣繕鏄睘浜庤緭鍏ョ殑绗簩涓暟銆�

璁剧疆涓�涓彉閲忔潵瀛樻斁鈥�+鈥�锛岀偣瀹岃繍绠楃鍚庯紝灏�append璁剧疆涓�false銆�

String number1

Charoperator瀛樻斁杩愮畻绗︺��

Module11 Swing

AWT鏄�Java鏈�鏃╁嚭鐜扮殑鍥惧舰鐣岄潰锛屼絾寰堝揩灏辫Swing鎵�鍙栦唬銆�

Swing鎵嶆槸涓�绉嶇湡姝g殑鍥惧舰寮�鍙戙��

AWT鍦ㄤ笉鍚屽钩鍙版墍鍑虹幇鐨勭晫闈㈠彲鑳芥湁鎵�涓嶅悓锛氬洜涓烘瘡涓�OS閮芥湁鑷繁鐨�UI缁勪欢搴擄紝java璋冪敤涓嶅悓绯荤粺鐨�UI銆�

娉ㄦ剰AWT涓洪噸閲忕骇缁勪欢锛岀浉褰撴秷鑰楄祫婧愶紝涓斾笉鍚岀郴缁熺殑缁勪欢鍙兘涓嶅悓銆傚洜涓鸿繖涓棶棰樹娇寰�AWT寮�鍙戠殑杞欢闅句互浣滃埌璺ㄥ钩鍙般��

鏇翠负瑕佸懡鐨勬槸锛氫笉鍚�OS鐨勭粍浠跺簱閮藉瓨鍦�BUG銆傚繀椤诲绉嶅钩鍙拌繘琛屾祴璇曪紝骞朵笖AWT鐨勭粍浠跺簱骞朵笉涓板瘜銆�

涓鸿В鍐充互涓婇棶棰橈紝SUN鍜�IBM浠ュ強NETSCAPE鑱斿悎寮�鍙戝嚭JAVA鍩虹绫诲寘Swing锛氭敞鎰�JAVA鐨勫熀纭�绫讳互Swing涓烘牳蹇冦��

娉ㄦ剰寮曠敤锛�javax.swing.*;javax琛ㄧずJAVA鐨勬墿灞曘��

鎴戜滑鍦ㄥ涔�JDBC鐨勬椂鍊欎細杩囧害鍒�J2EE銆�

鍦�Swing鐨勭粍浠朵腑锛屽熀鏈笂閮芥槸鍦�AWT缁勪欢鐨勫悕绉板墠闈㈠姞鈥淛鈥�銆�

涓�鑸儏鍐典笅锛岄櫎浜�Choise绛夌粍浠�:

import javax.swing.*;濂借鍔犱笂锛�import java.awt.*浠ュ強import java.awt.event.*銆�

Swing涓�AWT鐨勬渶澶у尯鍒槸Swing涓�JAVA鑷韩鐨勭粍浠躲�傚凡缁忎笉鏄绛夊疄浣擄紝涓庡簳灞傜殑OS鏃犲叧銆�

锛�JBUILDER灏辨槸浣跨敤Swing鍐欑殑锛�

Swing涓�AWT鍦ㄤ簨浠舵ā鍨嬪鐞嗕笂鏄竴鑷寸殑銆�

Jframe瀹為檯涓婃槸涓�鍫嗙獥浣撶殑鍙犲姞銆�

Swing姣�AWT鏇村姞澶嶆潅涓旂伒娲汇��

鍦�JDK1.4涓紝缁�JFRAME娣诲姞Button涓嶅彲鐢�jf.add(b)銆傝�屾槸浣跨敤jf.getContentPane().add(b)銆�

content鏄厛鐢宠闈㈡澘銆備笉杩囧湪JDK1.5涓彲浠ヤ娇鐢�add.銆�

Jpanel鏀寔鍙岀紦鍐叉妧鏈��

鍦�Jbutton涓彲浠ユ坊鍔犲浘鏍囥��

JscrollPane鍙互绠$悊姣斿睆骞曡繕瑕佸ぇ鐨勭粍浠躲��

TextArea鍙湁瑁呭叆JscrollPane涓墠鑳藉疄鐜版粴鍔ㄦ潯銆�

JeditorPane鐢ㄤ簬鏄剧ず娴忚鍣ㄣ��

娉ㄦ剰锛�Tabbed Panel涓�Border鐨勬瘮杈冦��

杩涘害鏉★細ProgressBar銆�

JcomboBox锛氫笅鎷夎彍鍗曪細鍦�AWT涓悓绫荤粍浠舵槸choice銆�

JlistPanel锛氶�夋嫨鍒楄〃

BorderPanel锛氳缃竟妗�

JsplitPanel锛氬彲灏嗗鍣ㄥ垎涓轰袱涓儴鍒嗭紝鍏朵腑涓�涓儴鍒嗘湁Jtree銆�

TextBox锛氫篃鏄竴绉嶆柊鐨勫鍣紝鍙互璁剧疆缁勪欢鐨勯棿璺濄��

TextFileChoose锛氭枃浠堕�夋嫨鍣ㄣ��

ColorChoose锛氶鑹查�夋嫨鍣�

Module 12Applet

Applet涓�Panel鐨勫瓙绫�

Applet鏄�java鐨勮嚜鍔ㄦ墽琛屾柟寮忥紙杩欐槸瀹冪殑浼樺娍锛屼富瑕佺敤浜�HTML锛夈��

宸ヤ綔鍥涚璇硶锛�init()锛�start()锛�stop()锛�destory()銆�

Swing涓湁涓�涓�Japplet锛屽浣跨敤Swing缁勪欢銆�

Applet娑堜骸鐨勫師鍥狅細

鈶�java涓哄畨鍏ㄨ捣瑙佸Applet鏈夋墍闄愬埗锛�Applet涓嶅厑璁歌闂湰鍦版枃浠朵俊鎭�佹晱鎰熶俊鎭紝涓嶈兘鎵ц鏈湴鎸囦护锛堟瘮濡�FORMAT锛夛紝涓嶈兘璁块棶鍒濆師鏈嶅姟鍣ㄤ箣澶栫殑鍏朵粬鏈嶅姟鍣ㄣ��

IE涓嶆敮鎸佹柊鐗堟湰鐨�Applet銆�

Applet鐨勪紭鍔匡細

缃戠粶浼犺緭锛岃嚜鍔ㄤ笅杞姐��

Application鐨勪紭鍔匡細娌℃湁鎵ц闄愬埗銆�

WebStart锛氬彲鍦ㄧ綉缁滀紶杈擄紝骞朵笖鍦ㄦ湰鍦版棤闄愬埗銆傚洜姝ゅ墠鏅厜鏄庛��

缁冧範锛�

浣跨敤Swing瀹炵幇涓�涓晫闈紝鍒嗕负涓婁笅涓や釜閮ㄥ垎锛屽崡杈逛负JtextField缁勪欢锛屽彲缂栬緫锛屼笂闈负JtextArea缁勪欢锛屼笉鍙紪杈戯紝鍦�JtextField缁勪欢杈撳叆瀛楃锛屾寜鍥炶溅锛屽氨鍙互灏嗗唴瀹硅緭鍏ュ埌JtextArea缁勪欢銆�(AREA鍖哄煙鍙互婊氬姩)

12.07

澶氱嚎绋�

杩涚▼锛氫换鍔�

浠诲姟骞跺彂鎵ц鏄竴涓畯瑙傛蹇碉紝寰涓婃槸涓茶鐨勩��

杩涚▼鐨勮皟搴︽槸鏈�OS璐熻矗鐨勶紙鏈夌殑绯荤粺涓虹嫭鍗犲紡锛屾湁鐨勭郴缁熶负鍏变韩寮忥紝鏍规嵁閲嶈鎬э紝杩涚▼鏈変紭鍏堢骇锛夈��

鐢�OS灏嗘椂闂村垎涓鸿嫢骞蹭釜鏃堕棿鐗囥��

JAVA鍦ㄨ瑷�绾ф敮鎸佸绾跨▼銆�

鍒嗛厤鏃堕棿鐨勪粛鐒舵槸OS銆�

鍙傜湅P377

绾跨▼鐢变袱绉嶅疄鐜版柟寮忥細

绗竴绉嶆柟寮忥細

class MyThread extends Thread{

public void run(){

闇�瑕佽繘琛屾墽琛岀殑浠g爜锛屽寰幆銆�

}

}

public class TestThread{

main(){

Thread t1=new Mythread();

T1.start();

}

}

鍙湁绛夊埌鎵�鏈夌殑绾跨▼鍏ㄩ儴缁撴潫涔嬪悗锛岃繘绋嬫墠閫�鍑恒��

绗簩绉嶆柟寮忥細

Class MyThreadimplements Runnable{

Publicvoid run(){

Runnable target=new MyThread();

Thread t3=new Thread(target);

Thread.start();//鍚姩绾跨▼

}

}

P384:閫氳繃鎺ュ彛瀹炵幇缁ф壙

缁冧範锛氬啓涓や釜绾跨▼锛�

杈撳叆200涓�鈥�###鈥�鈶¤緭鍏�200涓�鈥�***鈥�

涓嬮潰涓虹嚎绋嬩腑鐨�7涓潪甯搁噸瑕佺殑鐘舵�侊細锛堟湁鐨勪功涓婁篃鍙湁璁や负鍓嶄簲绉嶇姸鎬侊細鑰屽皢鈥�閿佹睜鈥�鍜�鈥�绛夊緟闃熷垪鈥�閮界湅鎴愭槸鈥�闃诲鈥�鐘舵�佺殑鐗规畩鎯呭喌锛氳繖绉嶈璇嗕篃鏄纭殑锛屼絾鏄皢鈥�閿佹睜鈥�鍜�鈥�绛夊緟闃熷垪鈥�鍗曠嫭鍒嗙鍑烘潵鏈夊埄浜庡绋嬪簭鐨勭悊瑙o級

鈶�鈶�

鈶�鈶�

鈶�鈶�run()缁撴潫

Start()

OS鍒嗛厤CPU

CPU鏃堕棿鐗囩粨鏉�

yield()o.wait()

绛夊緟閿佹爣璁�

notify()

娉ㄦ剰锛氬浘涓爣璁颁緷娆′负

鈶犺緭鍏ュ畬姣曪紱鈶�wake up鈶�t1閫�鍑�

鈶村绛夊緟杈撳叆锛堣緭鍏ヨ澶囪繘琛屽鐞嗭紝鑰�CUP涓嶅鐞嗭級锛屽垯鏀惧叆闃诲锛岀洿鍒拌緭鍏ュ畬姣曘��

鈶电嚎绋嬩紤鐪�sleep锛堬級

鈶�t1.join()鎸囧仠姝�main()锛岀劧鍚庡湪鏌愭鏃堕棿鍐呭皢t1鍔犲叆杩愯闃熷垪锛岀洿鍒�t1閫�鍑猴紝main()鎵嶇粨鏉熴��

鐗瑰埆娉ㄦ剰锛氣憼鈶♀憿涓庘懘鈶碘懚鏄竴涓�瀵瑰簲鐨勩��

杩涚▼鐨勪紤鐪狅細Thread sleep(1000);//鎷彿涓互姣涓哄崟浣�

褰�main()杩愯瀹屾瘯锛屽嵆浣垮湪缁撴潫鏃舵椂闂寸墖杩樻病鏈夌敤瀹岋紝CPU涔熸斁寮冩鏃堕棿鐗囷紝缁х画杩愯鍏朵粬绋嬪簭銆�

Try{Thread.sleep(1000);}

Catch(Exception e){e.printStackTrace(e);}

T1.join()琛ㄧず杩愯绾跨▼鏀惧純鎵ц鏉冿紝杩涘叆闃诲鐘舵�併��

褰�t1缁撴潫鏃讹紝main()鍙互閲嶆柊杩涘叆杩愯鐘舵�併��

T1.join瀹為檯涓婃槸鎶婂苟鍙戠殑绾跨▼缂栫▼骞惰杩愯銆�

绾跨▼鐨勪紭鍏堢骇锛�1-10锛岃秺澶т紭鍏堢骇瓒婇珮锛屼紭鍏堢骇瓒婇珮琚�OS閫変腑鐨勫彲鑳芥�у氨瓒婂ぇ銆傦紙涓嶅缓璁娇鐢紝鍥犱负涓嶅悓鎿嶄綔绯荤粺鐨勪紭鍏堢骇骞朵笉鐩稿悓锛屼娇寰楃▼搴忎笉鍏峰璺ㄥ钩鍙版�э紝杩欑浼樺厛绾у彧鏄矖鐣ュ湴鍒掑垎锛夈��

娉細绋嬪簭鐨勮法骞冲彴鎬э細闄や簡鑳藉杩愯锛岃繕蹇呴』淇濊瘉杩愯鐨勭粨鏋溿��

涓�涓娇鐢�yield()灏遍┈涓婁氦鍑烘墽琛屾潈锛屽洖鍒板彲杩愯鐘舵�侊紝绛夊緟OS鐨勫啀娆¤皟鐢ㄣ��

涓嬪崍锛�

绋嬪簭鍛橀渶瑕佸叧娉ㄧ殑绾跨▼鍚屾鍜屼簰鏂ョ殑闂銆�

澶氱嚎绋嬬殑骞跺彂涓�鑸笉鏄▼搴忓憳鍐冲畾锛岃�屾槸鐢卞鍣ㄥ喅瀹氥��

澶氱嚎绋嬪嚭鐜版晠闅滅殑鍘熷洜锛�

涓や釜绾跨▼鍚屾椂璁块棶涓�涓暟鎹祫婧愶紙涓寸晫璧勬簮锛夛紝褰㈡垚鏁版嵁鍙戠敓涓嶄竴鑷村拰涓嶅畬鏁淬��

鏁版嵁鐨勪笉涓�鑷村線寰�鏄洜涓轰竴涓嚎绋嬩腑鐨勪袱涓叧鑱旂殑鎿嶄綔鍙畬鎴愪簡涓�姝ャ��

閬垮厤浠ヤ笂鐨勯棶棰樺彲閲囩敤瀵规暟鎹繘琛屽姞閿佺殑鏂规硶

姣忎釜瀵硅薄闄や簡灞炴�у拰鏂规硶锛岄兘鏈変竴涓�monitor锛堜簰鏂ラ攣鏍囪锛夛紝鐢ㄦ潵灏嗚繖涓璞′氦缁欎竴涓嚎绋嬶紝鍙湁鎷垮埌monitor鐨勭嚎绋嬫墠鑳藉璁块棶杩欎釜瀵硅薄銆�

Synchronized:杩欎釜淇グ璇嶅彲浠ョ敤鏉ヤ慨楗版柟娉曞拰浠g爜鍧�

Object obj;

Obj.setValue(123);

Synchronized鐢ㄦ潵淇グ鏂规硶锛岃〃绀哄綋鏌愪釜绾跨▼璋冪敤杩欎釜鏂规硶涔嬪悗锛屽叾浠栫殑浜嬩欢涓嶈兘鍐嶈皟鐢ㄨ繖涓柟娉曘�傚彧鏈夋嬁鍒�obj鏍囪鐨勭嚎绋嬫墠鑳藉鎵ц浠g爜鍧椼��

娉ㄦ剰锛�Synchronized涓�瀹氫娇鐢ㄥ湪涓�涓柟娉曚腑銆�

閿佹爣璁版槸瀵硅薄鐨勬蹇碉紝鍔犻攣鏄瀵硅薄鍔犻攣锛岀洰鐨勬槸鍦ㄧ嚎绋嬩箣闂磋繘琛屽崗璋冦��

褰撶敤Synchronized淇グ鏌愪釜鏂规硶鐨勬椂鍊欙紝琛ㄧず璇ユ柟娉曢兘瀵瑰綋鍓嶅璞″姞閿併��

缁欐柟娉曞姞Synchronized鍜岀敤Synchronized淇グ瀵硅薄鐨勬晥鏋滄槸涓�鑷寸殑銆�

涓�涓嚎绋嬪彲浠ユ嬁鍒板涓攣鏍囪锛屼竴涓璞℃渶澶氬彧鑳藉皢monitor缁欎竴涓嚎绋嬨��

Synchronized鏄互鐗虹壊绋嬪簭杩愯鐨勬晥鐜囦负浠d环鐨勶紝鍥犳搴旇灏介噺鎺у埗浜掓枼浠g爜鍧楃殑鑼冨洿銆�

鏂规硶鐨�Synchronized鐗规�ф湰韬笉浼氳缁ф壙锛屽彧鑳借鐩栥��

绾跨▼鍥犱负鏈嬁鍒伴攣鏍囪鑰屽彂鐢熺殑闃诲涓嶅悓浜庡墠闈簲涓熀鏈姸鎬佷腑鐨勯樆濉烇紝绉颁负閿佹睜銆�

姣忎釜瀵硅薄閮芥湁鑷繁鐨勪竴涓攣姹犵殑绌洪棿锛岀敤浜庢斁缃瓑寰呰繍琛岀殑绾跨▼銆�

杩欎簺绾跨▼涓摢涓嚎绋嬫嬁鍒伴攣鏍囪鐢辩郴缁熷喅瀹氥��

閿佹爣璁板鏋滆繃澶氾紝灏变細鍑虹幇绾跨▼绛夊緟鍏朵粬绾跨▼閲婃斁閿佹爣璁帮紝鑰屽張閮戒笉閲婃斁鑷繁鐨勯攣鏍囪渚涘叾浠栫嚎绋嬭繍琛岀殑鐘跺喌銆傚氨鏄閿併��

姝婚攣鐨勯棶棰橀�氳繃绾跨▼闂寸殑閫氫俊鐨勬柟寮忚繘琛岃В鍐炽��

绾跨▼闂撮�氫俊鏈哄埗瀹為檯涓婁篃灏辨槸鍗忚皟鏈哄埗銆�

绾跨▼闂撮�氫俊浣跨敤鐨勭┖闂寸О涔嬩负瀵硅薄鐨勭瓑寰呴槦鍒楋紝鍒欎釜闃熷垪涔熸槸灞炰簬瀵硅薄鐨勭┖闂寸殑銆�

Object绫讳腑鍙堜竴涓�wait()锛屽湪杩愯鐘舵�佷腑锛岀嚎绋嬭皟鐢�wait()锛屾鏃惰〃绀虹潃绾跨▼灏嗛噴鏀捐嚜宸辨墍鏈夌殑閿佹爣璁帮紝鍚屾椂杩涘叆杩欎釜瀵硅薄鐨勭瓑寰呴槦鍒椼��

绛夊緟闃熷垪鐨勭姸鎬佷篃鏄樆濉炵姸鎬侊紝鍙笉杩囩嚎绋嬮噴鏀捐嚜宸辩殑閿佹爣璁般��

Notify()

濡傛灉涓�涓嚎绋嬭皟鐢ㄥ璞$殑notify()锛屽氨鏄�氱煡瀵硅薄绛夊緟闃熷垪鐨勪竴涓嚎绋嬪嚭鍒椼�傝繘鍏ラ攣姹犮�傚鏋滀娇鐢�notifyall()鍒欓�氱煡绛夊緟闃熷垪涓墍鏈夌殑绾跨▼鍑哄垪銆�

娉ㄦ剰锛氬彧鑳藉鍔犻攣鐨勮祫婧愯繘琛�wait()鍜�notify()銆�

閲婃斁閿佹爣璁板彧鏈夊湪Synchronized浠g爜缁撴潫鎴栬�呰皟鐢�wait()銆�

娉ㄦ剰閿佹爣璁版槸鑷繁涓嶄細鑷姩閲婃斁锛屽繀椤绘湁閫氱煡銆�

娉ㄦ剰鍦ㄧ▼搴忎腑鍒ゅ畾涓�涓潯浠舵槸鍚︽垚绔嬫椂瑕佹敞鎰忎娇鐢�WHILE瑕佹瘮浣跨敤IF瑕佷弗瀵嗐��

WHILE浼氭斁缃▼搴忛ザ杩囧垽鏂潯浠惰�岄�犳垚瓒婄晫銆�

琛ュ厖鐭ヨ瘑锛�

suspend锛堬級鏄皢涓�涓繍琛屾椂鐘舵�佽繘鍏ラ樆濉炵姸鎬侊紙娉ㄦ剰涓嶉噴鏀鹃攣鏍囪锛夈�傛仮澶嶇姸鎬佺殑鏃跺�欑敤resume()銆�Stop()鎸囬噴鏀惧叏閮ㄣ��

杩欏嚑涓柟娉曚笂閮芥湁Deprecated鏍囧織锛岃鏄庤繖涓柟娉曚笉鎺ㄨ崘浣跨敤銆�

涓�鑸潵璇达紝涓绘柟娉�main()缁撴潫鐨勬椂鍊欑嚎绋嬬粨鏉燂紝鍙槸涔熷彲鑳藉嚭鐜伴渶瑕佷腑鏂嚎绋嬬殑鎯呭喌銆傚浜庡绾跨▼涓�鑸瘡涓嚎绋嬮兘鏄竴涓惊鐜紝濡傛灉涓柇绾跨▼鎴戜滑蹇呴』鎯冲姙娉曚娇鍏堕��鍑恒��

濡傛灉涓绘柟娉�main()鎯崇粨鏉熼樆濉炰腑鐨勭嚎绋嬶紙姣斿sleep鎴�wait锛�

閭d箞鎴戜滑鍙互浠庡叾浠栬繘绋嬪绾跨▼瀵硅薄璋冪敤interrupt()銆傜敤浜庡闃诲锛堟垨閿佹睜锛変細鎶涘嚭渚嬪Interrupted Exception銆�

杩欎釜渚嬪浼氫娇绾跨▼涓柇骞舵墽琛�catch涓唬鐮併��

澶氱嚎绋嬩腑鐨勯噸鐐癸細瀹炵幇澶氱嚎绋嬬殑涓ょ鏂瑰紡锛�Synchronized,浠ュ強鐢熶骇鑰呭拰娑堣垂鑰呴棶棰橈紙ProducerConsumer.java鏂囦欢锛夈��

缁冧範锛�

瀛樿溅浣嶇殑鍋滃紑杞︾殑娆″簭杈撳嚭闂锛�

鍐欎袱涓嚎绋嬶紝涓�涓嚎绋嬫墦鍗�1-52锛屽彟涓�涓嚎绋嬬瓟搴斿瓧姣�A-Z銆傛墦鍗伴『搴忎负12A34B56C鈥︹��5152Z銆傞�氳繃浣跨敤绾跨▼涔嬮棿鐨勯�氫俊鍗忚皟鍏崇郴銆�

娉細鍒嗗埆缁欎袱涓璞℃瀯閫犱竴涓璞�o锛屾暟瀛楁瘡鎵撳嵃涓や釜鎴栧瓧姣嶆瘡鎵撳嵃涓�涓氨鎵цo.wait()銆傚湪o.wait()涔嬪墠涓嶈蹇樹簡鍐�o.notify()銆�

琛ュ厖璇存槑锛氶�氳繃Synchronized锛屽彲鐭�Vector杈�ArrayList鏂规硶鐨勫尯鍒氨鏄�Vector鎵�鏈夌殑鏂规硶閮芥湁Synchronized銆傛墍浠�Vector鏇翠负瀹夊叏銆�

鍚屾牱锛�Hashtable杈�HashMap涔熸槸濡傛銆�

12.08

Module 10锛�I/O娴侊紙java濡備綍瀹炵幇涓庡鐣屾暟鎹殑浜ゆ祦锛�

Input/Output锛氭寚璺ㄨ秺鍑轰簡JVM鐨勮竟鐣岋紝涓庡鐣屾暟鎹殑婧愬ご鎴栬�呯洰鏍囨暟鎹簮杩涜鏁版嵁浜ゆ崲銆�

杈撳嚭

杈撳叆

娉ㄦ剰锛氳緭鍏�/杈撳嚭鏄拡瀵�JVM鑰岃█銆�

File绫伙紙java.io.*锛夊彲琛ㄧず涓�涓枃浠讹紝涔熸湁鍙兘鏄竴涓洰褰曪紙鍦�JAVA涓枃浠跺拰鐩綍閮藉睘浜庤繖涓被涓紝鑰屼笖鍖哄垎涓嶆槸闈炲父鐨勬槑鏄撅級銆�

Java.io涓嬬殑鏂规硶鏄纾佺洏涓婄殑鏂囦欢杩涜纾佺洏鎿嶄綔锛屼絾鏄棤娉曡鍙栨枃浠剁殑鍐呭銆�

娉ㄦ剰锛氬垱寤轰竴涓枃浠跺璞″拰鍒涘缓涓�涓枃浠跺湪JAVA涓槸涓や釜涓嶅悓鐨勬蹇点�傚墠鑰呮槸鍦ㄨ櫄鎷熸満涓垱寤轰簡涓�涓枃浠讹紝浣嗗嵈骞舵病鏈夊皢瀹冪湡姝e湴鍒涘缓鍒�OS鐨勬枃浠剁郴缁熶腑锛岄殢鐫�铏氭嫙鏈虹殑鍏抽棴锛岃繖涓垱寤虹殑瀵硅薄涔熷氨娑堝け浜嗐�傝�屽垱寤轰竴涓枃浠舵墠鏄湪绯荤粺涓湡姝e湴寤虹珛涓�涓枃浠躲��

渚嬪锛�File f=new File(鈥�11.txt鈥�);//鍒涘缓涓�涓悕涓�11.txt鐨勬枃浠跺璞�

f.CreateNewFile();//鐪熸鍦板垱寤烘枃浠�

f.CreateMkdir()锛氬垱寤虹洰褰�

f.delete()锛涘垹闄ゆ枃浠�

f.deleteOnExit();鍦ㄨ繘绋嬮��鍑虹殑鏃跺�欏垹闄ゆ枃浠讹紝杩欐牱鐨勬搷浣滈�氬父鐢ㄥ湪涓存椂鏂囦欢鐨勫垹闄ゃ��

瀵逛簬鍛戒护锛�File f2=new file(鈥渄:\\abc\\789\\1.txt鈥�)

杩欎釜鍛戒护涓嶅叿澶囪法骞冲彴鎬э紝鍥犱负涓嶅悓鐨�OS鐨勬枃浠剁郴缁熷緢涓嶇浉鍚屻��

濡傛灉鎯宠璺ㄥ钩鍙帮紝鍦�file绫讳笅鏈�separtor()锛岃繑鍥為攣鍑哄钩鍙扮殑鏂囦欢鍒嗛殧绗︺��

File.fdir=new File(File.separator);

String str=鈥漚bc鈥�+File.separator+鈥�789鈥�;

浣跨敤鏂囦欢涓嬬殑鏂规硶鐨勬椂鍊欎竴瀹氭敞鎰忔槸鍚﹀叿澶囪法骞冲彴鎬с��

List()锛氭樉绀烘枃浠剁殑鍚嶏紙鐩稿璺緞锛�

ListFiles()锛氳繑鍥�Files绫诲瀷鏁扮粍锛屽彲浠ョ敤getName()鏉ヨ闂埌鏂囦欢鍚嶃��

浣跨敤isDirectory()鍜�isFile()鏉ュ垽鏂┒绔熸槸鏂囦欢杩樻槸鐩綍銆�

缁冧範锛�

鍐欎竴涓�javaTest绋嬪簭锛屽垪鍑烘墍鏈夌洰褰曚笅鐨�*.java鏂囦欢锛屾妸瀛愮洰褰曚笅鐨�JAVA鏂囦欢涔熸墦鍗板嚭鏉ャ��

浣跨敤I/O娴佽闂�file涓殑鍐呭銆�

JVM涓庡鐣岄�氳繃鏁版嵁閫氶亾杩涜鏁版嵁浜ゆ崲銆�

鍒嗙被锛�

鎸夋祦鍒嗕负杈撳叆娴佸拰杈撳嚭娴侊紱

鎸変紶杈撳崟浣嶅垎涓哄瓧鑺傛祦鍜屽瓧绗︽祦锛�

杩樺彲浠ュ垎涓鸿妭鐐规祦鍜岃繃婊ゆ祦銆�

鑺傜偣娴侊細璐熻矗鏁版嵁婧愬拰绋嬪簭涔嬮棿寤虹珛杩炴帴锛�

杩囨护娴侊細鐢ㄤ簬缁欒妭鐐瑰鍔犲姛鑳姐��

杩囨护娴佺殑鏋勯�犳柟寮忔槸浠ュ叾浠栨祦浣嶅弬鏁版瀯閫狅紙杩欐牱鐨勮璁℃ā寮忕О涓鸿楗版ā寮忥級銆�

瀛楄妭杈撳叆娴侊細io鍖呬腑鐨�InputStream涓烘墍鏈夊瓧鑺傝緭鍏ユ祦鐨勭埗绫汇��

Int read();璇诲叆涓�涓瓧鑺傦紙姣忔涓�涓級锛�

鍙厛浣跨敤newbyte[]=鏁扮粍锛岃皟鐢�read(byte[] b)

read (byte[])杩斿洖鍊煎彲浠ヨ〃绀烘湁鏁堟暟锛�read (byte[])杩斿洖鍊间负-1琛ㄧず缁撴潫銆�

瀛楄妭杈撳嚭娴侊細io鍖呬腑鐨�OutputStream浣嶆墍鏈夊瓧鑺傝緭鍏ユ祦鐨勭埗绫汇��

Write鍜岃緭鍏ユ祦涓殑read鐩稿搴斻��

鍦ㄦ祦涓�close()鏂规硶鐢辩▼搴忓憳鎺у埗銆傚洜涓鸿緭鍏ヨ緭鍑烘祦宸茬粡瓒呰秺浜�VM鐨勮竟鐣岋紝鎵�浠ユ湁鏃跺彲鑳芥棤娉曞洖鏀惰祫婧愩��

鍘熷垯锛氬嚒鏄法鍑鸿櫄鎷熸満杈圭晫鐨勮祫婧愰兘瑕佹眰绋嬪簭鍛樿嚜宸卞叧闂紝涓嶈鎸囨湜鍨冨溇鍥炴敹銆�

浠�Stream缁撳熬鐨勭被閮芥槸瀛楄妭娴併��

濡傛灉鏋勯��FileOutputStream鐨勫悓鏃剁鐩樹細寤虹珛涓�涓枃浠躲�傚鏋滃垱寤虹殑鏂囦欢涓庣鐩樹笂宸叉湁鐨勬枃浠跺悕閲嶅悕锛屽氨浼氬彂鐢熻鐩栥��

鐢�FileOutputStream涓殑boolean锛屽垯瑙嗭紝娣诲姞鎯呭喌锛屽皢鏁版嵁瑕嗙洊閲嶅悕鏂囦欢杩樻槸灏嗚緭鍏ュ唴瀹规斁鍦ㄦ枃浠剁殑鍚庨潰銆傦紙缂栧啓绋嬪簭楠岃瘉锛�

DataOutputStream:杈撳叆鏁版嵁鐨勭被鍨嬨��

鍥犱负姣忎腑鏁版嵁绫诲瀷鐨勪笉鍚岋紝鎵�浠ュ彲鑳戒細杈撳嚭閿欒銆�

鎵�鏈夊浜庯細DataOutputStream

DataInputStream

涓よ�呯殑杈撳叆椤哄簭蹇呴』涓�鑷淬��

杩囨护娴侊細

bufferedOutputStream

bufferedInputStream

鐢ㄤ簬缁欒妭鐐规祦澧炲姞涓�涓紦鍐茬殑鍔熻兘銆�

鍦�VM鐨勫唴閮ㄥ缓绔嬩竴涓紦鍐插尯锛屾暟鎹厛鍐欏叆缂撳啿鍖猴紝绛夊埌缂撳啿鍖虹殑鏁版嵁婊′簡涔嬪悗鍐嶄竴娆℃�у啓鍑猴紝鏁堢巼寰堥珮銆�

浣跨敤甯︾紦鍐插尯鐨勮緭鍏ヨ緭鍑烘祦鐨勯�熷害浼氬ぇ骞呮彁楂橈紝缂撳啿鍖鸿秺澶э紝鏁堢巼瓒婇珮銆傦紙杩欐槸鍏稿瀷鐨勭壓鐗茬┖闂存崲鏃堕棿锛�

鍒囪锛氫娇鐢ㄥ甫缂撳啿鍖虹殑娴侊紝濡傛灉鏁版嵁鏁版嵁杈撳叆瀹屾瘯锛屼娇鐢�flush鏂规硶灏嗙紦鍐插尯涓殑鍐呭涓�娆℃�у啓鍏ュ埌澶栭儴鏁版嵁婧愩�傜敤close()涔熷彲浠ヨ揪鍒扮浉鍚岀殑鏁堟灉锛屽洜涓烘瘡娆�close閮戒細浣跨敤flush銆備竴瀹氳娉ㄦ剰鍏抽棴澶栭儴鐨勮繃婊ゆ祦銆�

锛堥潪閲嶇偣锛夌閬撴祦锛氫篃鏄竴绉嶈妭鐐规祦锛岀敤浜庣粰涓や釜绾跨▼浜ゆ崲鏁版嵁銆�

PipedOutputStream

PipedInputStream

杈撳嚭娴侊細connect(杈撳叆娴�)

RondomAccessFile绫诲厑璁搁殢鏈鸿闂枃浠�

GetFilepoint()鍙互鐭ラ亾鏂囦欢涓殑鎸囬拡浣嶇疆锛屼娇鐢�seek()瀹氫綅銆�

Mode(鈥渞鈥�:闅忔満璇伙紱鈥漺鈥�锛氶殢鏈哄啓锛�鈥漴w鈥�锛氶殢鏈鸿鍐�)

缁冧範锛氬啓涓�涓被A锛�JAVA A file1 file2

file1瑕佹眰鏄郴缁熶腑宸茬粡瀛樺湪鐨勬枃浠躲��File2鏄繕娌℃湁瀛樺湪鐨勬枃浠躲��

鎵ц瀹岃繖涓懡浠わ紝閭d箞file2灏辨槸file1涓殑鍐呭銆�

瀛楃娴侊細reader\write鍙兘杈撶函鏂囨湰鏂囦欢銆�

FileReader绫伙細瀛楃鏂囦欢鐨勮緭鍑�

瀛楄妭娴佷笌瀛楃娴佺殑鍖哄埆锛�

瀛楄妭娴佺殑瀛楃缂栫爜锛�

瀛楃缂栫爜鎶婂瓧绗﹁浆鎹㈡垚鏁板瓧瀛樺偍鍒拌绠楁満涓紝鎸�ASCii灏嗗瓧姣嶆槧灏勪负鏁存暟銆�

鎶婃暟瀛椾粠璁$畻鏈鸿浆鎹㈡垚鐩稿簲鐨勫瓧绗︾殑杩囩▼绉颁负瑙g爜銆�

缂栫爜鏂瑰紡鐨勫垎绫伙細

ASCII锛堟暟瀛椼�佽嫳鏂囷級:1涓瓧绗﹀崰涓�涓瓧鑺傦紙鎵�鏈夌殑缂栫爜闆嗛兘鍏煎ASCII锛�

ISO8859-1锛堟娲诧級锛�1涓瓧绗﹀崰涓�涓瓧鑺�

GB-2312/GBK锛�1涓瓧绗﹀崰涓や釜瀛楄妭

Unicode: 1涓瓧绗﹀崰涓や釜瀛楄妭锛堢綉缁滀紶杈撻�熷害鎱級

UTF-8锛氬彉闀垮瓧鑺傦紝瀵逛簬鑻辨枃涓�涓瓧鑺傦紝瀵逛簬姹夊瓧涓や釜鎴栦笁涓瓧鑺傘��

鍘熷垯锛氫繚璇佺紪瑙g爜鏂瑰紡鐨勭粺涓�锛屾墠鑳戒笉鑷充簬鍑虹幇閿欒銆�

Io鍖呯殑InputStreamread绉颁负浠庡瓧鑺傛祦鍒板瓧绗︽祦鐨勬ˉ杞崲绫汇�傝繖涓被鍙互璁惧畾瀛楃杞崲鏂瑰紡銆�

OutputStreamred:瀛楃鍒板瓧鑺�

Bufferread鏈�readline()浣垮緱瀛楃杈撳叆鏇村姞鏂逛究銆�

鍦�I/O娴佷腑锛屾墍鏈夎緭鍏ユ柟娉曢兘鏄樆濉炴柟娉曘��

Bufferwrite缁欒緭鍑哄瓧绗﹀姞缂撳啿锛屽洜涓哄畠鐨勬柟娉曞緢灏戯紝鎵�浠ヤ娇鐢ㄧ埗绫�printwrite锛屽畠鍙互浣跨敤瀛楄妭娴佸璞★紝鑰屼笖鏂规硶寰堝銆�

缁冧範锛氬仛涓�涓浜嬫湰

swing/JfileChoose: getSelect file()

InputStreeamReader锛氭妸瀛楄妭鍙樹负瀛楃

JAVA涓瀛楃涓查暱鏃犻檺鍒�bufferedReader锛�ir锛�

12.09

class ObjectOutputStream涔熸槸杩囨护娴侊紝浣胯妭鐐规祦鐩存帴鑾峰緱杈撳嚭瀵硅薄銆�

鏈�鏈夌敤鐨勬柟娉曪細WriteObject(Object b)

鐢ㄦ祦浼犺緭瀵硅薄绉颁负瀵硅薄鐨勫簭鍒楀寲锛屼絾骞朵笉浣挎墍鏈夌殑瀵硅薄閮藉彲浠ヨ繘琛屽簭鍒楀寲鐨勩�傚彧鏈夊湪瀹炵幇绫绘椂蹇呴』瀹炵幇涓�涓帴鍙o細IO鍖呬笅鐨�Serializable(鍙簭鍒楀寲鐨�)銆傛鎺ュ彛娌℃湁浠讳綍鐨勬柟娉曪紝杩欐牱鐨勬帴鍙gО涓烘爣璁版帴鍙c��

Class Student implements Serializable

鎶婂璞¢�氳繃娴佸簭鍒楀寲鍒版煇涓�涓寔涔呮�т粙璐ㄧО涓哄璞$殑鍙寔涔呭寲銆�

Hibernate灏辨槸鐮旂┒瀵硅薄鐨勫彲鎸佷箙鍖栥��

ObuectInputStreamin=newObjectInputStream;

Object o1=in.readObuect();

Student s1=(Student)o1锛�

娉ㄦ剰锛氬洜涓�o1鏄竴涓璞★紝鍥犱负闇�瑕佸鍏惰繘琛屼繚瀛樸��

Transient鐢ㄦ潵淇グ灞炴�с��

Transient int num;

琛ㄧず褰撴垜浠灞炴�у簭鍒楀寲鏃跺拷鐣ヨ繖涓睘鎬э紙鍗冲拷鐣ヤ笉浣夸箣鎸佷箙鍖栵級銆�

鎵�鏈夊睘鎬у繀椤婚兘鏄彲搴忓垪鍖栫殑锛岀壒鍒槸褰撴湁浜涘睘鎬ф湰韬篃鏄璞$殑鏃跺�欙紝瑕佸挨鍏舵敞鎰忚繖涓�鐐广��

鍒ゆ柇鏄惁涓�涓睘鎬ф垨瀵硅薄鍙簭鍒楀寲锛�Serialver銆�

Serialver TestObject锛�TestObject蹇呴』涓哄凡缁忕紪璇戯級

鎵ц缁撴灉锛氬鏋滀笉鍙簭鍒楀寲锛涘垯鍑虹幇涓嶅彲搴忓垪鍖栫殑鎻愮ず銆傚鏋滃彲浠ュ簭鍒楀寲锛岄偅涔堝氨浼氬嚭鐜板簭鍒楀寲鐨�ID锛�UID銆�

java.until.*鏈�

StringTokenizer锛堝弬鏁�1锛屽弬鏁�2锛夋寜鏌愮绗﹀彿闅斿紑鏂囦欢

StringTokenizer(s,鈥�:鈥�)鐢�鈥�锛�鈥�闅斿紑瀛楃锛�s涓哄璞°��

缁冧範锛氬皢涓�涓被搴忓垪鍖栧埌鏂囦欢锛岀劧鍚庤鍑恒�備笅鍗堬細

缃戠粶鍩虹鐭ヨ瘑

JAVA缃戠粶缂栫▼

缃戠粶涓庡垎甯冨紡闆嗙兢绯荤粺鐨勫尯鍒細姣忎釜鑺傜偣閮芥槸涓�鍙拌绠楁満锛岃�屼笉鏄悇绉嶈绠楁満鍐呴儴鐨勫姛鑳借澶囥��

Ip:鍏锋湁鍏ㄧ悆鍞竴鎬э紝鐩稿浜�internet锛�IP涓洪�昏緫鍦板潃銆�

绔彛(port)锛氫竴鍙�PC涓彲浠ユ湁65536涓鍙o紝杩涚▼閫氳繃绔彛浜ゆ崲鏁版嵁銆傝繛绾跨殑鏃跺�欓渶瑕佽緭鍏�IP涔熼渶瑕佽緭鍏ョ鍙d俊鎭��

璁$畻鏈洪�氫俊瀹為檯涓婄殑涓绘満涔嬮棿鐨勮繘绋嬮�氫俊锛岃繘绋嬬殑閫氫俊灏遍渶瑕佸湪绔彛杩涜鑱旂郴銆�

192.168.0.23:21

鍗忚锛氫负浜嗚繘琛岀綉缁滀腑鐨勬暟鎹氦鎹紙閫氫俊锛夎�屽缓绔嬬殑瑙勫垯銆佹爣鍑嗘垨绾﹀畾銆�

涓嶅悓灞傜殑鍗忚鏄笉鍚岀殑銆�

缃戠粶灞傦細瀵诲潃銆佽矾鐢憋紙鎸囧浣曞埌杈惧湴鍧�鐨勮繃绋嬶級

浼犺緭灞傦細绔彛杩炴帴

TCP妯″瀷锛氬簲鐢ㄥ眰/浼犺緭灞�/缃戠粶灞�/缃戠粶鎺ュ彛

绔彛鏄竴绉嶆娊璞$殑杞欢缁撴瀯锛屼笌鍗忚鐩稿叧锛�TCP23绔彛鍜�UDT23绔彛涓轰袱涓笉鍚岀殑姒傚康銆�

绔彛搴旇鐢�1024浠ヤ笂鐨勭鍙o紝浠ヤ笅鐨勭鍙i兘宸茬粡璁惧畾鍔熻兘銆�

濂楁帴瀛�(socket)鐨勫紩鍏ワ細

Ip+Port=Socket锛堣繖鏄釜瀵硅薄鐨勬蹇点�傦級

Socket涓轰紶杈撳眰姒傚康锛岃��JSP鏄搴旂敤灞傜紪绋嬨�備緥锛�

java.net.*;

(Server绔畾涔夐『搴�)

ServerSocket(intport)

Socket.accept()锛�//闃诲鏂规硶锛屽綋瀹㈡埛绔彂鍑鸿姹傛槸灏辨仮澶�

濡傛灉瀹㈡埛绔敹鍒拌姹傦細

鍒�Socket SI=ss.accept()锛�

娉ㄦ剰瀹㈡埛绔拰鏈嶅姟鍣ㄧ殑Socket涓轰袱涓笉鍚岀殑socket銆�

Socket鐨勪袱涓柟娉曪細

getInputStream()锛氬鎴风鐢�

getOutputStream()鏈嶅姟鍣ㄧ鐢�

浣跨敤瀹屾瘯鍚庡垏璁�Socket.close()锛屼袱涓�Socket閮藉叧锛岃�屼笖涓嶇敤鍏冲唴閮ㄧ殑娴併��

鍦�client绔紝Socket s=new Socket(鈥�127.0.0.1鈥�,8000);

127.0.0.1涓轰竴涓粯璁ゆ湰鏈虹殑鍦板潃銆�

缁冧範锛�

瀹㈡埛绔悜鏈嶅姟鍣ㄥ彂鍑轰竴涓瓧绗︿覆锛屾湇鍔″櫒杞崲鎴愬ぇ鍐欎紶鍥炲鎴风銆�

澶у啓鐨勫嚱鏁帮細String.toUpperCase()

鏈嶅姟鍣ㄥ憡璇夊鎴风锛�鈥�鑷紑鏈轰互鏉ヤ綘鏄n涓敤鎴�鈥�銆�

12.12

UDP缂栫▼锛�

DatagramSocket锛堥偖閫掑憳锛夛細瀵瑰簲鏁版嵁鎶ョ殑Socket姒傚康锛屼笉闇�瑕佸垱寤轰袱涓�socket锛屼笉鍙娇鐢ㄨ緭鍏ヨ緭鍑烘祦銆�

DatagramPacket锛堜俊浠讹級锛氭暟鎹寘锛屾槸UDP涓嬭繘琛屼紶杈撴暟鎹殑鍗曚綅锛屾暟鎹瓨鏀惧湪瀛楄妭鏁扮粍涓��

UDP涔熼渶瑕佺幇鏈�Server绔紝鐒跺悗鍐嶆湁Client绔��

涓ょ閮芥槸DatagramPacket锛堢浉褰撲簬鐢佃瘽鐨勬蹇碉級锛岄渶瑕�NEW涓や釜DatagramPacket銆�

InetAddress:缃戝潃

杩欑淇℃伅浼犺緭鏂瑰紡鐩稿綋浜庝紶鐪燂紝淇℃伅鎵撳寘锛屽湪鎺ュ彈绔噯澶囩焊銆�

妯″紡锛�

鍙戦�佺锛�Server:

DatagramPacketinDataPacket=new DatagramPacket ((msg,msg.length); InetAdress.getByName(ip),port);

鎺ユ敹绔細

clientAddress=inDataPack.getAddress();//鍙栧緱鍦板潃

clientPort=inDataPack.getPort();//鍙栧緱绔彛鍙�

datagramSocket.send;//Server

datagramSocket.accept;//Client

URL:鍦ㄥ簲鐢ㄥ眰鐨勭紪绋�

娉ㄦ剰姣旇緝锛�

http://Localhost:8080/directory//鏌ユ壘缃戠粶鏈嶅姟鍣ㄧ殑鐩綍

file://directory//鏌ユ壘鏈湴鐨勬枃浠剁郴缁�

java鐨勫紑鍙戜富瑕佷互http涓哄熀纭�銆�

鍙嶅皠锛氫富瑕佺敤浜庡伐鍏峰拰妗嗘灦鐨勫紑鍙戙��

鍙嶅皠鏄浜庣被鐨勫啀鎶借薄锛涢�氳繃瀛楃涓叉潵鎶借薄绫汇��

JAVA绫荤殑杩愯锛�classLoader:鍔犺浇鍒拌櫄鎷熸満锛�vm锛�

Vm涓彧鑳藉瓨鍌ㄥ璞★紙鍔ㄦ�佽繍琛屾椂鐨勬蹇碉級锛�.class鏂囦欢鍔犺浇鍒�VM涓婂氨鎴愪负涓�涓璞★紝鍚屾椂鍒濆闈欐�佹垚鍛樺強闈欐�佷唬鐮侊紙鍙墽琛屼竴娆★級銆�

Lang鍖呬笅鏈変竴涓被涓�Class锛氬湪鍙嶅皠涓娇鐢ㄣ�傛绫讳腑鐨勬瘡涓璞′负VM涓殑绫诲璞★紝姣忎釜绫婚兘瀵瑰簲绫荤被鐨勪竴涓璞★紙class.class锛夈��

渚嬶細瀵逛簬涓�涓�Object绫伙紝鐢�getClass()寰楀埌鍏剁被鐨勫璞★紝鑾峰緱绫荤殑瀵硅薄灏辩浉褰撲簬鑾峰緱绫荤殑淇℃伅锛屽彲浠ヨ皟鐢ㄥ叾涓嬬殑鎵�鏈夋柟娉曪紝鍖呮嫭绫荤殑绉佹湁鏂规硶銆�

娉ㄦ剰锛氬湪鍙嶅皠涓病鏈夌畝鍗曟暟鎹被鍨嬶紝鎵�鏈夌殑缂栬瘧鏃剁被鍨嬮兘鏄璞°��

鍙嶅皠鎶婄紪璇戞椂搴旇瑙e喅鐨勯棶棰樼暀鍒颁簡杩愯鏃躲��

你可能感兴趣的:(Java)