鍓嶅叓澶╃瑪璁�

DAY聽 01

JAVA绠�杩�

Java鏄敱SUN鍏徃鍦�1995骞存帹鍑虹殑涓�闂ㄩ珮绾х紪绋嬭瑷�锛屾槸鐜颁粖鏈嶅姟鍣ㄧ鐨勯閫夌紪绋嬭瑷�锛屾槸澶ф暟鎹殑鍩虹璇█銆侸ava鐨勪竴涓噸瑕佺殑鐗规�ф槸璺ㄥ钩鍙般��

Java涔嬫墍浠ヨ兘澶熻法骞冲彴鏄洜涓烘湁JVM锛圝ava Virtual Machine锛� Java铏氭嫙鏈猴級銆傛墍鏈夌殑Java绋嬪簭骞朵笉鏄洿鎺ュ拰鎿嶄綔绯荤粺浜や簰鑰屾槸鍏堜氦鐢盝VM杩涜缈昏瘧锛岀劧鍚嶫VM灏嗙▼搴忕炕璇戜负褰撳墠鎿嶄綔绯荤粺鑳藉鐞嗚В鐨勮瑷�涔嬪悗鍐嶄氦鐢辨搷浣滅郴缁熸墽琛屻��

娉ㄦ剰锛欽AVA璇█鏄法骞冲彴鐨勪絾鏄疛VM涓嶆槸璺ㄥ钩鍙扮殑

鎶�鏈粨鏋�

JAVASE --- Java Standard Edition --- Java鏍囧噯鐗�/鍩虹鐗堛�傛槸Java鎶�鏈粨鏋勭殑鍩虹

JAVAEE --- Java Enterprise Edition --- Java浼佷笟鐗堬紝鏄湪浼佷笟涓繘琛屽洟闃熷紑鍙戠殑鏃跺�欎娇鐢�

JAVAME --- Java Micro Edition --- Java寰瀷鐗堬紝鏄负涓�浜涘皬鍨嬬數瀛愮殑宓屽叆鏉ユ彁渚涙柟妗�

JDK --- Java Development Kit --- Java寮�鍙戝伐鍏峰寘锛屼负Java绋嬪簭鐨勫紑鍙戞潵鎻愪緵鍩烘湰鐨勫伐鍏� --- 鍖呭惈浜嗗伐鍏峰寘+ JRE聽

JRE --- Java Runtime Environment --- Java杩愯鏃剁幆澧冿紝涓篔ava绋嬪簭鐨勮繍琛屾潵鎻愪緵鍩烘湰鐨勭幆澧� --- 鍖呭惈浜咼VM + 鏍稿績绫诲簱

JVM --- Java Virtual Machine --- Java铏氭嫙鏈猴紝鏄疛ava绋嬪簭鑳藉璺ㄥ钩鍙扮殑鍓嶆彁

Oak --- 姗℃爲

JDK1.0 -> JDK1.1 -> JDK1.2 -> JDK1.3 -> JDK1.4 -> JDK1.5/JDK5.0 -> JDK1.6/JDK6 -> JDK1.7/JDK7.0 -> JDK1.8 -> JDK1.9/JDK17.9 -> JDK10/JDK18.3 -> JDK11/JDK18.9

鎵╁睍锛歀TS - long time service

www.oracle.com

娉ㄦ剰锛氬畨瑁呰矾寰勪腑涓嶈鍑虹幇绌烘牸鍜屼腑鏂�

灏嗙▼搴忕炕璇戞垚璁$畻鏈烘墍鑳界悊瑙g殑璇█ --- 缂栬瘧

Java鏂囦欢鍦ㄧ紪璇戝畬鎴愪箣鍚庝細浜х敓涓�涓猚lass鏂囦欢 --- 瀛楄妭鐮佹枃浠讹紙缁欒绠楁満鐪嬬殑锛�

娉ㄦ剰锛�

1. 绋嬪簭瑕佹兂杩愯闇�瑕佷竴涓叆鍙� --- 涓诲嚱鏁�

2. class鏂囦欢鍚嶅拰绫诲悕瀵瑰簲锛屽湪杩愯鐨勬椂鍊欒鍐欑殑鏄痗lass鏂囦欢鍚�

3. 鐢╬ublic闄愬埗鐨勭被绉颁箣涓哄叕鍏辩被锛屽叕鍏辩被瑕佹眰绫诲悕鍜孞ava鏂囦欢鍚嶅繀椤讳竴鑷淬��

4. 濡傛灉瀹氫箟浜嗗寘锛屽湪杩愯鐨勬椂鍊欓渶瑕佹坊鍔犲寘鍚�(鍚屼竴涓洏绗�)

Java 鍖呭悕.绫诲悕 java cn.tedu.de.Demo

5.濡傛灉鎯虫妸Java鏂囦欢缂栬瘧鍒版寚瀹氬寘涓紝闇�瑕佸湪鍖呬腑澹版槑浣嶇疆锛岀劧鍚庝娇鐢ㄤ笅鍒楀懡浠ょ紪璇戯紝鍐嶄娇鐢ㄧ鍥涗釜鐭ヨ瘑鐐硅繍琛屽寘鍐呮枃浠躲��

鐜鍙橀噺锛氭寚缁欏綋鍓嶇殑鎿嶄綔绯荤粺鏉ユ寚瀹氳繍琛屽弬鏁扮殑鍊�

JAVA_HOME鍙橀噺鍊间负JDK鐨勫畨瑁呰矾寰勩��

Path=%JAVA_HOME%\bin;

PS锛氫笉鍚岀洏绗︿笅鐨勭紪璇戝拰璋冪敤

缂栬瘧锛� javac D:\\(java鏂囦欢鐨勪綅缃�)鍖呭悕.java

聽 聽 聽 渚嬪瓙锛歫avac D:\\OperatorDemo.java

杩愯锛歫ava锛堢┖鏍硷級-cp锛堢┖鏍硷級D:\\(java鏂囦欢鐨勪綅缃�)(绌烘牸)鍖呭悕

聽聽 渚嬪瓙锛歫ava锛堢┖鏍硷級-cp锛堢┖鏍硷級D:\\锛堢┖鏍硷級OperatorDemo聽 聽

鍏抽敭瀛�

鍦↗ava涓湁鐗规畩鐨勫惈涔夈��

鍒扮洰鍓嶄负姝竴鍏辨槸53涓叧閿瓧 --- 2涓叧閿瓧娌℃湁浣跨敤锛歝onst/goto --- 淇濈暀瀛�

娉ㄦ剰锛氬叧閿瓧閮芥槸灏忓啓鐨�

鏍囪瘑绗�

鍦ㄧ▼搴忚嚜瀹氫箟鐨勫悕绉�

鍛藉悕瑙勫垯

鐢卞瓧姣�(甯歌璇█鐨勫熀鏈瓧绗�)銆佹暟瀛椼�乢銆�$缁勬垚锛堜絾鏄噺灏戜娇鐢�$锛�

铏界劧java鏀寔涓枃鍛藉悕锛屼絾鏄噺灏戜娇鐢�

鏁板瓧涓嶈兘寮�澶�

涓嶈兘浣跨敤鍏抽敭瀛�

鍖哄垎澶у皬鍐櫬� Demo demo

瑙佸悕鐭ユ剰

娌℃湁涓诲嚱鏁帮紝绋嬪簭渚濈劧鑳藉缂栬瘧

DAY聽 02

澶嶄範锛�

1. Java璺ㄥ钩鍙帮細鍩轰簬JVM銆傞拡瀵规瘡涓�涓搷浣滅郴缁熼兘鏈変笉鍚岀殑jvm涓庝箣瀵瑰簲锛宩vm鍦ㄨ繖涓繃绋嬩腑灞忚斀浜嗗悇涓搷浣滅郴缁熶箣闂寸殑宸紓鎬с��

2. Java鐨勬妧鏈粨鏋勶細JAVASE JAVAEE JAVAME

3. JDK銆丣RE銆丣VM锛欽RE鍖呭惈浜咼VM+鏍稿績绫诲簱锛圝ava绋嬪簭杩愯鎵�闇�瑕佺殑鍩烘湰鐨勬敮鎸侊級锛屼负绋嬪簭鐨勮繍琛屾彁渚涚幆澧冦�侸DK鍖呭惈浜咼RE+寮�鍙戝伐鍏枫��

4. 鍏ラ棬绋嬪簭锛欽ava绋嬪簭涓�瀹氭槸鍐欏埌Java鏂囦欢锛�.java锛夛紱绋嬪簭杩愯闇�瑕佸叆鍙�---涓诲嚱鏁帮紱绫荤紪璇戝畬鎴愪箣鍚庝細浜х敓涓�涓猚lass鏂囦欢銆�

5. javac -d 鍖呯殑瀛樻斁浣嶇疆 瑕佺紪璇戠殑Java鏂囦欢

聽 java鍖呭悕.绫诲悕聽 聽

java cn.tedu.de.Demo聽

6. 鐜鍙橀噺锛欽AVA_HOME=JDK鐨勫畨瑁呰矾寰勶紝Path = %JAVA_HOME%\bin;

7. 鍏抽敭瀛楋細鏈夌壒娈婂惈涔夌殑鍗曡瘝 --- 53涓叧閿瓧 --- 2涓繚鐣欏瓧锛歝onst/goto --- 鎵�鏈夌殑鍏抽敭瀛楅兘鏄皬鍐�

8. 鏍囪瘑绗︼細绋嬪簭鑷畾涔夌殑鍚嶇О銆傜敱瀛楁瘝銆佹暟瀛椼�乢銆�$缁勬垚锛屾敮鎸佷腑鏂囧懡鍚嶃�備笉鑳戒互鏁板瓧寮�澶达紝涓嶈兘浣跨敤鍏抽敭瀛楋紝鍖哄垎澶у皬鍐欍�傝鍚嶇煡鎰忋��

椹煎嘲鍛藉悕娉�

绫诲悕/鎺ュ彛鍚嶏細濡傛灉鐢卞涓崟璇嶇粍鎴愶紝閭d箞姣忎竴涓崟璇嶇殑棣栧瓧姣嶅ぇ鍐欍�� HelloWorld

鍙橀噺鍚�/鏂规硶鍚嶏細濡傛灉鐢卞涓崟璇嶇粍鎴愶紝閭d箞绗竴涓崟璇嶇殑棣栧瓧姣嶅皬鍐欙紝鍏朵綑鍗曡瘝鐨勯瀛楁瘝澶у啓 playGame main

鍖呭悕锛氬鏋滅敱澶氫釜鍗曡瘝缁勬垚锛岄偅涔堟瘡涓�涓崟璇嶄箣闂寸敤 . 闅斿紑锛屾墍鏈夊瓧姣嶉兘鏄皬鍐� cn.tedu.de

甯搁噺鍚嶏細濡傛灉鐢卞涓崟璇嶇粍鎴愶紝閭d箞姣忎竴涓崟璇嶄箣闂寸敤_闅斿紑锛屾墍鏈夊瓧姣嶉兘鏄ぇ鍐� PLAY_GAME

娉ㄩ噴 鍗曡娉ㄩ噴涔嬮棿鍙互宓屽 ,澶氳娉ㄩ噴涔嬮棿涓嶈兘宓屽,鏂囨。娉ㄩ噴涓嶈兘宓屽澶氳娉ㄩ噴銆�

鐢ㄤ簬瑙i噴璇存槑鐨勬枃瀛�

// 娉ㄩ噴鏂囧瓧 鍗曡娉ㄩ噴

/* 娉ㄩ噴鏂囧瓧*/ 澶氳娉ㄩ噴

/** 娉ㄩ噴鏂囧瓧 */鏂囨。娉ㄩ噴 --- 閲岄潰鐨勬敞閲婂唴瀹瑰彲浠ュ埄鐢╦avadoc鍛戒护鎻愬彇鍑烘潵褰㈡垚鏂囨。锛堝氨鏄绋嬪簭鐨勮鏄庝功锛�

浠g爜鍐呭锛毬� javadoc鏂囦欢鍚�.java

瀛楅潰閲�

鍦ㄨ绠楁満涓笉鍙敼鍙樼殑閲�

鏁存暟甯搁噺锛氭墍鏈夌殑鏁存暟 7 15 186 -42

灏忔暟甯搁噺锛氭墍鏈夌殑灏忔暟 3.12 8.005 6.0 9.00

瀛楃甯搁噺锛氬皢涓�涓瓧姣嶃�佹暟瀛楁垨鑰呮槸绗﹀彿鐢� 鈥樷�� 鏍囪瘑璧锋潵 鈥榓鈥� 鈥�+鈥� 鈥�5鈥� 鈥樺皬鈥� 鈥� 鈥�

瀛楃涓插父閲忥細灏嗕竴涓垨鑰呭涓瓧绗︾敤 鈥溾�� 鏍囪瘑璧锋潵 鈥渁bc鈥� 鈥�+鈥� 鈥溾��

