±À¤¶:| ½Õ¸Ñ­û½Òµ{ | Makeup Course | Hypnosis course | English course | NLP training | cissp cisa cism | Àç¾i¾Ç½Òµ{ |

µo·s¸ÜÃD
¥´¦L

[ÀÉ®×] Java¤Jªù¡Ð¡Ð¦³Ãö©óJava¤¤´Ì»P°ïªº«ä¦Ò

Java¤Jªù¡Ð¡Ð¦³Ãö©óJava¤¤´Ì»P°ïªº«ä¦Ò

1. ´Ì(stack)»P°ï(heap)³£¬OJava¥Î¨Ó¦bRam¤¤¦s©ñ¼Æ¾Úªº¦a¤è¡C»PC++¤£¦P¡AJava¦Û°ÊºÞ²z´Ì©M°ï¡Aµ{¦¡­û¤£¯àª½±µ¦a³]¸m´Ì©Î°ï¡C

2. ´ÌªºÀu¶Õ¬O¡A¦s¨ú³t«×¤ñ°ï­n§Ö¡A¶È¦¸©óª½±µ¦ì©óCPU¤¤ªº±H¦s¾¹¡C¦ý¯ÊÂI¬O¡A¦s¦b´Ì¤¤ªº¼Æ¾Ú¤j¤p»P¥Í¦s´Á¥²¶·¬O½T©wªº¡A¯Ê¥FÆF¬¡©Ê¡C¥t¥~¡A´Ì¼Æ¾Ú¥i¥H¦@¥Î¡A¸Ô¨£²Ä3ÂI¡C°ïªºÀu¶Õ¬O¥i¥H°ÊºA¦a¤À°t°O¾ÐÅé¤j¤p¡A¥Í¦s´Á¤]¤£¥²¨Æ¥ý§i¶D½sĶ¾¹¡AJavaªº©U§£¦¬¶°¾¹·|¦Û°Ê¦¬¨«³o¨Ç¤£¦A¨Ï¥Îªº¼Æ¾Ú¡C¦ý¯ÊÂI¬O¡A¥Ñ©ó­n¦b¹B¦æ®É°ÊºA¤À°t°O¾ÐÅé¡A¦s¨ú³t«×¸ûºC¡C

3. Java¤¤ªº¼Æ¾ÚÃþ«¬¦³¨âºØ¡C

¤@ºØ¬O°ò¥»Ãþ«¬(primitive types), ¦@¦³8ºØ¡A§Yint, short, long, byte, float, double, boolean, char(ª`·N¡A¨Ã¨S¦³stringªº°ò¥»Ãþ«¬)¡C³oºØÃþ«¬ªº©w¸q¬O³q¹L½Ñ¦pint a = 3; long b = 255L;ªº§Î¦¡¨Ó©w¸qªº¡AºÙ¬°¦Û°ÊÅܼơC­È±oª`·Nªº¬O¡A¦Û°ÊÅܼƦsªº¬O¦r­±­È¡A¤£¬OÃþªº¹ê¨Ò¡A§Y¤£¬OÃþªº¤Þ¥Î¡A³o¸Ì¨Ã¨S¦³Ãþªº¦s¦b¡C¦pint a = 3; ³o¸Ìªºa¬O¤@­Ó«ü¦VintÃþ«¬ªº¤Þ¥Î¡A«ü¦V3³o­Ó¦r­±­È¡C³o¨Ç¦r­±­Èªº¼Æ¾Ú¡A¥Ñ©ó¤j¤p¥iª¾¡A¥Í¦s´Á¥iª¾(³o¨Ç¦r­±­È©T©w©w¸q¦b¬Y­Óµ{¦¡¶ôùØ­±¡Aµ{¦¡¶ô°h¥X«á¡A¦r¬q­È´N®ø¥¢¤F)¡A¥X©ó°l¨D³t«×ªº­ì¦]¡A´N¦s¦b©ó´Ì¤¤¡C

¥t¥~¡A´Ì¦³¤@­Ó«Ü­«­nªº¯S®í©Ê¡A´N¬O¦s¦b´Ì¤¤ªº¼Æ¾Ú¥i¥H¦@¥Î¡C°²³]§Ú­Ì¦P®É©w¸q¡G

int a = 3;
int b = 3¡F

½sĶ¾¹¥ý³B²zint a = 3¡F­º¥ý¥¦·|¦b´Ì¤¤³Ð«Ø¤@­ÓÅܼƬ°aªº¤Þ¥Î¡AµM«á·j´M¦³¨S¦³¦r­±­È¬°3ªº¦a§}¡A¨S§ä¨ì¡A´N¶}ÅP¤@­Ó¦s©ñ3³o­Ó¦r­±­Èªº¦a§}¡AµM«á±Na«ü¦V3ªº¦a§}¡C±µµÛ³B²zint b = 3¡F¦b³Ð«Ø§¹bªº¤Þ¥ÎÅܼƫá¡A¥Ñ©ó¦b´Ì¤¤¤w¸g¦³3³o­Ó¦r­±­È¡A«K±Nbª½±µ«ü¦V3ªº¦a§}¡C³o¼Ë¡A´N¥X²{¤Fa»Pb¦P®É§¡«ü¦V3ªº±¡ªp¡C

¯S§Oª`·Nªº¬O¡A³oºØ¦r­±­Èªº¤Þ¥Î»PÃþ¹ï¶Hªº¤Þ¥Î¤£¦P¡C°²©w¨â­ÓÃþ¹ï¶Hªº¤Þ¥Î¦P®É«ü¦V¤@­Ó¹ï¶H¡A¦pªG¤@­Ó¹ï¶H¤Þ¥ÎÅܼƭקï¤F³o­Ó¹ï¶Hªº¤º³¡ª¬ºA¡A¨º»ò¥t¤@­Ó¹ï¶H¤Þ¥ÎÅܼƤ]§Y¨è¤Ï¬M¥X³o­ÓÅܤơC¬Û¤Ï¡A³q¹L¦r­±­Èªº¤Þ¥Î¨Ó­×§ï¨ä­È¡A¤£·|¾É­P¥t¤@­Ó«ü¦V¦¹¦r­±­Èªº¤Þ¥Îªº­È¤]¸òµÛ§ïÅܪº±¡ªp¡C¦p¤W¨Ò¡A§Ú­Ì©w¸q§¹a»Pbªº­È«á¡A¦A¥Oa=4¡F¨º»ò¡Ab¤£·|µ¥©ó4¡AÁÙ¬Oµ¥©ó3¡C¦b½sĶ¾¹¤º³¡¡A¹J¨ìa=4¡F®É¡A¥¦´N·|­«·s·j¯Á´Ì¤¤¬O§_¦³4ªº¦r­±­È¡A¦pªG¨S¦³¡A­«·s¶}ÅP¦a§}¦s©ñ4ªº­È¡F¦pªG¤w¸g¦³¤F¡A«hª½±µ±Na«ü¦V³o­Ó¦a§}¡C¦]¦¹a­Èªº§ïÅܤ£·|¼vÅT¨ìbªº­È¡C

¥t¤@ºØ¬O¥]¸ËÃþ¼Æ¾Ú¡A¦pInteger, String, Doubleµ¥±N¬ÛÀ³ªº°ò¥»¼Æ¾ÚÃþ«¬¥]¸Ë°_¨ÓªºÃþ¡C³o¨ÇÃþ¼Æ¾Ú¥þ³¡¦s¦b©ó°ï¤¤¡AJava¥Înew()»y¥y¨ÓÅã¥Ü¦a§i¶D½sĶ¾¹¡A¦b¹B¦æ®É¤~®Ú¾Ú»Ý­n°ÊºA³Ð«Ø¡A¦]¦¹¤ñ¸ûÆF¬¡¡A¦ý¯ÊÂI¬O­n¦û¥Î§ó¦hªº®É¶¡¡C 4. String¬O¤@­Ó¯S®íªº¥]¸ËÃþ¼Æ¾Ú¡C§Y¥i¥H¥ÎString str = new String("abc");ªº§Î¦¡¨Ó³Ð«Ø¡A¤]¥i¥H¥ÎString str = "abc"¡Fªº§Î¦¡¨Ó³Ð«Ø(§@¬°¹ï¤ñ¡A¦bJDK 5.0¤§«e¡A§A±q¥¼¨£¹LInteger i = 3;ªº¹Bºâ¦¡¡A¦]¬°Ãþ»P¦r­±­È¬O¤£¯à³q¥Îªº¡A°£¤FString¡C¦Ó¦bJDK 5.0¤¤¡A³oºØ¹Bºâ¦¡¬O¥i¥Hªº¡I¦]¬°½sĶ¾¹¦b«á»O¶i¦æInteger i = new Integer(3)ªºÂà´«)¡C«eªÌ¬O³W½dªºÃþªº³Ð«Ø¹Lµ{¡A§Y¦bJava¤¤¡A¤@¤Á³£¬O¹ï¶H¡A¦Ó¹ï¹³¬OÃþªº¹ê¨Ò¡A¥þ³¡³q¹Lnew()ªº§Î¦¡¨Ó³Ð«Ø¡CJava¤¤ªº¦³¨ÇÃþ¡A¦pDateFormatÃþ¡A¥i¥H³q¹L¸ÓÃþªºgetInstance()¤èªk¨Óªð¦^¤@­Ó·s³Ð«ØªºÃþ¡A¦ü¥G¹H¤Ï¤F¦¹­ì«h¡C¨ä¹ê¤£µM¡C¸ÓÃþ¹B¥Î¤F³æ¨Ò¼Ò¦¡¨Óªð¦^Ãþªº¹ê¨Ò¡A¥u¤£¹L³o­Ó¹ê¨Ò¬O¦b¸ÓÃþ¤º³¡³q¹Lnew()¨Ó³Ð«Øªº¡A¦ÓgetInstance()¦V¥~³¡ÁôÂäF¦¹²Ó¸`¡C¨º¬°¤°»ò¦bString str = "abc"¡F¤¤¡A¨Ã¨S¦³³q¹Lnew()¨Ó³Ð«Ø¹ê¨Ò¡A¬O¤£¬O¹H¤Ï¤F¤W­z­ì«h¡H¨ä¹ê¨S¦³¡C

5. Ãö©óString str = "abc"ªº¤º³¡¤u§@¡CJava¤º³¡±N¦¹»y¥yÂà¤Æ¬°¥H¤U´X­Ó¨BÆJ¡G

(1)¥ý©w¸q¤@­Ó¦W¬°strªº¹ïStringÃþªº¹ï¶H¤Þ¥ÎÅܼơGString str¡F

(2)¦b´Ì¤¤·j´M¦³¨S¦³¦s©ñ­È¬°"abc"ªº¦a§}¡A¦pªG¨S¦³¡A«h¶}ÅP¤@­Ó¦s©ñ¦r­±­È¬°"abc"ªº¦a§}¡A±µµÛ³Ð«Ø¤@­Ó·sªºStringÃþªº¹ï¶Ho¡A¨Ã±Noªº¦r²Å¦ê­È«ü¦V³o­Ó¦a§}¡A¦Ó¥B¦b´Ì¤¤³o­Ó¦a§}®ÇÃä°O¤U³o­Ó¤Þ¥Îªº¹ï¶Ho¡C¦pªG¤w¸g¦³¤F­È¬°"abc"ªº¦a§}¡A«h·j´M¹ï¶Ho¡A¨Ãªð¦^oªº¦a§}¡C