甯冨皵甯搁噺锛歵rue/false --- 鐢ㄤ簬琛ㄧず閫昏緫鍊�

绌哄父閲忥細null

杩涘埗

璁℃暟鏂瑰紡

浜岃繘鍒讹細0-1锛屾弧2杩�1 1+1=10 11+1=100 111+1=1000銆傚湪绋嬪簭涓互0b/0B寮�澶存爣璁颁竴涓簩杩涘埗鏁板瓧(浠嶫DK1.7寮�濮�)聽 0b1001 0b00101

鍏繘鍒讹細0-7锛屾弧8杩�1聽 7+1=10 27+1=30 77+1=100瑕佹眰浠�0寮�澶存爣璁颁竴涓叓杩涘埗鏁板瓧 045 053

鍗佽繘鍒讹細0-9锛屾弧10杩�1 Java涓暟瀛楅粯璁ゅ氨鏄崄杩涘埗

鍗佸叚杩涘埗锛�0-9锛孉-F锛屾弧16杩�1 9+1=a a+1=b f+1=10 39+1=3a 3f+1=40聽 99+1=9a 9f+1=a0 af+1=b0 ff+1=100瑕佹眰浠�0x/0X浣滀负寮�澶存爣璁奥� 0xB3

杩涘埗鐨勮浆鎹�

鍗佽繘鍒惰浆鎹负浜岃繘鍒讹細灏嗕竴涓崄杩涘埗鏁板瓧涓嶆柇鐨勯櫎浠�2锛岀劧鍚庤幏鍙栦綑鏁帮紝灏嗕綑鏁板�掑簭鎺掑垪锛屾帓鍒椾箣鍚庣殑缁撴灉灏辨槸瀵瑰簲鐨勪簩杩涘埗

浜岃繘鍒惰浆鍖栦负鍗佽繘鍒讹細浠庤繖涓簩杩涘埗鏁板瓧鐨勬渶浣庝綅娆″紑濮嬶紝鐒跺悗姣忎竴浣嶄箻浠ュ綋鍓嶇殑2鐨勪綅娆℃骞傦紝鏈�鍚庢眰鍜屻��

鍗佽繘鍒惰浆鍖栦负鍏朵粬杩涘埗锛氬崄杩涘埗鏁板瓧鍚戝摢涓繘鍒惰浆鍖栭偅涔堜箙闄や互瀵瑰簲鐨勮繘鍒讹紝鐒跺悗鍙栦綑鏁帮紝灏嗕綑鏁板�掓帓

鍏朵粬杩涘埗杞寲涓哄崄杩涘埗锛氫粠杩欎釜杩涘埗鐨勬暟瀛楃殑浣庝綅娆″紑濮嬶紝鐒跺悗鎸変綅娆′箻浠ュ綋鍓嶇殑杩涘埗鐨勪綅娆℃骞傦紝鏈�鍚庢眰鍜�

浜岃繘鍒惰浆鍖栦负鍏繘鍒讹細浠庝簩杩涘埗鏁板瓧鐨勪綆浣嶆寮�濮嬶紝姣忎笁浣嶅垝鍒嗕负涓�缁勪骇鐢熶竴涓叓杩涘埗鏁板瓧锛屾渶楂樹綅濡傛灉涓嶈冻涓変綅锛岃ˉ0銆傛渶鍚庡皢浜х敓鐨勫叓杩涘埗鏁板瓧鎺掑垪 --- 涓夊彉涓�

鍏繘鍒惰浆鍖栦负浜岃繘鍒讹細姣忎竴浣嶅叓杩涘埗鏁板瓧浜х敓3浣嶄簩杩涘埗鏁板瓧锛屽鏋滀笉瓒充笁浣嶏紝琛�0. --- 涓�鍙樹笁

鍗佸叚杩涘埗鍜屼簩杩涘埗涔嬮棿鐨勮浆鎹㈢被姣斿叓杩涘埗鍜屼簩杩涘埗鐨勮浆鎹�

鎵╁睍锛氬崄杩涘埗灏忔暟杞崲涓轰簩杩涘埗

缁濆ぇ閮ㄥ垎鐨勫皬鏁拌浆鍖栦负浜岃繘鍒堕兘鏄棤闄愮殑 --- 鎵�浠ヨ绠楁満鍦ㄥ瓨鍌ㄥ皬鏁扮殑鏃跺�欎細浜х敓鑸嶅叆璇樊

鍙橀噺

鍦ㄧ▼搴忎腑鐢ㄤ簬瀛樺偍鏁版嵁鐨勫鍣ㄣ��

鍙橀噺涓嶈兘閲嶅悕銆�

鍙橀噺蹇呴』鍏堝畾涔夊悗浣跨敤

鍙橀噺蹇呴』鍏堢粰鍊煎悗浣跨敤

鍙橀噺蹇呴』鍦ㄥ摢鍎垮畾涔夊氨鍦ㄥ摢鍎夸娇鐢�

鎵╁睍锛氳绠楁満瀛樺偍鍗曚綅

姣忎竴涓簩杩涘埗鏁板瓧绉颁箣涓�1浣� --- bit - b

瀛楄妭- Byte - B聽 1B = 8b

鍗冨瓧鑺� - kilobyte - KB 1KB = 210B = 1024B

鍏嗗瓧鑺� - MB -> GB -> TB -> PB

8Mb = 1MB

100Mb = 12.5MB

3GB = 3000MB --- 鍦ㄩ�氫俊棰嗗煙鏄寜鐓у崈杩涘埗璁$畻

鏁版嵁绫诲瀷

鍩烘湰鏁版嵁绫诲瀷

鏁板�煎瀷

鏁存暟鍨�

byte - 瀛楄妭鍨�-聽 1涓瓧鑺� - -27~27-1 -> -128~127

byte b = 25; byte b2 = 127; byte b3 = -128;

short - 鐭暣鍨� - 2涓瓧鑺� - -215~215-1 -> -32768~32767

short s = 800; short s2 = 1500;

int - 鏁村瀷 - 4涓瓧鑺� - -231~231-1 -> -2.1*109~2.1*109 - Java涓紝鏁存暟榛樿涓篿nt绫诲瀷

int i = 5;聽

long - 闀挎暣鍨� - 8涓瓧鑺� - -263~263-1 -> -1018~1018 闇�瑕佷互L/l浣滀负缁撳熬鏍囪

long l = 54L;

娴偣鍨�

float - 鍗曠簿搴� - 4涓瓧鑺� -> -1038~1038 - 闇�瑕佷互f/F浣滀负缁撳熬

double - 鍙岀簿搴� - 8涓瓧鑺� -> -10308~10308 Java涓皬鏁伴粯璁や负double绫诲瀷 - 灏忔暟缁撳熬鍙互娣诲姞D/d浣滀负鏍囪

double d = 4.5; double d2 = 2.58; double d3 = 9.54D;

char - 瀛楃鍨� - 2涓瓧鑺� -> 0~65535 - 瀛樺偍鐢ㄧ殑灏辨槸utf-16聽

char c = 鈥榓鈥�; char c2 = '\ua4f3'; char c3 = 鈥樹腑鈥�;

杞箟瀛楃

\t-鍒惰〃绗� table \r-鍥炶溅 return \n-鎹㈣next聽

\\-鍙嶆枩鏉燶聽 \鈥�-鍗曞紩鍙仿� \鈥�-鍙屽紩鍙�

鎵╁睍锛氬皢瀛楃杞崲鏁板瓧鐨勮繃绋嬬О涔嬩负缂栫爜 --- 缂栫爜琛�

ISO-8859-1 - 瑗挎鐮佽〃 - 1涓瓧鑺傝〃绀�1涓瓧绗� a

gb2312 - 鍥芥爣鐮� - gbk - 2涓瓧鑺傝〃绀�1涓瓧绗� - 鏀跺綍浜嗗父瑙佺殑绠�浣撴眽瀛椾互鍙婁竴閮ㄥ垎甯歌鐨勭箒浣撴眽瀛�

Unicode缂栫爜浣撶郴 - 鏀跺綍浜嗕笘鐣屼笂甯歌璇█鐨勫熀鏈瓧绗� - 瑙勫畾浜嗕竴绯诲垪鐨勭紪鐮佽鍒� - utf-8-> 3涓瓧鑺傝〃绀轰竴涓瓧绗� utf-16 -> 2涓瓧鑺傝〃绀�1涓瓧绗�

娉ㄦ剰锛氳瀹氭棤璁哄摢寮犵爜琛ㄥ吋瀹硅タ娆х爜琛�

k 1 1 1 1

鍖� X 2 3 2

boolean - 甯冨皵鍨� - true/false锛岀敤浜庤〃绀洪�昏緫鍊�

boolean b = true; boolean b2 = false;

寮曠敤鏁版嵁绫诲瀷

鏁扮粍[]聽

绫� class

鎺ュ彛interface聽

鏁版嵁绫诲瀷鐨勮浆鎹�

鑷姩绫诲瀷杞崲/闅愬紡杞崲

byte b = 125;

int i = b;

瑙勫緥涓�锛氬皬鐨勭被鍨嬭嚜鍔ㄨ浆鍖栦负澶х殑绫诲瀷

short s = 7;

long l = s;

long l = 500; // 500鏄竴涓暣鏁帮紝鏁存暟榛樿涓篿nt锛宨nt鐨勮寖鍥存瘮long灏忥紝鎵�浠ュ彲浠ヨ嚜鍔ㄨ浆鎹�

float f = 56.71F;

double d = f;

int i = 300;

double d = i;

瑙勫緥浜岋細鏁存暟绫诲瀷鍙互鑷姩杞寲涓烘诞鐐圭被鍨嬶紝鍙兘浼氫骇鐢熻垗鍏ヨ宸�

int i = 500;

float f = i; // i鏄痠nt绫诲瀷锛宨nt鐨勫彇鍊艰寖鍥存瘮float灏忥紝鎵�浠nt鍙互鑷姩杞寲涓篺loat

long l = 259L;

float f = l;

float f = -25; // -25鏄暣鏁�

char c = 鈥榓鈥�;

int i = c;

瑙勫緥涓夛細瀛楃鍙互鑷姩鎻愬崌涓烘暣鏁�

寮哄埗绫诲瀷杞崲/鏄惧紡杞崲

int i = 35;

byte b = (byte)i;

瑙勫緥涓�锛氬綋鎶婂ぇ鐨勭被鍨嬭浆鍖栦负灏忕殑绫诲瀷鐨勬椂鍊欙紝鍥犱负琛ョ爜鐨勬崲绠楅棶棰橈紝鎵�浠ュ彲鑳戒細浜х敓涓�浜涙兂涓嶅埌鏁版嵁

double d = 6.4;

int i = (int)d;

瑙勫緥浜岋細灏忔暟鍦ㄨ浆鍖栦负鏁存暟鐨勬椂鍊欐槸鑸嶅純灏忔暟浣�

鎵╁睍锛氭暟鎹殑鍘熷弽琛ヤ笁鐮�

鏁版嵁绫诲瀷鐨勬渶楂樹綅鏄鍙蜂綅 --- 濡傛灉鏈�楂樹綅鏄�0锛屽垯琛ㄧず涓�涓鏁帮紱濡傛灉鏈�楂樹綅鏄�1锛屽垯琛ㄧず涓�涓礋鏁般��

璁$畻鏈轰腑瀛樺偍鐨勬槸鏁版嵁鐨勮ˉ鐮侊紝璁$畻鐨勪篃鏄暟鎹殑琛ョ爜

鐩存帴璁$畻鍑烘潵鐨勪簩杩涘埗鏁板瓧鏄暟鎹殑鍘熺爜

濡傛灉鏄鏁帮紝閭d箞鍘熷弽琛ヤ笁鐮佷竴鑷�

int i = 7;

00000000 00000000 00000000 00000111 鍘熺爜

00000000 00000000 00000000 00000111 鍙嶇爜

00000000 00000000 00000000 00000111 琛ョ爜

濡傛灉鏄礋鏁帮紝閭d箞鍙嶇爜鏄湪鍘熺爜鐨勫熀纭�涓婏紝鏈�楂樹綅涓嶅彉锛屽叾浣欎綅0<->1锛涜ˉ鐮佹槸鍦ㄥ弽鐮佺殑鍩虹涓�+1

int j = -9;

10000000 00000000 00000000 00001001 鍘熺爜

11111111 11111111 11111111 11110110 鍙嶇爜

11111111 11111111 11111111 11110111 琛ョ爜聽

娉ㄦ剰锛氳瀹氱敤-0琛ㄧず褰撳墠绫诲瀷鐨勬渶灏忓��

杩愮畻绗�

绠楁湳杩愮畻绗�

+ - * / % ++ --

娉ㄦ剰锛�

1. byte/short/char鍦ㄨ繍绠楃殑鏃跺�欒嚜鍔ㄦ彁鍗囦负int

2. 鏁村瀷鍦ㄨ繍绠楃殑鏃跺�欎繚鎸佺被鍨嬩笉鍙�

3. 灏忕被鍨嬪拰澶х被鍨嬭繍绠楋紝缁撴灉涓�瀹氭槸澶х被鍨�

4. 浠绘剰鏁存暟/0 - ArithmeticException - 绠楁湳寮傚父

聽聽 浠绘剰闈為浂鏁板瓧/0.0 浠绘剰闈為浂灏忔暟/0 - Infinity - 鏃犵┓澶�

0/0.0 0.0/0.0 0.0/0 - NaN - Not a Number - 闈炴暟瀛�

DAY 03

澶嶄範锛�

1. 娉ㄩ噴锛氭槸绋嬪簭涓敤浜庤В閲婅鏄庣殑鏂囧瓧 - 鏂囨。娉ㄩ噴涓殑鏂囧瓧鍙互鍒╃敤javadoc鍛戒护杩涜鎻愬彇

2. 瀛楅潰閲忥細鏁存暟銆佸皬鏁般�佸瓧绗︺�佸瓧绗︿覆銆佸竷灏斻�佺┖

3. 杩涘埗锛氬疄闄呬笂鏄竴绉嶈鏁版柟寮忋��

浜岃繘鍒讹細0-1锛屾弧2杩�1锛岄渶瑕佷互0b寮�澶达紙浠嶫DK1.7寮�濮嬶級

鍏繘鍒讹細0-7锛屾弧8杩�1锛岄渶瑕佷互0寮�澶�

鍗佽繘鍒讹細0-9锛屾弧鍗佽繘1锛岀▼搴忎腑榛樿灏辨槸鍗佽繘鍒�

鍗佸叚杩涘埗锛�0-9锛宎-f锛屾弧16杩�1锛岄渶瑕佷互0x寮�澶�

娉ㄦ剰杩涘埗涔嬮棿鐨勮浆鎹㈣鍒�

4. 鍙橀噺锛氭暟鎹被鍨� 鍙橀噺鍚� = 鏁版嵁; - 鍙橀噺蹇呴』鍦ㄥ畾涔夌殑鑼冨洿鍐呬娇鐢紱鍙橀噺蹇呴』鍏堝畾涔夊悗浣跨敤锛屼篃蹇呴』鍏堢粰鍊煎悗浣跨敤

5. 鏁版嵁绫诲瀷锛�

鍩烘湰鏁版嵁绫诲瀷

byte short int long float double char boolean

byte鐨勫彇鍊艰寖鍥达細-128~127

鏁存暟榛樿涓篿nt锛屽皬鏁伴粯璁や负double

long绫诲瀷闇�瑕佷互l/L浣滀负缁撳熬

float绫诲瀷闇�瑕佷互F/f浣滀负缁撳熬

char绫诲瀷鐨勯粯璁ょ紪鐮佹槸utf-16 - 2涓瓧鑺�

boolean鐢ㄤ簬琛ㄧず閫昏緫鍊�

寮曠敤鏁版嵁绫诲瀷

鏁版嵁[] 绫籧lass 鎺ュ彛interface

6. 鏁版嵁绫诲瀷鐨勮浆鎹�

闅愬紡杞崲

灏忕被鍨嬪彲浠ヨ嚜鍔ㄨ浆鍖栦负澶х被鍨�

鏁存暟鍙互鑷姩杞寲涓哄皬鏁帮紝鍙兘浼氫骇鐢熺簿搴︽崯澶�

瀛楃鍙互鑷姩杞寲涓烘暣鏁�

鏄惧紡杞崲

澶х被鍨嬭浆鎹负灏忕被鍨嬶紝鍥犱负瀛楄妭鐨勬崯澶卞彲鑳藉鑷存暟鎹笉绮剧‘

灏忔暟杞崲涓烘暣鏁扮殑鏃跺�欓渶瑕佽垗寮冨皬鏁颁綅

杩愮畻绗�

绠楁湳杩愮畻绗�

+ - * / % ++ --

娉ㄦ剰锛�

1. byte/short/char鍦ㄨ繍绠楃殑鏃跺�欎細鑷姩鎻愬崌涓篿nt

2. 鏁存暟鐨勮繍绠楃粨鏋滀竴瀹氭槸鏁存暟

3. 灏忕被鍨嬪拰澶х被鍨嬭繍绠楃粨鏋滀竴瀹氭槸澶х被鍨�

4. 浠绘剰鏁存暟/0 - ArithmeticException

闈為浂鏁板瓧/0.0 闈為浂灏忔暟/0 - Infinity

0.0/0.0 0.0/0 0/0.0 - NaN - 闈炴暟瀛�

% 鍙栨ā杩愮畻 - 鍙栦綑杩愮畻

9%4=1 3%8=3

-9%4=-1 9%-4=1 -9%-4=-1

%鐨勭粨鏋滅殑姝h礋鐪嬬殑鏄�%宸﹁竟鏁版嵁鐨勬璐� -> 濡傛灉宸﹁竟鐨勬暟瀛楁槸涓�涓鏁帮紝閭d箞缁撴灉灏辨槸姝f暟锛涘弽涔嬶紝閭d箞缁撴灉灏辨槸璐熸暟

5%1.4=0.8 6.3%1.7=1.2聽

++/-- 鑷/鑷噺杩愮畻

++/--濡傛灉鍦ㄥ彉閲忎箣鍓嶏紝閭d箞鍏堣嚜澧�/鑷噺锛岀劧鍚庡弬涓庡悗缁繍绠�

++/--濡傛灉鍦ㄥ彉閲忎箣鍚庯紝閭d箞鍏堝皢鍊煎彇鍑烘潵鍙備笌杩愮畻锛岀劧鍚庡彉閲忓啀鑷/鑷噺

int i = 6;

// int j = i++ + ++i; -> 14

int j = ++i + i++; -> 14

byte/short/char閮藉彲浠ュ弬涓庤嚜澧炶繍绠�

char c = 鈥榖鈥�;

int i = c + 2; -> 100

鈥榓鈥� ~ 鈥榸鈥� -> 97~122 鈥楢鈥� ~ 鈥榋鈥� -> 65~90 鈥�0鈥� ~ 鈥�9鈥� -> 48~57

char c = 鈥�0鈥�;

int i = c + 3; -> 51

璧嬪�艰繍绠楃

= += -= *= /= %= &= |= ^= <<= >>= >>>=

byte/short/char鍙互鍙備笌璧嬪�艰繍绠�

闄や簡=浠ュ锛屽叾浣欑殑绗﹀彿閮借姹傝繖涓彉閲忓緱鍏堟湁鍊�

娉ㄦ剰:鍦↗ava涓笉鏀寔杩炵瓑瀹氫箟浣嗘槸鏀寔杩炵瓑璧嬪��

int i = 5;

i += i *= i -= 3; -> 15

i = 5 + (5 * (5 - 3));

int j = 7;

j -= j *= j++; -> -42

j = 7 - (7 * 7);

鍏崇郴/姣旇緝杩愮畻绗�

==鐩哥瓑 !=涓嶇瓑 > < >= <=

娉ㄦ剰锛氫笉鏀寔杩炵潃鐨勬瘮杈冩柟寮�

閫昏緫杩愮畻绗�

娉ㄦ剰锛氶�昏緫杩愮畻绗︾畻鐨勬槸閫昏緫鍊�

&涓� |鎴� !闈� ^寮傛垨 &&鐭矾涓� ||鐭矾鎴�

true&true=true true&false=false false&true=false聽

false&false=false

true|true=true true|false=true false|true=true

false|false=false

!true=false !false=true

true^true=false true^false=true false^true=true

false^false=false

&&锛氬鏋滃墠杈圭殑琛ㄨ揪寮忕殑缁撴灉涓篺alse锛屽垯鍚庤竟鐨勮〃杈惧紡涓嶅啀杩愮畻锛屾暣涓〃杈惧紡鐨勭粨鏋滃氨纭畾涓篺alse

||锛氬鏋滃墠杈圭殑琛ㄨ揪寮忕殑缁撴灉涓簍rue锛屽垯鍚庤竟鐨勮〃杈惧紡灏变笉鍐嶈繍绠楋紝鏁翠釜琛ㄨ揪寮忕殑缁撴灉灏辩‘瀹氫负true

娉ㄦ剰锛殀|濡傛灉鍦�&&鐨勫墠杈瑰彲浠ユ妸&&鐭矾鎺�

浣嶈繍绠楃

娉ㄦ剰锛氫綅杩愮畻绗﹂拡瀵规暣鏁扮殑琛ョ爜杩涜杩愮畻锛屾墍浠ヨ繍绠楃粨鏋滀篃鏄ˉ鐮�

& | ^ << >> >>> ~鍙栧弽

浜ゆ崲鍊肩殑鏂瑰紡

鏂瑰紡涓�锛氬紓鎴栨硶

int i = 5, j = 9;

i = i ^ j;

j = i ^ j; -> j = i ^ j ^ j; -> j = i;

i = i ^ j; -> i = i ^ j ^ i; -> i = j;

鏂瑰紡浜岋細鍔犲噺娉�

int i =5, j = 9;

i = i + j;

j = i - j; -> j = i + j - j; -> j = i;

i = i - j; -> i = i + j - i; -> i = j;

鏂瑰紡涓夛細杩藉熬娉�

int i = 5, j = 9;

int temp = i;

i = j;

j = temp;

鎬荤粨锛氫笁绉嶆柟寮忕殑姣旇緝

寮傛垨娉曠殑鏁堢巼鏄渶楂樼殑銆傚彧鑳介拡瀵规暣鏁拌繘琛屼氦鎹紝灞�闄愭�уお澶�

鍔犲噺娉曠殑鏁堢巼鏄綆浜庡紓鎴栦絾鏄珮浜庤拷灏俱�傜悊璁轰笂鍙互浜ゆ崲鏁板�肩被鍨嬶紝浣嗗疄闄呬笂寰堝皯鐢ㄤ簬浜ゆ崲灏忔暟

杩藉熬娉曠殑鏁堢巼鏄渶浣庣殑銆傚彲浠ヤ氦鎹换鎰忎竴涓被鍨嬬殑鍊�

涓夊厓杩愮畻绗�

鏍煎紡锛氶�昏緫鍊� ? 琛ㄨ揪寮�1 : 琛ㄨ揪寮�2

鎵ц椤哄簭锛氬厛鎵ц閫昏緫鍊硷紝濡傛灉閫昏緫鍊间负true锛屽垯鎵ц琛ㄨ揪寮�1锛涘弽涔嬪垯鎵ц琛ㄨ揪寮�2

涓夊厓琛ㄨ揪寮忔湰韬槸涓�涓〃杈惧紡锛屾剰鍛崇潃杩欎釜琛ㄨ揪寮忔墽琛屽畬鎴愪箣鍚庨渶瑕佹湁涓�涓粨鏋� --- 杩欎釜缁撴灉蹇呴』鑳藉畾涔夊搴旂被鍨嬬殑鍙橀噺鏉ユ帴浣�

a > b ? 鈥渁bc鈥� : true; -> 娌℃湁鍔炴硶瀹氫箟涓�涓粺涓�绫诲瀷鐨勭粨鏋滄潵瀛樺偍锛岃繖绉嶅啓娉曞氨鏄敊璇殑

double d = a > b ? 3 : 5.25;

float f = a > b ? 鈥榓鈥� : 3.5f;

缁冧範锛� 杈撳嚭鍒嗘暟瀵瑰簲鐨勭瓑绾� >=90-A >=80-B >=70-C >=60-D <60-E

鎵╁睍锛氫粠鎺у埗鍙拌幏鍙栨暟鎹�

import java.util.Scanner;

Scanner s = new Scanner(System.in);

int i = s.nextInt(); // 鑾峰彇鏁存暟

double d = s.nextDouble(); // 鑾峰彇灏忔暟

String str = s.next(); // 鑾峰彇瀛楃涓�

杩愮畻绗︾殑浼樺厛绾�

~ ! ++ -- * / % + - << >> >>> 鍏崇郴 閫昏緫 & | ^ 涓夊厓 璧嬪��

涓�鍏� > 浜屽厓 > 涓夊厓 > 璧嬪��(绋嬪簭鐨勮繍琛岄『搴忔槸浠庝笂鍒颁笅锛屼粠宸﹀埌鍙筹紝涓�瀹氳娉ㄦ剰杩愮畻绗︾殑浼樺厛绾�)

娴佺▼鎺у埗

椤哄簭缁撴瀯锛氭寚浠g爜鏄粠涓婂埌涓嬩粠宸﹀埌鍙虫潵渚濇缂栬瘧杩愯鐨�

鍒嗘敮缁撴瀯

鍒ゆ柇缁撴瀯

if(閫昏緫鍊�){

浠g爜鍧�;

}

鎵ц椤哄簭锛氬厛鎵ц閫昏緫鍊硷紝濡傛灉閫昏緫鍊间负true锛屽垯鎵ц浠g爜鍧楋紱鍙嶄箣鍒欎笉鎵ц