(3)±Nstr«ü¦V¹ï¶Hoªº¦a§}¡C

­È±oª`·Nªº¬O¡A¤@¯ëStringÃþ¤¤¦r²Å¦ê­È³£¬Oª½±µ¦s­Èªº¡C¦ý¹³String str = "abc"¡F³oºØ³õ¦X¤U¡A¨ä¦r²Å¦ê­È«o¬O«O¦s¤F¤@­Ó«ü¦V¦s¦b´Ì¤¤¼Æ¾Úªº¤Þ¥Î¡I

¬°¤F§ó¦n¦a»¡©ú³o­Ó°ÝÃD¡A§Ú­Ì¥i¥H³q¹L¥H¤Uªº´X­Ó¥N½X¶i¦æÅçÃÒ¡C

String str1 = "abc";
String str2 = "abc";
System.out.println(str1==str2); //true

ª`·N¡A§Ú­Ì³o¸Ì¨Ã¤£¥Îstr1.equals(str2)¡Fªº¤è¦¡¡A¦]¬°³o±N¤ñ¸û¨â­Ó¦r²Å¦êªº­È¬O§_¬Ûµ¥¡C==¸¹¡A®Ú¾ÚJDKªº»¡©ú¡A¥u¦³¦b¨â­Ó¤Þ¥Î³£«ü¦V¤F¦P¤@­Ó¹ï¶H®É¤~ªð¦^¯u­È¡C¦Ó§Ú­Ì¦b³o¸Ì­n¬Ýªº¬O¡Astr1»Pstr2¬O§_³£«ü¦V¤F¦P¤@­Ó¹ï¶H¡C
µ²ªG»¡©ú¡AJVM³Ð«Ø¤F¨â­Ó¤Þ¥Îstr1©Mstr2¡A¦ý¥u³Ð«Ø¤F¤@­Ó¹ï¶H¡A¦Ó¥B¨â­Ó¤Þ¥Î³£«ü¦V¤F³o­Ó¹ï¶H¡C