娉ㄦ剰锛氬鏋渋f涓殑浠g爜鍧楀彧鏈�1鍙ヨ瘽锛岄偅涔堝彲浠ョ渷鐣}涓嶅啓

if(閫昏緫鍊�){

Code1;

} else {

Code2;

}

鎵ц椤哄簭锛氬厛鎵ц閫昏緫鍊硷紝濡傛灉閫昏緫鍊间负true锛岄偅涔堟墽琛孋ode1锛涘弽涔嬫墽琛孋ode2

缁冧範锛�

1. 杈撳叆涓変釜鏁板瓧锛岃幏鍙栦笁涓暟瀛椾腑鐨勬渶灏忓��

2. 杈撳叆涓�涓暟瀛楄〃绀洪噸閲忥紝濡傛灉閲嶉噺<=20锛屽垯姣忓崈鍏嬫敹璐�0.35鍏冿紱濡傛灉瓒呰繃20鍗冨厠涓嶈秴杩�100鍗冨厠鐨勮寖鍥达紝鍒欒秴杩囩殑閮ㄥ垎鎸夌収姣忓崈鍏�0.5鍏冩敹璐癸紱濡傛灉瓒呰繃100鍗冨厠锛屽垯瓒呰繃鐨勮寖鍥存寜鐓ф瘡鍗冨厠0.8鍏冩敹璐广�傝绠楄緭鍏ョ殑閲嶉噺瀵瑰簲鐨勬�昏垂鐢�

if(閫昏緫鍊�1){

Code1;

} else if(閫昏緫鍊�2){]

Code2;

}

...

else {

Code;

}

鎵ц椤哄簭锛氬厛鎵ц閫昏緫鍊�1锛屽鏋滈�昏緫鍊�1涓簍rue锛屽垯鎵цCode1锛涘弽涔嬪垯鎵ц閫昏緫鍊�2锛屽鏋滈�昏緫鍊�2涓簍rue锛屽垯鎵цCode2锛涘弽涔嬪垯椤烘缁х画寰�涓嬫墽琛�

缁冧範锛�

杈撳叆涓�涓暟瀛楄〃绀烘湀浠斤紝鐒跺悗杈撳嚭杩欎釜鏈堜唤鎵�瀵瑰簲鐨勫鑺傘��3-5-鏄� 6-8-澶� 9-11-绉� 12銆�1銆�2-鍐�

Day04

澶嶄範锛�

1. 杩愮畻绗�

绠楁湳锛�

% - 鍙栦綑 - 娉ㄦ剰缁撴灉鐨勬璐熷彿

++/--鍦ㄥ彉閲忎箣鍓嶉渶瑕佸厛鑷鍚庤繍绠楋紱鍦ㄥ彉閲忎箣鍚庡厛杩愮畻鍚庤嚜澧烇紱byte/short/char鍙備笌杩愮畻

璧嬪�硷細

闄や簡=锛屽叾浠栫殑绗﹀彿閮借姹傚彉閲忓厛鏈夊�兼墠鑳戒娇鐢�

byte/short/char鍙互鍙備笌璧嬪�艰繍绠�

涓嶅厑璁歌繛绛夊畾涔変絾鏄厑璁歌繛绛夎祴鍊�

姣旇緝锛�

涓嶅厑璁哥敤姣旇緝杩愮畻绗﹁〃绀轰竴涓繛缁殑鑼冨洿 --- 3 < n < 5

閫昏緫锛�

^锛氱浉鍚屼负鍋囦笉鍚屼负鐪�

&&鍜寍|鐨勭煭璺壒鎬�

浣嶏細

閽堝鏁存暟鐨勮ˉ鐮佽繘琛岃繍绠�

浜ゆ崲鍊肩殑鏂瑰紡锛氳拷灏炬硶銆佸姞鍑忔硶銆佸紓鎴栨硶

涓夊厓锛�

鎵ц椤哄簭锛氬厛鎵ц閫昏緫鍊硷紝濡傛灉閫昏緫鍊间负true鍒欐墽琛岃〃杈惧紡1锛涘弽涔嬫墽琛岃〃杈惧紡2

涓夊厓琛ㄨ揪寮忎腑鐨勪袱涓紡瀛愮殑缁撴灉绫诲瀷蹇呴』鑳藉杞寲

娴佺▼鎺у埗

椤哄簭缁撴瀯锛氭寚浠g爜浠庝笂鍒颁笅浠庡乏鍒板彸渚濇缂栬瘧杩愯

鍒嗘敮缁撴瀯

鍒ゆ柇缁撴瀯

if(){}

if(){}else {}

if(){}else if(){}

缁冧範锛氳緭鍏ヤ竴涓暟瀛楋紝鐒跺悗杈撳嚭杩欎釜鏁板瓧琛ㄧず鏄熸湡鍑�

3 -> 鏄熸湡涓�

閫夋嫨缁撴瀯

switch(閫夋嫨){

case 閫夐」1:Code1;break;

case 閫夐」2:Code2;break;

...

}

switch()涓渶瑕佷竴涓�夐」锛岄�夐」鍙兘鏄痓yte/short/char/int锛屼粠JDK1.7寮�濮嬶紝鍏佽浣跨敤String

濡傛灉姣忎竴涓猚ase涔嬪悗閮芥湁break锛宑ase椤哄簭涓嶅奖鍝嶇粨鏋�

濡傛灉鏈変竴涓垨鑰呭涓猚ase涔嬪悗娌℃湁break锛岄偅涔堣繖涓椂鍊檆ase涔嬮棿鐨勯『搴忓奖鍝嶇粨鏋�

缁冧範锛氳緭鍏ヤ袱涓暟瀛椾互鍙婁竴涓鍙凤紝杈撳嚭杩欎袱涓暟瀛楀湪杩欎釜绗﹀彿涓嬭繍绠椾骇鐢熺殑缁撴灉

5 9 + -> 14

switch(){

case 鈥�+鈥�:...

case 鈥�-鈥�:...

}

缁冧範锛氳緭鍏ヤ笁涓暟瀛楄〃绀哄勾鏈堟棩锛岃緭鍑鸿繖涓�澶╁湪杩欎竴骞存槸绗嚑澶�

2012 3 5 ---> 65

2014 3 5 ---> 64

闇�瑕佸垽鏂钩骞撮棸骞达細閫㈢櫨鏁撮櫎400锛涗笉閫㈢櫨鏁撮櫎4

2012 % 4 == 0 --- true

2100 % 400 == 0 --- false聽

寰幆缁撴瀯

鐢ㄤ簬瀹屾垚涓�浜涚浉鍚屾垨鑰呯浉浼肩殑閲嶅鐨勬搷浣�

while(閫昏緫鍊�){

Code锛�

}

鎵ц椤哄簭锛�

缁冧範锛�

1. 姹�1-100浠ュ唴鎵�鏈夌殑濂囨暟鐨勫拰 --- i = 1; i += 2;

2. 鎵撳嵃100浠ュ唴鑳借3鏁撮櫎鑰屼笉鑳借7鏁撮櫎鐨勬暟瀛� --- 鍏堣幏鍙�3鐨勫�嶆暟聽 int i = 0; i += 3;

3. 杈撳叆涓�涓暟瀛楋紝杈撳嚭杩欎釜鏁板瓧鏄竴涓嚑浣嶆暟

4. 杈撳叆涓�涓暟瀛楋紝杈撳嚭杩欎釜鏁板瓧鐨勬墍鏈夌殑鍥犳暟 --- 浠�1寮�濮嬶紝閫愪釜鏁板瓧鍙栦綑杩欎釜杈撳叆鐨勬暟瀛楋紝鐪嬫槸鍚﹁兘澶熸暣闄�

20锛�1 2 4 5 10 20

瀹氫箟涓�涓惊鐜紝闇�瑕佷笁涓绱狅細瀹氫箟涓�涓彉閲忔潵鎺у埗娆℃暟锛屽埄鐢ㄥ垽鏂潯浠跺喅瀹氬惊鐜粨鏉燂紱鍦ㄥ惊鐜繃绋嬩腑闇�瑕佹敼鍙樺彉閲�

do{

Code;

} while(閫昏緫鍊�);

娉ㄦ剰锛氭棤璁烘潯浠舵槸鍚︽弧瓒筹紝do-while鐨勫惊鐜綋蹇呯劧鑷冲皯鎵ц涓�娆°��

for(瀹氫箟寰幆鍙橀噺; 鎺у埗鏉′欢; 鏀瑰彉寰幆鍙橀噺){

Code;

}

涔犳儻涓婂鏋滃彉鍖栦笉瑙勫緥鎴栬�呮鏁颁笉纭畾涓�鑸娇鐢╳hile寰幆锛涘鏋滃彉鍖栬寰嬫垨鑰呮槸娆℃暟鍥哄畾锛屼竴鑸槸鐢╢or寰幆

姹�1-10鐨勫拰 --- for寰幆

int sum = 0;

for(int i = 1; i <= 10; i++){

sum += i;

}

浠庢帶鍒跺彴鑾峰彇涓�涓ぇ浜�10鐨勫鏁�

Scanner s = new Scanner(System.in);

int n = s.nextInt();

// 浣跨敤while寰幆

while(n < 10 || n % 2 == 0){

n = s.nextInt();

}

// 浣跨敤for寰幆

for(; n < 10 || n % 2 == 0; n = s.nextInt()){

}

缁冧範锛氭墦鍗颁節涔濅箻娉曡〃

1*1=1

1*2=2 2*2=4

1*3=3 2*3=6 3*3=9

銆傘�傘��

缁冧範锛�

鐧鹃挶鐧鹃浮 --- 3鏂囬挶1鍙叕楦★紝2鏂囬挶1鍙瘝楦★紝1鏂囬挶3鍙皬楦★紱100鏂囬挶濡備綍涔版伆濂�100鍙浮锛� --- 鍏堝畾涔変竴涓惊鐜〃绀哄叕楦★紝宓屽涓�涓惊鐜〃绀烘瘝楦★紝璁$畻灏忛浮鐨勪釜鏁帮紝鏍规嵁鍚勭楦$殑涓暟鏉ヨ绠楅挶鏁版槸鍚︿负100

break鍜宑ontinue

break锛氱敤浜庨�夋嫨缁撴瀯鍜屽惊鐜粨鏋勶紝琛ㄧず缁撴潫褰撳墠鐨勪竴灞傜粨鏋�

continue锛氬彧鑳界敤浜庡惊鐜粨鏋勶紝琛ㄧず璺宠繃鏈寰幆缁х画涓嬫寰幆锛堝彧鑳借烦杩囦竴灞傚惊鐜級

鎵╁睍浣滀笟锛氫竴涓惊鐜墦鍗颁節涔濅箻娉曡〃

鏁扮粍

瀛樺偍鍚屼竴绫诲瀷鐨勫涓暟鎹殑瀹瑰櫒---澶у皬鏄浐瀹氱殑

鏁扮粍浼氬鏀惧叆鍏朵腑鐨勬暟鎹紙鍏冪礌锛夎繘琛岀紪鍙凤紝缂栧彿鏄粠0寮�濮嬬殑 - 涓嬫爣

鏁扮粍鐨勫閲� --- 闀垮害

瀹氫箟鏍煎紡

鏁版嵁绫诲瀷[] 鏁扮粍鍚� = new 鏁版嵁绫诲瀷[闀垮害];

int[] arr = new int[5]; --- 琛ㄧず瀹氫箟涓�涓兘瀛樺偍5涓暣鍨嬪厓绱犵殑鏁扮粍

arr[3] = 10;

鍐呭瓨

Java灏嗘墍鍗犵敤鐨勫唴瀛樺垝鍒嗕负浜�5鍧楋細鏍堝唴瀛樸�佸爢鍐呭瓨銆佹柟娉曞尯銆佹湰鍦版柟娉曟爤銆丳C璁℃暟鍣紙瀵勫瓨鍣級

鏍堝唴瀛�

鐢ㄤ簬瀛樺偍鍙橀噺鐨勩�傚彉閲忓湪鏍堝唴瀛樹娇鐢ㄥ畬鎴愪箣鍚庝細绔嬪嵆绉婚櫎鍑烘爤鍐呭瓨銆�

鍫嗗唴瀛�

鐢ㄤ簬瀛樺偍瀵硅薄锛堟暟缁勬槸涓�绉嶇壒娈婄殑瀵硅薄锛夌殑銆傚厓绱犲湪瀛樺叆鍫嗗唴瀛樹腑涔嬪悗浼氳嚜鍔ㄧ殑璧嬩簣榛樿鍊硷細byte/short/int-0 long-0L float-0.0f double-0.0 char-鈥榎u0000鈥� boolean-false锛屽叾浠栫被鍨嬬殑榛樿鍊奸兘鏄痭ull銆傚璞″湪鐢ㄥ畬涔嬪悗鏄湪涓嶇‘瀹氱殑鏌愪釜鏃跺埢琚洖鏀躲��

logab = logcb/logca聽 logabn = nlogab logab = loga + logb

DAY05

澶嶄範锛�

1. 娴佺▼鎺у埗

椤哄簭缁撴瀯

鍒嗘敮缁撴瀯锛�

鍒ゆ柇缁撴瀯锛歩f, if-else, if-else if

閫夋嫨缁撴瀯锛歴witch-case --- 閫夐」鐨勭被鍨嬪彲浠ユ槸byte/ short/ char/ int, 浠嶫DK1.7寮�濮嬶紝鍏佽浣跨敤String銆俢ase涔嬪悗鏈夋棤break锛岄偅涔堜粬鐨勯『搴忓皢浼氬奖鍝嶇粨鏋�

寰幆缁撴瀯锛歸hile, do-while, for

do-while鐨勫惊鐜綋鏃犺濡備綍閮戒細鑷冲皯鎵ц涓�娆°��

鍦ㄦ鏁板浐瀹氭垨鑰呮槸鍙樺寲瑙勫緥鐨勫墠鎻愪笅锛屽缓璁娇鐢╢or寰幆锛涘湪娆℃暟涓嶅浐瀹氭垨鑰呭彉鍖栦笉瑙勫緥鐨勬儏鍐典笅锛屽缓璁娇鐢╳hile寰幆

寰幆宓屽

break鍜宑ontinue

break锛氱敤浜庨�夋嫨鍜屽惊鐜粨鏋勶紝琛ㄧず缁堟褰撳墠鐨勪竴灞傜粨鏋勩��

continue锛氱敤浜庡惊鐜粨鏋勶紝琛ㄧず璺冲嚭褰撳墠鐨勪竴娆″惊鐜户缁笅娆″惊鐜紙涔熸槸鍙兘璺充竴灞傦級

鏁扮粍

鐢ㄤ簬瀛樺偍澶氫釜鍚屼竴绫诲瀷鐨勬暟鎹殑瀹瑰櫒 --- 澶у皬鏄浐瀹氱殑

涓嬫爣鏄粠0寮�濮嬶紝鎵�浠ユ渶澶т笅鏍囨槸闀垮害-1

瀹氫箟鏍煎紡

鏁版嵁绫诲瀷[] 鏁扮粍鍚� = new 鏁版嵁绫诲瀷[闀垮害];

鏁版嵁绫诲瀷[] 鏁扮粍鍚� = new 鏁版嵁绫诲瀷[]{鍏冪礌1, 鍏冪礌2, ...};--- 杩欑鏂瑰紡鍦ㄥ畾涔夌殑鏃跺�欑粰瀹氫簡鍏蜂綋鐨勫厓绱犲悓鏃朵篃瑙勫畾浜嗘暟缁勭殑闀垮害

int[] arr = new int[]{5,3,7,1,8,9,2}; 琛ㄧず瀹氫箟浜嗕竴涓厓绱犵被鍨嬩负鏁村瀷鐨勬暟缁勶紝鏁扮粍涓殑鍏冪礌鏄�5,3,7,1,8,9,2锛屾剰鍛崇潃鏁扮粍鐨勯暱搴︽槸7

鏁扮粍绫诲瀷[] 鏁扮粍鍚� = {鍏冪礌1, 鍏冪礌2, ...}; --- 涓嶅厑璁稿垎寮�瀹氫箟

鏁扮粍鐨勫唴瀛�

鏁扮粍瀛樺偍鍦ㄥ爢鍐呭瓨涓紝骞朵笖鍦ㄥ爢鍐呭瓨涓細鑷姩璧嬩簣榛樿鍊硷細byte/short/int - 0, long - 0L, float - 0.0f, double - 0.0, char - 鈥榎u0000鈥�, boolean - false锛屽叾浠栨墍鏈夌被鍨嬬殑榛樿鍊奸兘鏄痭ull

娉ㄦ剰锛氭暟缁勫湪璧嬪�肩殑鏃跺�欒祴鐨勫疄闄呬笂鏄湴鍧�

鏁扮粍鐨勫簲鐢�

1. 鎿嶄綔鎸囧畾浣嶇疆涓婄殑鍏冪礌锛氭暟缁勫悕[涓嬫爣]

2. 鑾峰彇鏁扮粍鐨勯暱搴︼細鏁扮粍鍚�.length

3. 閬嶅巻鏁扮粍

// 鏂瑰紡涓�锛氫笅鏍囨槸浠�0->length - 1

for(int i = 0; i < arr.length; i++){

System.out.println(arr[i]);

}

// 鏂瑰紡浜岋細鐩存帴鑾峰彇姣忎竴涓綅缃笂鐨勫厓绱�

// 澧炲己for寰幆

// 鍙兘閬嶅巻鏁扮粍浣嗘槸涓嶈兘鏀瑰彉鏁扮粍涓殑鍏冪礌

for(int i : arr){

System.out.println(i);

}

// 鏂瑰紡涓夛細灏嗘暟缁勪腑鐨勫厓绱犱竴涓釜鐨勬嬁鍑烘潵鎷兼帴鎴愬瓧绗︿覆

String str = Arrays.toString(arr);

System.out.println(str);

4. 鑾峰彇鏁扮粍涓渶鍊硷紙鏈�澶у��/鏈�灏忓�硷級

鏂瑰紡涓�锛氬畾涔夊彉閲忔潵璁板綍鏁扮粍涓殑鏈�澶у�硷紝鐒跺悗閬嶅巻鏁扮粍锛岃鏁扮粍涓殑鍏冪礌渚濇涓庢渶澶у�艰繘琛屾瘮杈冿紱濡傛灉澶т簬鏈�澶у�硷紝鍒欏皢鐢ㄨ繖涓厓绱犺鐩栧師鏉ョ殑鏈�澶у��

鏂瑰紡浜岋細瀹氫箟鍙橀噺鏉ヨ褰曟渶澶у�肩殑涓嬫爣

5. 鏁扮粍鐨勬帓搴�

鏃堕棿澶嶆潅搴︼細鍦ㄧ▼搴忎腑鎵句竴娈靛繀鐒朵細鎵ц鐨勪唬鐮侊紝灏嗚繖娈典唬鐮佺殑鎵ц鏃堕棿璁や负鏄崟浣�1锛屾墽琛岃繖涓崟浣�1闇�瑕佺殑娆℃暟灏辨槸鏃堕棿澶嶆潅搴� - 鏃堕棿澶嶆潅搴︿笉鑰冭檻绯绘暟锛屼竴鑸潵璇存槸鎵炬渶楂橀樁 -> O(nx), O((logn)x),O(nx(logn)y)

绌洪棿澶嶆潅搴︼細杩欐绋嬪簭鎵ц鎵�闇�瑕侀澶栬�楄垂鐨勭┖闂村氨鏄┖闂村鏉傚害

鎵╁睍锛氬啋娉℃帓搴忓拰閫夋嫨鎺掑簭閮芥槸绋冲畾鐨勬帓搴忕畻娉� --- 鎺掑簭绠楁硶鐨勭ǔ瀹氫笌鍚︾殑渚濇嵁鏄浉绛夌殑鍏冪礌鍦ㄦ帓搴忕殑鏃跺�欐槸鍚﹂渶瑕佷氦鎹�

6. 鍙嶈浆鏁扮粍锛氶灏句簰鎹� --- 鏃堕棿澶嶆潅搴(n)锛岀┖闂村鏉傚害o(1)

7. 鏁扮粍鍏冪礌鐨勬煡鎵撅細

鏁扮粍鍏冪礌鏃犲簭鐨勫墠鎻愪笅锛岃幏鍙栦竴涓厓绱犵殑浣嶇疆鍙兘閫氳繃閬嶅巻鐨勬柟寮忎竴涓�姣旇緝銆�

濡傛灉鏁扮粍鍏冪礌鏈夊簭锛屼娇鐢ㄤ簩鍒嗘煡鎵� --- 绌洪棿澶嶆潅搴(1)锛屾椂闂村鏉傚害O(logn)

2x = n -> x = log2n -> logn --- 榛樿浠�2涓哄簳鏁�

8. 鏁扮粍鐨勫鍒�

System.arraycopy(瑕佸鍒剁殑鏁扮粍, 瑕佸鍒剁殑璧峰涓嬫爣, 瀛樻斁鐨勬暟缁�, 瑕佸瓨鏀剧殑璧峰涓嬫爣, 涓暟);

浜岀淮鏁扮粍

瀛樺偍鐨勫厓绱犳槸涓�缁存暟缁� --- 瀛樺偍鏁扮粍鐨勬暟缁�

瀹氫箟鏍煎紡

鏁版嵁绫诲瀷[][] 鏁扮粍鍚� = new 鏁版嵁绫诲瀷[鍖呭惈鐨勪竴缁存暟缁勭殑涓暟][姣忎竴涓竴缁存暟缁勭殑闀垮害];

int[][] arr = new int[3][5]; 琛ㄧず瀹氫箟浜嗕竴涓兘瀛樺偍3涓暣鍨嬩竴缁存暟缁勭殑浜岀淮鏁扮粍锛屾瘡涓�涓竴缁存暟缁勮兘5涓暣鍨嬪厓绱�

鏁版嵁绫诲瀷[][] 鏁扮粍鍚� = new 鏁版嵁绫诲瀷[鍖呭惈鐨勪竴缁存暟缁勭殑涓暟][];

int[][] arr = new int[5][]; 瀹氫箟浜嗕竴涓兘瀛樺偍5涓暣鍨嬩竴缁存暟缁勭殑浜岀淮鏁扮粍 --- 蹇呴』鍏堜繚璇佽繖涓�浣嶄笂鐨勪竴缁存暟缁勫厛缁欏畾澶у皬锛岀劧鍚庡啀缁欏��

arr[0] = new int[3];

arr[1] = new int[7];

arr[2] = new int[2];

鏁版嵁绫诲瀷[][] 鏁扮粍鍚� = {{鏁扮粍1}, {鏁扮粍2}, {鏁扮粍3},...};

int[][] arr = {{2,4,1}, {4,7,2,9}, {3}, {5,0,6,7,4,3}}; --- 浜岀淮鏁扮粍鐨勫ぇ灏忎负4

娉ㄦ剰锛歔]濡傛灉鍦ㄥ彉閲忓悕涔嬪墠閭d箞绱ц窡鏁版嵁绫诲瀷锛屼篃灏辨剰鍛崇潃鍚庨潰瀹氫箟鐨勫彉閲忓疄闄呬笂閮芥槸鏁扮粍锛涗絾濡傛灉[]鍦ㄥ彉閲忓悕涔嬪悗锛岄偅涔圼]鍙璺熺潃鐨勮繖涓彉閲忎笉浼氬幓褰卞搷鍏朵粬鐨勫彉閲忋��

鍐呭瓨瀛樺偍

缁冧範锛氭潹杈変笁瑙�

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

鐗圭偣锛氭瘡涓�琛岀殑寮�濮嬪拰缁撴潫閮芥槸1锛涘叾浣欎綅缃殑鍏冪礌鏄绠楋細

arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];

杈撳叆涓�涓暟瀛梟琛ㄧず琛屾暟锛岃緭鍑哄搴旂殑鍓峮琛�

DAY06

澶嶄範锛�

1. 鏁扮粍

瀹氫箟鏍煎紡

鍐呭瓨瀛樺偍锛氭暟缁勬槸瀛樺偍鍦ㄥ爢鍐呭瓨涓紝鍦ㄦ爤鍐呭瓨涓瓨鍌ㄥ爢鍐呭瓨涓搴旂殑鍦板潃銆傛暟缁勫湪瀛樺叆鍫嗗唴瀛樼殑鏃跺�欓渶瑕佽嚜鍔ㄨ祴浜堥粯璁ゅ�笺��--- 鏁扮粍鍦ㄨ祴鍊肩殑鏃跺�欑粰鐨勪篃鏄湴鍧�

int[] arr1 = new int[3];

int[] arr2 = arr1; // 鎸囧悜鍚屼竴涓┖闂�

鏁扮粍搴旂敤锛�

鏁扮粍鐨勯亶鍘嗭細閫氳繃涓嬫爣閬嶅巻锛屽寮篺or寰幆

鍏冪礌鐨勬帓搴忥細鍐掓场鎺掑簭锛堢浉閭讳袱涓厓绱犱袱涓ゆ瘮杈冿級锛岄�夋嫨鎺掑簭锛堥�夊畾涓�涓厓绱犲拰鍏朵粬鍏冪礌鏉ヤ緷娆℃瘮杈冿級--- 鏃堕棿澶嶆潅搴(n2),绌洪棿澶嶆潅搴(1)锛屾槸绋冲畾鐨勬帓搴忕畻娉曪紱Arrays.sort鍙兘杩涜鍗囧簭鎺掑簭

鏁扮粍鐨勫弽杞細棣栧熬浜掓崲 - 鏃堕棿澶嶆潅搴(n),绌洪棿澶嶆潅搴(1)