§Ú­Ì¦A¨Ó§ó¶i¤@¨B¡A±N¥H¤W¥N½X§ï¦¨¡G

String str1 = "abc";
String str2 = "abc";
str1 = "bcd";
System.out.println(str1 + "," + str2); //bcd, abc
System.out.println(str1==str2); //false

³o´N¬O»¡¡A½á­ÈªºÅܤƾɭP¤FÃþ¹ï¶H¤Þ¥ÎªºÅܤơAstr1«ü¦V¤F¥t¥~¤@­Ó·s¹ï¶H¡I¦Óstr2¤´Â«ü¦V­ì¨Óªº¹ï¶H¡C¤W¨Ò¤¤¡A·í§Ú­Ì±Nstr1ªº­È§ï¬°"bcd"®É¡AJVMµo²{¦b´Ì¤¤¨S¦³¦s©ñ¸Ó­Èªº¦a§}¡A«K¶}ÅP¤F³o­Ó¦a§}¡A¨Ã³Ð«Ø¤F¤@­Ó·sªº¹ï¶H¡A¨ä¦r²Å¦êªº­È«ü¦V³o­Ó¦a§}¡C

¨Æ¹ê¤W¡AStringÃþ³Q³]­p¦¨¬°¤£¥i§ïÅÜ(immutable)ªºÃþ¡C¦pªG§A­n§ïÅܨä­È¡A¥i¥H¡A¦ýJVM¦b¹B¦æ®É®Ú¾Ú·s­È®¨®¨³Ð«Ø¤F¤@­Ó·s¹ï¶H¡AµM«á±N³o­Ó¹ï¶Hªº¦a§}ªð¦^µ¹­ì¨ÓÃþªº¤Þ¥Î¡C³o­Ó³Ð«Ø¹Lµ{Áö»¡¬O§¹¥þ¦Û°Ê¶i¦æªº¡A¦ý¥¦²¦³º¦û¥Î¤F§ó¦hªº®É¶¡¡C¦b¹ï®É¶¡­n¨D¤ñ¸û±Ó·PªºÀô¹Ò¤¤¡A·|±a¦³¤@©wªº¤£¨}¼vÅT¡C