鍏冪礌鐨勬煡鎵撅細鍏冪礌鏃犲簭锛屽惊鐜亶鍘嗭紱鍏冪礌鏈夊簭锛屼簩鍒嗘煡鎵� - 鏃堕棿澶嶆潅搴(logn)锛岀┖闂村鏉傚害o(1)

鏁扮粍鐨勫鍒讹細System.arraycopy - Arrays.copyOf

2. 浜岀淮鏁扮粍

鐢ㄤ簬瀛樺偍涓�缁存暟缁�

瀹氫箟鏍煎紡

鍐呭瓨瀛樺偍锛氫簩缁存暟缁勭殑姣忎竴涓綅缃笂瀛樺偍鐨勬槸瀵瑰簲鐨勪竴缁存暟缁勭殑鍦板潃锛涘鏋滄病鏈夋寚瀹氫竴缁存暟缁勭殑澶у皬锛岄偅涔堜簩缁存暟缁勭殑浣嶇疆涓婂瓨鍌ㄥ緱鏄痭ull

鏂规硶

褰撳湪绋嬪簭涓渶瑕侀噸澶嶄娇鐢ㄦ煇娈甸�昏緫鎴栬�呭姛鑳斤紝灏嗚繖娈甸�昏緫鎻愬彇鍑烘潵褰㈡垚涓�绉嶆柊鐨勫舰寮�---鏂规硶锛屼篃鍙嚱鏁�

瀹氫箟鏍煎紡

淇グ绗� 杩斿洖鍊肩被鍨� 鏂规硶鍚�(鍙傛暟鍒楄〃){

鏂规硶浣�;

return 杩斿洖鍊�;

}

// 鍐欎竴涓柟娉曟眰1-n鐨勫拰

// 鏄庣‘缁撴灉锛氭眰1-n鐨勫拰锛岄偅涔堝拰鏄竴涓暣鏁帮紝鎰忓懗鐫�缁撴灉鏄痠nt绫诲瀷锛屾墍浠ヨ繑鍥炲�肩被鍨嬩篃灏辨槸int绫诲瀷

// 鏄庣‘鏈煡閲忥細姹�1-n鐨勫拰锛宯鍦ㄦ柟娉曚腑涓嶈兘鑷姩浜х敓锛岄渶瑕佷娇鐢ㄦ柟娉曠殑浜烘潵浼犲叆涓�涓�硷紝杩欎釜鏃跺�欓渶瑕佷互鍙傛暟褰㈠紡鏉ヤ綋鐜�

// 瀹氫箟鏂规硶鐨勬椂鍊欏湪()涓畾涔変簡鍙傛暟 --- 褰㈠紡鍙傛暟 - 褰㈠弬聽

public static int sum(int n){

int sum = 0;

for(int i = 1; i <= n; i++){

sum += i;

}

return sum;

}

缁冧範锛�

1. 鍝ュ痉宸磋但鐚滄兂锛氫换浣曚竴涓ぇ浜庣瓑浜�6鐨勫伓鏁伴兘鍙互鍒嗚В鎴愪袱涓川鏁颁箣鍜屻��

16 = 3 + 13

16 = 5 + 11

杈撳叆澶т簬绛変簬6鐨勫伓鏁帮紝鐒跺悗杈撳嚭瀹冩墍鏈夌殑鍒嗚В褰㈠紡

鎬濊矾锛氬湪杩欎釜杩囩▼涓閲嶅鎵ц鐨勪唬鐮佹槸鍒ゆ柇璐ㄦ暟

2. 浜插瘑鏁帮細濡傛灉A鐨勬墍鏈夊洜瀛愶紙鍚�1鑰屼笉鍚湰韬級涔嬪拰绛変簬B锛岃�屼笖B鐨勬墍鏈夊洜瀛愶紙鍚�1鑰屼笉鍚湰韬級涔嬪拰绛変簬A锛孉鍜孊灏辨槸涓�瀵逛翰瀵嗘暟

16:1+2+4+8 = 15

15:1+3+5 = 9

鎵撳嵃5000浠ュ唴鎵�鏈夌殑浜插瘑鏁�

鎬濊矾锛氶渶瑕侀噸澶嶆墽琛岀殑閫昏緫鏄幏鍙栦竴涓暟鐨勬墍鏈夊洜瀛愪箣鍜�

鏂规硶鐨勯噸杞�

鍦ㄥ悓涓�涓被涓紝瀛樺湪浜嗘柟娉曞悕涓�鑷磋�屽弬鏁板垪琛ㄤ笉鍚岋紙鍙傛暟涓暟涓嶅悓鎴栬�呮槸瀵瑰簲浣嶇疆涓婄殑鍙傛暟绫诲瀷涓嶅悓锛夌殑鏂规硶 --- 鏂规硶鐨勯噸杞� --- 渚濋潬鍙傛暟鍒楄〃鏉ュ尯鍒嗚皟鐢ㄧ殑鏂规硶

鏂规硶鍦ㄨ皟鐢ㄧ殑鏃跺�欎細杩涜妯$硦鍖归厤---鍙傛暟绫诲瀷鍦ㄦ病鏈夋渶绗﹀悎鐨勬儏鍐典笅浼氳嚜鍔ㄦ彁鍗囷紝灏变細瀵艰嚧鎻愬崌涔嬪悗鍙兘浼氭湁澶氫釜鍖归厤

鏂规硶鐨勪紶鍊�

娉ㄦ剰锛�

1. 鏂规硶鏄湪鏍堝唴瀛樹腑鎵ц

2. 鏂规硶鍦ㄤ紶鍊肩殑鏃跺�欙紝鍩烘湰绫诲瀷浼犻�掔殑瀹為檯鍊硷紝鏁扮粍浼犻�掔殑鏄湴鍧�銆�

3. 浼犻�掑湴鍧�涔嬪悗锛屽鏋滃湴鍧�娌℃湁鍙戠敓鏀瑰彉锛屽垯浠g爜鎵ц褰卞搷鍘熸潵鐨勬暟缁勶紱濡傛灉鍦板潃鍙戠敓浜嗘敼鍙橈紝鍒欐敼鍙樹箣鍚庣殑浠g爜涓嶄細褰卞搷鍘熸潵鐨勬暟缁�

鏂规硶鐨勯�掑綊

灞曠幇褰㈠紡锛氭柟娉曡皟鐢ㄤ簡鑷繁鏈韩

缁冧範锛氳緭鍏ヤ竴涓暟瀛梟锛屾眰n! = n(n-1)(n-2)...1

6! = 6*5*4*3*2*1=720

娉ㄦ剰锛氬湪閫掑綊鐨勬椂鍊欙紝褰撴墽琛屾鏁拌繃澶氫細浜х敓StackOverflowError - 鏍堟孩鍑洪敊璇�

鎬荤粨锛氬湪涓�浜涘満鏅腑锛屽鏋滆兘纭畾杩欎竴椤瑰拰鍓峮椤圭殑鍏崇郴锛岄偅涔堝彲浠ヤ娇鐢ㄩ�掑綊 ---> 閫嗘帹

IDE --- 鏅鸿兘寮�鍙戝伐鍏�

Eclipse(鏃ラ) --- 鍏嶈垂銆佸熀浜庢彃浠躲�佸紑婧愩�佺豢鑹猜�

Kepler(寮�鏅嫆) -> Luna(鏈堢) -> Mars(鐏槦) -> Neon(闇撹櫣鐏�) -> Oxygen(姘ф皵)

闈㈠悜瀵硅薄

闈㈠悜瀵硅薄鏄竴绉嶆�濈淮鏂瑰紡锛岀浉瀵逛簬闈㈠悜杩囩▼鑰岃█鐨勩��

闈㈠悜杩囩▼鍦ㄦ祦绋嬩腑鍏虫敞鍔ㄤ綔鎵ц鐨勬瘡涓�涓粏鑺� --- 鑷繁鍔ㄦ墜鍋�

闈㈠悜瀵硅薄閲嶇偣鎵捐繖涓璞★紝鍙鎵惧埌浜嗗璞★紝閭d箞杩欎釜瀵硅薄鎵�鍏锋湁鐨勫姛鑳藉氨鑳藉琚娇鐢� --- 鎵惧埆浜哄仛

闈㈠悜瀵硅薄涓�瀹氭瘮闈㈠悜杩囩▼濂藉悧锛�--- 涓嶄竴瀹� ---鐩稿绠�鍗曠殑浜嬪姟寤鸿浣跨敤闈㈠悜杩囩▼锛岀浉瀵瑰鏉傜殑浜嬪姟寤鸿浣跨敤闈㈠悜瀵硅薄

闈㈠悜瀵硅薄鏈韩鏄熀浜庨潰鍚戣繃绋嬬殑

绫讳笌瀵硅薄鐨勫叧绯�

鏍规嵁涓�绫诲璞¤繘琛屾娊鍙栧拰鎬荤粨锛屽皢杩欑被瀵硅薄鐨勭壒寰佹娊鍙栨垚浜嗗睘鎬э紝灏嗚繖绫诲璞$殑琛屼负鎶藉彇鎴愪簡鏂规硶锛岀敤绫昏〃绀鸿繖涓�绫诲璞� -> 绫绘槸瀵硅薄鐨勬娊鍙栧拰姒傛嫭鐨勮繃绋�

瀵硅薄鐨勫唴瀛樺瓨鍌�

鎴愬憳鍙橀噺鍜屽眬閮ㄥ彉閲�

1. 瀹氫箟浣嶇疆锛氭垚鍛樺彉閲忓畾涔夊湪绫诲唴鏂规硶澶栵紱灞�閮ㄥ彉閲忔槸瀹氫箟鍦ㄦ柟娉曟垨鑰呮槸璇彞閲岄潰

2. 浣滅敤鑼冨洿锛氭垚鍛樺彉閲忎綔鐢ㄥ湪鏁翠釜绫诲唴锛涘眬閮ㄥ彉閲忔槸鍙兘浣滅敤鍦ㄥ畾涔夊畠鐨勬柟娉曟垨鑰呰鍙ヤ腑

3. 鍐呭瓨浣嶇疆锛氭垚鍛樺彉閲忛殢鐫�瀵硅薄鐨勫垱寤鸿�屽瓨鍦ㄤ簡鍫嗗唴瀛樹腑骞朵笖鍦ㄥ爢鍐呭瓨涓祴浜堜簡榛樿鍊硷紱灞�閮ㄥ彉閲忓湪鏍堝唴瀛樹腑瀛樺偍

4. 鐢熷懡鍛ㄦ湡锛氭垚鍛樺彉閲忓啀瀵硅薄鍒涘缓鐨勬椂鍊欏嚭鐜帮紝鍦ㄥ璞¤鍥炴敹鐨勬椂鍊欓攢姣侊紱灞�閮ㄥ彉閲忓湪鏂规硶鎴栬�呰鍙ユ墽琛岀殑鏃跺�欏垱寤猴紝鏂规硶鎴栬�呰鍙ユ墽琛屽畬鎴愪箣鍚庡氨绔嬪嵆閿�姣�

Eclipse - 鏃ラ

鍏嶈垂銆佸紑婧愩�佺豢鑹层�佸熀浜庢彃浠�

Eclipse鏄敱Java璇█寮�鍙戠殑

Kepter - Luna(JDK1.7) - Mars - Neon - Oxygen

Intelli J --- IDEA --- 鏀惰垂

Ctrl + c 澶嶅埗

Ctrl + v 绮樿创

Ctrl + x 鍓垏

Ctrl + s 淇濆瓨

Alt + / 蹇嵎鎻愮ず閿�

Ctrl + 1 閿欒鎻愮ず閿�

Ctrl + Shift + o 瀵煎寘

Alt + Shift + S source

Ctrl + Shift + f 璋冩暣鏍煎紡 --- 涓嶈兘鍦ㄤ换浣曡緭鍏ユ硶涓嬩娇鐢�

Alt + 鈫�/鈫撀� 鏁磋涓婄Щ/涓嬬Щ

Ctrl + F11 杩愯

Ctrl + F 鎼滅储

Alt + Ctrl + 鈫�/鈫� 鏁磋鍚戜笂/鍚戜笅澶嶅埗涓�琛�

Ctrl + D 鍒犻櫎涓�琛�

Ctrl + / 娣诲姞/鍙栨秷鍗曡娉ㄩ噴

Ctrl + Shift + / 娣诲姞澶氳娉ㄩ噴

Ctrl + Shift + \ 鍙栨秷澶氳娉ㄩ噴

Alt + 鈫� 鍒囨崲鍒颁笂涓�涓紪杈戠殑椤甸潰

Ctrl + N 鏂板缓

Ctrl + W 鍏抽棴褰撳墠鐨勭晫闈�

Alt + F4聽 鍏抽棴褰撳墠鐨勫簲鐢ㄧ▼搴�

DAY聽 07

澶嶄範锛�

1. 鏂规硶锛氶渶瑕侀噸澶嶄娇鐢ㄦ煇娈甸�昏緫鐨勬椂鍊欙紝灏卞皢杩欐閫昏緫鎻愬彇鎴愭柊鐨勫舰寮忋��

瀹氫箟鏍煎紡锛氫慨楗扮 杩斿洖鍊肩被鍨� 鏂规硶鍚�(鍙傛暟鍒楄〃){鏂规硶浣�; return 杩斿洖鍊�;} --- 褰㈠弬锛屽疄鍙� --- 鏂规硶鍚�+鍙傛暟鍒楄〃 -> 鏂规硶绛惧悕

public static int add(int i, int j){} --- add(int, int)

鏂规硶鐨勯噸杞斤細鍦ㄥ悓涓�涓被涓瓨鍦ㄤ簡鏂规硶鍚嶄竴鑷磋�屽弬鏁板垪琛ㄤ笉鍚岋紙鍙傛暟鐨勪釜鏁�/瀵瑰簲浣嶇疆涓婄殑鍙傛暟绫诲瀷锛夌殑鏂规硶

鏂规硶鐨勪紶鍊硷細鍩烘湰绫诲瀷浼犻�掔殑鏄疄闄呭�硷紱瀵硅薄浼犻�掔殑鏄湴鍧�锛屽湴鍧�涓嶅彉鐨勫墠鎻愪笅鍙互鏀瑰彉鍏朵腑鐨勫睘鎬ф垨鑰呭厓绱犮��

鏂规硶鐨勯�掑綊锛氬湪鏂规硶涓皟鐢ㄤ簡鑷繁鏈韩銆傚綋閫掑綊灞傛澶繁浼氬嚭鐜癝tackOverflowError --- 鏍堟孩鍑洪敊璇� --- 閫掑綊鐨勬�濊矾寰�寰�鏄�嗘帹鐨勬�濈淮鏂瑰紡

2. 闈㈠悜瀵硅薄涓庨潰鍚戣繃绋嬬殑姣旇緝锛氶兘鏄�濈淮鏂瑰紡銆傞潰鍚戣繃绋嬫槸娉ㄩ噸娴佺▼涓殑姣忎竴涓楠わ紝娓呮姣忎竴涓楠や腑鐨勭粏鑺傦紙鑷繁鍋氾級锛涢潰鍚戝璞℃槸娉ㄩ噸瀵硅薄锛屽彧瑕佹嫢鏈変簡瀵硅薄灏辫兘浣跨敤瀵硅薄韬笂鐨勫姛鑳斤紙鎵惧埆浜哄仛锛夈�傞潰鍚戝璞℃槸鍩轰簬闈㈠悜杩囩▼鐨勩�傜浉瀵圭畝鍗曠殑浜嬪姟浣跨敤闈㈠悜杩囩▼锛岀浉瀵瑰鏉傜殑浜嬪姟浣跨敤闈㈠悜瀵硅薄銆�--- 闈㈠悜瀵硅薄鏇撮�傚悎浜庡洟闃熺殑寮�鍙戯紱闈㈠悜杩囩▼涓�鑸�岃█姣旈潰鍚戝璞℃洿閫傚悎浜庢晥鐜囧紑鍙戙��

3. 绫讳笌瀵硅薄鐨勫叧绯伙細绫绘槸瀵硅薄鐨勬鎷�/鎶藉彇锛屽璞℃槸绫荤殑鍏蜂綋瀹炵幇

4. 瀵硅薄鐨勫唴瀛樺瓨鍌細瀵硅薄鏄瓨鍌ㄥ湪鍫嗗唴瀛樹腑锛屽湪鏍堝唴瀛樹腑浼氬瓨鍌ㄥ璞$殑鍦板潃寮曠敤銆傚璞″湪瀛樺偍鍒板唴瀛樹腑涔嬪悗鍏朵腑鐨勫睘鎬т細鑷姩璧嬩簣榛樿鍊笺��--- 瀵硅薄鍦ㄤ娇鐢ㄥ畬鎴愪箣鍚庝笉涓�瀹氱珛鍗崇Щ鍑哄爢鍐呭瓨鑰屾槸鍦ㄤ笉瀹氱殑鏌愪釜鏃跺埢琚洖鏀躲��

5. 鎴愬憳鍙橀噺鍜屽眬閮ㄥ彉閲忥細瀹氫箟浣嶇疆銆佷綔鐢ㄨ寖鍥淬�佸唴瀛樹綅缃�佺敓鍛藉懆鏈�

鏋勯�犳柟娉�

鐗圭偣锛氫笌绫诲悓鍚嶈�屾病鏈夎繑鍥炲�肩被鍨嬬殑鏂规硶

浣滅敤锛氬垱寤哄璞�

this鍏抽敭瀛�

this鍏抽敭瀛楀湪绫讳腑璋冪敤鏈被閲岄潰鐨勫睘鎬у拰鏂规硶锛屼唬琛ㄥ綋鍓嶅湪娲诲姩鐨勫璞°��

this璇彞 -> this(鍙傛暟鍒楄〃) - 琛ㄧず鍦ㄦ湰绫荤殑鏋勯�犳柟娉曚腑璋冪敤鏈被瀵瑰簲褰㈠紡鐨勫叾浠栫殑鏋勯�犳柟娉� - this璇彞蹇呴』鏀惧湪鏋勯�犳柟娉曠殑绗竴琛�

浠g爜鍧�

鏋勯�犱唬鐮佸潡锛氬畾涔夊湪绫讳腑鐢▄}鍖呰捣鏉ョ殑浠g爜 --- 鍦ㄥ垱寤哄璞$殑鏃跺�欏厛浜庢瀯閫犳柟娉曟墽琛�

灞�閮ㄤ唬鐮佸潡锛氬畾涔夊湪鏂规硶涓敤{}鍖呰捣鏉ョ殑浠g爜 --- 鎻愰珮浜嗘爤鍐呭瓨鐨勫埄鐢ㄧ巼

闈㈠悜瀵硅薄鐨勭壒寰�

灏佽銆佺户鎵裤�佸鎬侊紙鎶借薄锛�

灏佽

灏嗕唬鐮佽繘琛屾彁鍙栧拰鎬荤粨锛屾娊鍙栨垚涓嶅悓鐨勫舰寮� --- 灏佽

浣撶幇褰㈠紡锛氭柟娉曘�佺被锛堝睘鎬х殑绉佹湁鍖� - 灏嗗睘鎬ч檺鍒朵负绉佹湁鐨勶紝鐒跺悗鎻愪緵瀵瑰鐨勮缃拰鑾峰彇鐨勬柟娉曪紝鐒跺悗鍦ㄦ柟娉曚腑杩涜闄愬埗浣挎暟鎹洿鍔犵鍚堝父鐞嗭級

浼樺娍锛氭彁楂樹簡浠g爜鐨勫鐢ㄦ�э紝淇濊瘉浜嗘暟鎹殑鍚堟硶鎬�

鏉冮檺淇グ绗�

鎸囧湪Java涓敤浜庨檺瀹氫娇鐢ㄨ寖鍥寸殑鍏抽敭瀛�

鏈被涓� 瀛愮被涓� 鍚屽寘绫讳腑 鍏朵粬绫讳腑

public 鍙互 鍙互 鍙互 鍙互

protected 鍙互 鍙互 鍙互 涓嶅彲浠�

榛樿 鍙互 鍚屽寘瀛愮被鍙互 鍙互 涓嶅彲浠�

private 鍙互 涓嶅彲浠� 涓嶅彲浠� 涓嶅彲浠�

缁冧範锛氬畾涔変竴涓被琛ㄧず鐭╁舰锛堥暱鏂瑰舰锛夛紝鎻愪緵鑾峰彇鍛ㄩ暱鍜岄潰绉殑鏂规硶

缁ф壙

濡傛灉涓�浜涚被涓惈鏈夌浉鍚岀殑浠g爜锛岄偅涔堝彲浠ュ皢杩欎簺鐩稿悓鐨勪唬鐮佹彁鍙栧埌涓�涓柊鐨勭被涓紝鐒跺悗閫氳繃extends鍏抽敭瀛楄鍘熸潵鐨勭被鍜屾柊鐨勭被浜х敓鍏崇郴 --- 缁ф壙銆� 閫氳繃缁ф壙锛屽師鏉ョ殑绫诲氨绉颁箣涓轰簡瀛愮被锛堟淳鐢熺被锛夛紝鏂扮殑绫诲氨鎴愪簡鐖剁被锛堣秴绫�/鍩虹被锛夈��

瀛愮被閫氳繃缁ф壙鐖剁被鍙互浣跨敤鐖剁被涓殑涓�閮ㄥ垎鏂规硶鍜屽睘鎬�

娉ㄦ剰锛氬瓙绫荤户鎵夸簡鐖剁被鐨勫叏閮ㄧ殑鏁版嵁鍩燂紙鏂规硶+灞炴�э級锛屼絾鏄户鎵夸箣鍚庡彧鏈変竴閮ㄥ垎鏁版嵁鍩熷瀛愮被鍙

鍦↗ava涓紝鏀寔鐨勬槸绫诲拰绫讳箣闂寸殑鍗曠户鎵� -> 涓�涓瓙绫诲彧鑳界户鎵夸竴涓埗绫伙紝浣嗘槸涓�涓埗绫诲彲浠ユ湁澶氫釜瀛愮被

鍗曠户鎵夸竴瀹氫紭浜庡缁ф壙鍚楋紵 - 涓嶅

澶氱户鎵挎瘮鍗曠户鎵胯兘澶熸洿濂界殑鎻愰珮浠g爜鐨勫鐢ㄦ��

class A {

public int m(){return 9;}

}

class B {

public boolean m(){return false;}

}

class C extends A, B{}

C c = new C();

c.m(); // 杩斿洖鍊肩被鍨嬭兘纭畾鍚楋紵

澶氱户鎵垮鑷村湪璋冪敤鏂规硶鐨勬椂鍊欏彲鑳戒骇鐢熸涔�

浼樺娍锛氭彁楂樹唬鐮佺殑澶嶇敤鎬э紝閬垮厤鏂规硶鐨勮皟鐢ㄤ骇鐢熸涔�

super鍏抽敭瀛�

鍦ㄥ瓙绫讳腑鐢ㄤ簬琛ㄧず鐖剁被瀵硅薄鐨勫紩鐢紝鍙互鍦ㄥ瓙绫讳腑璋冪敤鐖剁被涓殑鏂规硶鐨勫睘鎬с��

super璇彞 --- 瀛愮被鍦ㄧ户鎵跨埗绫讳箣鍚庯紝瀛愮被鐨勬瀯閫犳柟娉曚腑浼氬惈鏈変竴涓猻uper璇彞銆傚鏋滄病鏈夋墜鍔ㄦ寚瀹歴uper璇彞锛岄偅涔堥粯璁や娇鐢╯uper()璋冪敤鐖剁被鏃犲弬鐨勬瀯閫狅紱濡傛灉鐖剁被鍙彁渚涗簡鍚弬鏋勯�狅紝閭d箞瀛愮被灏卞繀椤绘墜鍔ㄦ彁渚涘搴斿舰寮忕殑super璇彞 --- super璇彞蹇呴』鍦ㄥ瓙绫绘瀯閫犳柟娉曠殑棣栬

鏂规硶鐨勯噸鍐�/瑕嗙洊

鍦ㄧ埗瀛愮被涓瓨鍦ㄤ簡鏂规硶绛惧悕鐩稿悓鐨勯潪闈欐�佹柟娉曘�傞伒寰� 鈥滀袱绛変袱灏忎竴澶р�濆師鍒欙細

1. 鏂规硶绛惧悕鐩稿悓

2. 濡傛灉鐖剁被涓殑鏂规硶鐨勮繑鍥炲�肩被鍨嬫槸鍩烘湰绫诲瀷/void锛岄偅涔堝瓙绫婚噸鍐欑殑鏂规硶鐨勮繑鍥炲�肩被鍨嬩笌鐖剁被涓�鑷�

class A {

public void m(){}

}

class B extends A {

public void m(){}

}

3. 濡傛灉鐖剁被涓殑鏂规硶鐨勮繑鍥炲�肩被鍨嬫槸寮曠敤绫诲瀷锛岄偅涔堝瓙绫诲湪閲嶅啓鏂规硶鐨勬椂鍊欙紝杩斿洖鍊肩被鍨嬭涔堜笌鐖剁被涓�鑷达紝瑕佷箞鏄埗绫绘柟娉曡繑鍥炲�肩被鍨嬬殑瀛愮被

class A {}

class B extends A {}

class聽 C {

public A m(){return null;}

}

class D extends C {

public B m(){return null;}

}

4. 瀛愮被閲嶅啓鐨勬柟娉曠殑鏉冮檺淇グ绗︾殑鑼冨洿瑕佸ぇ浜庣瓑浜庣埗绫讳腑瀵瑰簲鏂规硶鐨勬潈闄愪慨楗扮鐨勮寖鍥�

class A {

public void m(){}

}