¦A­×§ï­ì¨Ó¥N½X¡G

String str1 = "abc";
String str2 = "abc";

str1 = "bcd";

String str3 = str1;
System.out.println(str3); //bcd

String str4 = "bcd";
System.out.println(str1 == str4); //true

str3³o­Ó¹ï¶Hªº¤Þ¥Îª½±µ«ü¦Vstr1©Ò«ü¦Vªº¹ï¶H(ª`·N¡Astr3¨Ã¨S¦³³Ð«Ø·s¹ï¶H)¡C·ístr1§ï§¹¨ä­È«á¡A¦A³Ð«Ø¤@­ÓStringªº¤Þ¥Îstr4¡A¨Ã«ü¦V¦]str1­×§ï­È¦Ó³Ð«Øªº·sªº¹ï¶H¡C¥i¥Hµo²{¡A³o¦^str4¤]¨S¦³³Ð«Ø·sªº¹ï¶H¡A±q¦Ó¦A¦¸¹ê²{´Ì¤¤¼Æ¾Úªº¦@¥Î¡C

§Ú­Ì¦A±µµÛ¬Ý¥H¤Uªº¥N½X¡C

String str1 = new String("abc");
String str2 = "abc";
System.out.println(str1==str2); //false

³Ð«Ø¤F¨â­Ó¤Þ¥Î¡C³Ð«Ø¤F¨â­Ó¹ï¶H¡C¨â­Ó¤Þ¥Î¤À§O«ü¦V¤£¦Pªº¨â­Ó¹ï¶H¡C

String str1 = "abc";
String str2 = new String("abc");
System.out.println(str1==str2); //false

³Ð«Ø¤F¨â­Ó¤Þ¥Î¡C³Ð«Ø¤F¨â­Ó¹ï¶H¡C¨â­Ó¤Þ¥Î¤À§O«ü¦V¤£¦Pªº¨â­Ó¹ï¶H¡C

¥H¤W¨â¬q¥N½X»¡©ú¡A¥u­n¬O¥Înew()¨Ó·s«Ø¹ï¶Hªº¡A³£·|¦b°ï¤¤³Ð«Ø¡A¦Ó¥B¨ä¦r²Å¦ê¬O³æ¿W¦s­Èªº¡A§Y¨Ï»P´Ì¤¤ªº¼Æ¾Ú¬Û¦P¡A¤]¤£·|»P´Ì¤¤ªº¼Æ¾Ú¦@¥Î¡C

6. ¼Æ¾ÚÃþ«¬¥]¸ËÃþªº­È¤£¥i­×§ï¡C¤£¶È¶È¬OStringÃþªº­È¤£¥i­×§ï¡A©Ò¦³ªº¼Æ¾ÚÃþ«¬¥]¸ËÃþ³£¤£¯à§ó§ï¨ä¤º³¡ªº­È¡C 7. µ²½×»P«Øij¡G

(1)§Ú­Ì¦b¨Ï¥Î½Ñ¦pString str = "abc"¡Fªº®æ¦¡©w¸qÃþ®É¡AÁ`¬O·Q·íµM¦a»{¬°¡A§Ú­Ì³Ð«Ø¤FStringÃþªº¹ï¶Hstr¡C¾á¤ß³´¨À¡I¹ï¶H¥i¯à¨Ã¨S¦³³Q³Ð«Ø¡I°ß¤@¥i¥HªÖ©wªº¬O¡A«ü¦VStringÃþªº¤Þ¥Î³Q³Ð«Ø¤F¡C¦Ü©ó³o­Ó¤Þ¥Î¨ì©³¬O§_«ü¦V¤F¤@­Ó·sªº¹ï¶H¡A¥²Å½®Ú¾Ú¤W¤U¤å¨Ó¦Ò¼{¡A°£«D§A³q¹Lnew()¤èªk¨ÓÅã­n¦a³Ð«Ø¤@­Ó·sªº¹ï¶H¡C¦]¦¹¡A§ó¬°·Ç½Tªº»¡ªk¬O¡A§Ú­Ì³Ð«Ø¤F¤@­Ó«ü¦VStringÃþªº¹ï¶Hªº¤Þ¥ÎÅܼÆstr¡A³o­Ó¹ï¶H¤Þ¥ÎÅܼƫü¦V¤F¬Y­Ó­È¬°"abc"ªºStringÃþ¡C²M¿ô¦a»{ÃѨì³o¤@ÂI¹ï±Æ°£µ{¦¡¤¤Ãø¥Hµo²{ªºbug¬O«Ü¦³À°§Uªº¡C

(2)¨Ï¥ÎString str = "abc"¡Fªº¤è¦¡¡A¥i¥H¦b¤@©wµ{«×¤W´£°ªµ{¦¡ªº¹B¦æ³t«×¡A¦]¬°JVM·|¦Û°Ê®Ú¾Ú´Ì¤¤¼Æ¾Úªº¹ê»Ú±¡ªp¨Ó¨M©w¬O§_¦³¥²­n³Ð«Ø·s¹ï¶H¡C¦Ó¹ï©óString str = new String("abc")¡Fªº¥N½X¡A«h¤@·§¦b°ï¤¤³Ð«Ø·s¹ï¶H¡A¦Ó¤£ºÞ¨ä¦r²Å¦ê­È¬O§_¬Ûµ¥¡A¬O§_¦³¥²­n³Ð«Ø·s¹ï¶H¡A±q¦Ó¥[­«¤Fµ{¦¡ªº­t¾á¡C³o­Ó«ä·QÀ³¸Ó¬O¨É¤¸¼Ò¦¡ªº«ä·Q¡A¦ýJDKªº¤º³¡¦b³o¸Ì¹ê²{¬O§_À³¥Î¤F³o­Ó¼Ò¦¡¡A¤£±o¦Óª¾¡C

(3)·í¤ñ¸û¥]¸ËÃþùØ­±ªº¼Æ­È¬O§_¬Ûµ¥®É¡A¥Îequals()¤èªk¡F·í´ú¸Õ¨â­Ó¥]¸ËÃþªº¤Þ¥Î¬O§_«ü¦V¦P¤@­Ó¹ï¶H®É¡A¥Î==¡C

(4)¥Ñ©óStringÃþªºimmutable©Ê½è¡A·íStringÅܼƻݭn¸g±`ÅÜ´«¨ä­È®É¡AÀ³¸Ó¦Ò¼{¨Ï¥ÎStringBufferÃþ¡A¥H´£°ªµ{¦¡®Ä²v¡C




http://big5.ccidnet.com:89/gate/ ... 0225/1370149_1.html

TOP

§Ú们学®Õ¤]¦³这门课,¥i¬O¤£«ç¤\¯à学会,·Q来这学学 请°²¤j®a

TOP

µo·s¸ÜÃD


­«­nÁn©ú¡G¥»°Q½×°Ï¬O¥H§Y®É¤W¸ü¯d¨¥ªº¤è¦¡¹B§@¡A¥»ºô¯¸¹ï©Ò¦³¯d¨¥ªº¯u¹ê©Ê¡B§¹¾ã©Ê¤Î¥ß³õµ¥¡A¤£­t¥ô¦óªk«ß³d¥ô¡C¦Ó¤@¤Á¯d¨¥¤§¨¥½×¥u¥Nªí¯d¨¥ªÌ­Ó¤H·N¨£¡A¨Ã«D¥»ºô¯¸¤§¥ß³õ¡A¥Î¤á¤£À³«H¿à¤º®e¡A¨ÃÀ³¦Û¦æ§PÂ_¤º®e¤§¯u¹ê©Ê¡C©ó¦³Ãö±¡§Î¤U¡A¥Î¤áÀ³´M¨D±M·~·N¨£(¦p¯A¤ÎÂåÀø¡Bªk«ß©Î§ë¸êµ¥°ÝÃD)¡C¥Ñ©ó¥»°Q½×°Ï¨ü¨ì¡u§Y®É¤W¸ü¯d¨¥¡v¹B§@¤è¦¡©Ò³W­­¡A¬G¤£¯à§¹¥þºÊ¹î©Ò¦³¯d¨¥¡A­YŪªÌµo²{¦³¯d¨¥¥X²{°ÝÃD¡A½ÐÁpµ¸§Ú­Ì¡C¥»°Q½×°Ï¦³Åv§R°£¥ô¦ó¯d¨¥¤Î©Úµ´¥ô¦ó¤H¤h¤W¸ü¯d¨¥¡A¦P®É¥ç¦³¤£§R°£¯d¨¥ªºÅv§Q¡C¤Á¤Å¼¶¼g²Ê¨¥Â©»y¡B½ÚÁ½¡B´è¬V¦â±¡¼É¤O©Î¤H¨­§ðÀ»ªº¨¥½×¡A·q½Ð¦Û«ß¡C¥»ºô¯¸«O¯d¤@¤Áªk«ßÅv§Q¡C


Copyright 1997- Xocat. All Right Reserved.