class B extends A {

public void m(){}

}

娉ㄦ剰:濡傛灉鐖剁被涓殑鏂规硶鐢╬rivate淇グ锛岄偅涔堣繖涓柟娉曞瀛愮被涓嶅彲瑙侊紝鎵�浠ユ鏃朵笌瀛愮被涓殑鏂规硶鏋勪笉鎴愰噸鍐�

澶氭��

缂栬瘧鏃跺鎬侊細鏂规硶鐨勯噸杞�

add(2, 4) -> add(int, int)

add(3, 1, 7) -> add(int, int, int)

杩愯鏃跺鎬侊細鍚戜笂閫犲瀷鍜屾柟娉曠殑閲嶅啓 --- 鍩轰簬缁ф壙鐨�

娉ㄦ剰锛氬鏋滀娇鐢ㄥ悜涓婇�犲瀷鏉ュ垱寤哄璞★紝閭d箞杩欎釜瀵硅薄鎵�鑳借皟鐢ㄧ殑鏂规硶鐪嬬殑鏄埗绫讳腑鐨勫0鏄庯紝鏂规硶濡備綍鎵ц鐪嬬殑鏄瓙绫讳腑鐨勫疄鐜拌繃绋�

閲嶅啓鐨勭悊瑙�

1. 瀛愮被閲嶅啓鐨勬柟娉曠殑鏉冮檺淇グ绗︾殑鑼冨洿瑕佸ぇ浜庣瓑浜庣埗绫讳腑瀵瑰簲鏂规硶鐨勬潈闄愪慨楗扮鐨勮寖鍥�

2. 濡傛灉鐖剁被涓殑鏂规硶鐨勮繑鍥炲�肩被鍨嬫槸寮曠敤绫诲瀷锛岄偅涔堝瓙绫诲湪閲嶅啓鏂规硶鐨勬椂鍊欙紝杩斿洖鍊肩被鍨嬭涔堜笌鐖剁被涓�鑷达紝瑕佷箞鏄埗绫绘柟娉曡繑鍥炲�肩被鍨嬬殑瀛愮被

娉ㄦ剰锛欽ava涓墍鏈夌殑鍩烘湰绫诲瀷涔嬮棿娌℃湁缁ф壙鍏崇郴锛屼箣鎵�浠ヨ兘澶熻嚜鍔ㄦ彁鍗囷紝鏄洜涓烘墍琛ㄧず鐨勮寖鍥存槸鍚﹁兘澶熷寘鍚�

DAY08

澶嶄範锛�

1. 鏋勯�犳柟娉曪細

鐗圭偣锛氫笌绫诲悓鍚嶈�屾病鏈夎繑鍥炲�肩被鍨�

浣滅敤锛氱敤浜庡垱寤哄璞�

褰撶被涓病鏈夋墜鍔ㄦ寚瀹氭瀯閫犳柟娉曠殑鏃跺�欏湪缂栬瘧鐨勬椂鍊欒嚜鍔ㄦ坊鍔犱竴涓棤鍙傛瀯閫�

2. this鍏抽敭瀛楋細浠h〃鏈被鐨勫湪娲诲姩鐨勫璞★紝鐢ㄤ簬鍦ㄦ湰绫讳腑璋冪敤鏈被鐨勬柟娉曞拰灞炴�� --- this璇彞锛岃〃绀鸿皟鐢ㄦ湰绫讳腑鍏朵粬鐨勫搴斿舰寮忕殑鏋勯�犳柟娉曪紝蹇呴』鏀惧湪棣栬

3. 浠g爜鍧楋細

鏋勯�犱唬鐮佸潡锛氬湪鍒涘缓瀵硅薄鐨勬椂鍊欏厛浜庢瀯閫犳柟娉曟墽琛屼竴娆� --- 鐢ㄤ簬瀹屾垚涓�浜涘垵濮嬪寲鎿嶄綔

灞�閮ㄤ唬鐮佸潡锛氭彁楂樻爤鍐呭瓨鐨勫埄鐢ㄧ巼

4. 灏佽锛�

浣撶幇褰㈠紡锛氭柟娉曘�佺被锛堝睘鎬х殑绉佹湁鍖� -> 灏嗗睘鎬ц缃负private锛屽澶栨彁渚涘搴旂殑get/set鐨勬柟娉曪紝鍦ㄦ柟娉曚腑鍙互杩涜闄愬畾浣挎暟鎹洿鍔犵鍚堝満鏅姹傦級

浼樺娍锛氭彁楂樺鐢ㄦ�э紝淇濊瘉鏁版嵁鐨勫悎娉曟��

5. 缁ф壙 锛氱敤extends鍏抽敭瀛楁潵瀹屾垚缁ф壙鍏崇郴 --- 鏀寔鐨勭被涓庣被涔嬮棿鐨勫崟缁ф壙 --- 鍗曠户鎵垮拰澶氱户鎵跨殑浼樺姡鎬� --- 鎻愰珮澶嶇敤鎬э紝閬垮厤鏂规硶璋冪敤浜х敓姝т箟 --- 瀛愮被鍙互缁ф壙鐖剁被鍏ㄩ儴鐨勬暟鎹煙锛屼絾鏄彧鏈変竴閮ㄥ垎鍙

6. 澶氭�侊細

缂栬瘧鏃跺鎬侊細鏂规硶鐨勯噸杞�

杩愯鏃跺鎬侊細

鍚戜笂閫犲瀷锛氱敤鐖剁被鏉ュ0鏄庣敤瀛愮被鏉ュ垱寤� --- 瀵硅薄鑳藉共浠�涔堢湅鐨勬槸鐖剁被锛屽璞″浣曟墽琛屾柟娉曠湅鐨勬槸瀛愮被銆�

鏂规硶鐨勯噸鍐�(Override)锛氱埗瀛愮被涓瓨鍦ㄤ簡鏂规硶绛惧悕瀹屽叏鐩稿悓鐨勯潪闈欐�佹柟娉曘��--- 涓ょ瓑涓ゅ皬涓�澶�

7. 鏉冮檺淇グ绗︼細public protected 榛樿 private --- protected鍦ㄥ瓙绫讳腑浣跨敤鐨勬椂鍊欐寚鐨勬槸鍦ㄥ搴旂殑瀛愮被涓娇鐢紝涓嶈兘璺ㄥ瓙绫讳娇鐢�

8. super鍏抽敭瀛楋細鍦ㄥ瓙绫讳腑琛ㄧず鐖剁被瀵硅薄鐨勫紩鐢紝鐢ㄤ簬璋冪敤鐖剁被涓殑鏂规硶鍜屽睘鎬� --- super璇彞锛岃〃绀哄湪瀛愮被鐨勬瀯閫犳柟娉曚腑璋冪敤鐖剁被瀵瑰簲褰㈠紡鐨勬瀯閫犳柟娉曘�傚瓙绫绘瀯閫犳柟娉曚腑濡傛灉娌℃湁鎵嬪姩鎸囧畾super璇彞锛岄偅涔堥粯璁よ皟鐢ㄧ埗绫绘棤鍙傛瀯閫狅紙super()锛�;濡傛灉鐖剁被鍙彁渚涗簡鍚弬鏋勯�狅紝閭d箞瀛愮被鐨勬瀯閫犳柟娉曚腑蹇呴』鎵嬪姩鎻愪緵瀵瑰簲褰㈠紡鐨剆uper璇彞

static - 闈欐��

淇グ绗� - 鐢ㄤ簬淇グ鏁版嵁銆佹柟娉曘�佷唬鐮佸潡浠ュ強鍐呴儴绫�

闈欐�佸彉閲�

鐢╯tatic淇グ鍙橀噺锛岀О涔嬩负闈欐�佸彉閲忥紝涔熷彨绫诲彉閲忋�傚湪绫诲姞杞界殑鏃跺�欏姞杞藉埌浜嗘柟娉曞尯锛屽苟涓斿湪鏂规硶鍖轰腑琚祴浜堜簡榛樿鍊笺�傞潤鎬佸彉閲忔槸鍏堜簬瀵硅薄鍑虹幇鐨勶紝鎵�浠ヤ範鎯笂鏄�氳繃绫诲悕鏉ヨ皟鐢ㄩ潤鎬佸彉閲忋�傛瘡涓�涓璞″瓨鍌ㄧ殑鏄繖涓潤鎬佸彉閲忓湪鏂规硶鍖轰腑鐨勫湴鍧�锛屾墍浠ラ潤鎬佸彉閲忔槸琚繖涓被鐨勬墍鏈夊璞℃墍鍏变韩鐨�

闈欐�佸彉閲忚兘鍚﹀畾涔夊埌鏋勯�犳柟娉曚腑锛�---涓嶈兘銆傞潤鎬佸彉閲忔槸鍦ㄧ被鍔犺浇鐨勬椂鍊欏嚭鐜帮紝鍏堜簬瀵硅薄鍑虹幇銆傛瀯閫犳柟娉曞湪鍒涘缓瀵硅薄鐨勬椂鍊欐墽琛屻��

娉ㄦ剰锛�

1. 绫绘槸鍔犺浇鍒版柟娉曞尯涓殑

2. 绫绘槸鍦ㄧ涓�娆′娇鐢ㄧ殑鏃跺�欐墠鍔犺浇锛屽姞杞戒箣鍚庡氨涓嶄細绉婚櫎

缁冧範锛氬畾涔変竴涓被锛岀粺璁¤繖涓被鍒涘缓瀵硅薄鐨勪釜鏁�

闈欐�佹柟娉�

鐢╯tatic淇グ鐨勬柟娉曪紝绉颁箣涓洪潤鎬佹柟娉曘�傞潤鎬佹柟娉曢殢鐫�绫荤殑鍔犺浇鑰屽姞杞藉埌鏂规硶鍖轰腑锛屼絾鏄湪鏂规硶鍖轰腑涓嶆墽琛屽彧瀛樺偍锛屽湪鏂规硶琚皟鐢ㄧ殑鏃跺�欏埌鏍堝唴瀛樻墽琛屻�傞潤鎬佹柟娉曞厛浜庡璞″瓨鍦紝鎵�浠ヤ範鎯笂鏄�氳繃绫诲悕鏉ヨ皟鐢ㄩ潤鎬佹柟娉曘��

main Arrays.sort() System.arraycopy()

闈欐�佹柟娉曚腑鍙互瀹氫箟闈欐�佸彉閲忓悧锛�--- 涓嶈兘 --- 闈欐�佹柟娉曞湪璋冪敤鐨勬椂鍊欐墽琛岋紝闈欐�佹柟娉曟墽琛岀殑鏃跺�欓噷闈㈢殑鍙橀噺鎵嶈兘鍒濆鍖栵紱闈欐�佸彉閲忔槸鍦ㄧ被鍔犺浇鐨勬椂鍊欏垵濮嬪寲

闈欐�佹柟娉曚腑鑳藉惁浣跨敤this/super锛�--- 涓嶈 --- this浠h〃褰撳墠鍦ㄦ椿鍔ㄧ殑瀵硅薄锛岄潤鎬佹柟娉曞厛浜庡璞″瓨鍦�

鑳藉惁鍦ㄩ潤鎬佹柟娉曚腑鐩存帴浣跨敤鏈被涓殑闈為潤鎬佹柟娉�/闈為潤鎬佸睘鎬э紵--- 涓嶈

public class A {

int i = 5;

public static void m(){

int j = (this.)i;

}

}

闈欐�佹柟娉曞彲浠ラ噸杞藉悧锛�---鍙互

闈欐�佹柟娉曞彲浠ヨ缁ф壙鍚楋紵---鍙互

闈欐�佹柟娉曞彲浠ラ噸鍐欏悧锛�---涓嶅彲浠�

闈欐�佹柟娉曡櫧鐒朵笉鑳借閲嶅啓锛屼絾鏄埗瀛愮被涓彲浠ュ瓨鍦ㄦ柟娉曠鍚嶄竴鑷寸殑闈欐�佹柟娉� --- 闈欐�佹柟娉曠殑闅愯棌锛坔ide锛�

娉ㄦ剰锛氱埗瀛愮被涓彲浠ュ瓨鍦ㄦ柟娉曠鍚嶄竴鑷寸殑鏂规硶锛岃涔堥兘鏄潪闈欐�侊紙閲嶅啓锛夎涔堥兘鏄潤鎬侊紙闅愯棌锛�

闈欐�佷唬鐮佸潡

鐢╯tatic{}鍖呰捣鏉ョ殑浠g爜 --- 鍦ㄧ被鍔犺浇鐨勬椂鍊欐墽琛屼竴娆�

鎵ц椤哄簭锛氱埗绫婚潤鎬� -> 瀛愮被闈欐�� -> 鐖剁被闈為潤鎬� -> 鐖剁被鐨勬瀯閫犳柟娉� -> 瀛愮被闈為潤鎬� -> 瀛愮被鐨勬瀯閫犳柟娉�

你可能感兴趣的:(鍓嶅叓澶╃瑪璁�)