javaÖеĹؼü×Ö(staticºÍfinal)
ÕâƪÎÄÕ²»ÊǶÔprivate£¬public£¬protected½øÐÐ˵Ã÷£¬Ö»ÒªÑ§¹ýÃæÏò¶ÔÏóµÄ³ÌÐòÉè¼Æ£¬¶ÔÒÔÉÏÈý¸ö¹Ø¼üÔÙÊìϤ²»¹ýÁË¡£ÕâÀïҪ˵µÄÊÇÁíÍâÁ½¸ö¹Ø¼ü×Ö---staticºÍfinal¡£
1. static¹Ø¼ü×Ö
ÔÚÎÒÃÇ´´½¨Ò»¸öÀàµÄʵÀýʱ£¨¶ÔÏ󣩣¬Í¨³£Ê¹ÓÃnew·½·¨£¬ÕâÑùÕâ¸öÀàµÄÊý¾Ý¿Õ¼ä²Å»á±»´´½¨£¬Æä·½·¨²ÅÄܱ»µ÷Óá£
µ«ÊÇ£¬ÓÐʱºòÎÒÃÇÏ£ÍûÒ»¸öÀàËäÈ»¿ÉÒÔ±»´´½¨n¸ö¶ÔÏó£¨ÏÔÈ»Õân¸ö¶ÔÏóµÄÊý¾Ý¿Õ¼äÊDz»ÏàͬµÄ£©£¬µ«Õân¸ö¶ÔÏóµÄijЩÊý¾ÝÊÇÏàͬµÄ£¬¼´²»¹ÜÕâ¸öÀàÓжàÉÙµÄʵÀý£¬ÕâЩÊý¾Ý¶ÔÕâЩʵÀý¶øÑÔÖ®ÓÐÒ»·ÝÄڴ濽±´¡£»¹ÓÐÕâÖÖÇé¿ö£¬¼´ÓÐʱϣÍûij¸ö·½·¨²»Óë°üº¬ËüµÄÀàµÄÈκÎʵÀý£¨¶ÔÏó£©ÁªÏµÔÚÒ»Æð¡£¼´Ê¹Ã»Óд´½¨¶ÔÏó£¬Ò²Äܵ÷ÓÃÕâ¸ö·½·¨¡£
ͨ¹ýstatic¾ÍÄÜʵÏÖÕâÑùÁ½¸öÄ¿µÄ£¬static¹Ø¼ü×Ö¿ÉÒÔÓÃÓÚÊôÐԺͷ½·¨¡£
ÏÂÃæÊÇThinking in javaÖжÔstaticµÄÒ»¶Î¾«±Ù²ûÊö¡£
µ±ÉùÃ÷Ò»¸öÊÂÎïÊÇstaticʱ£¬¾ÍÒâζ×ÅÕâ¸öÊý¾Ý»ò·½·¨²»»áÓë°üº¬ËüµÄÄǸöÀàµÄÈκζÔÏóʵÀý¹ØÁªÔÚÒ»Æð¡£ËùÒÔ£¬¼´Ê¹´Óδ´´½¨Ä³¸öÀàµÄÈκζÔÏó£¬Ò²¿ÉÒÔµ÷ÓÃÆästatic·½·¨»ò·ÃÎÊÆästaticÊý¾Ý¡£
Àý£º¶ÔÓÚ¾²Ì¬ÊôÐÔ
class StaticTest{
public static int i = 0;
}
¶ÔÓÚÉÏÃæÕâ¸öÀ࣬¼´Ê¹ÎÒÃDz»´´½¨ËûµÄʵÀý£¬Ò²¿ÉÒÔÒýÓÃÆäiÊôÐÔ£¬ÒýÓ÷½·¨ºÜ¼òµ¥ÔÚÁíÍâÒ»¸öµØ·½Ê¹ÓÃStaticTest.i¼´¿ÉµÃµ½Õâ¸öÊôÐÔµÄÖµ¡£
¶ÔÓÚ¾²Ì¬·½·¨
class StaticFunc{
public static int incr(int i){
i++;
return i;
}
}
ÔÚÍⲿ£¬¿ÉÒÔÖ±½ÓʹÓÃStaitcFunc.incr(8)µÄ·½Ê½µ÷ÓÃÕâ¸ö·½·¨¡£ÐèҪ˵Ã÷µÄÊÇÔÚstatic·½·¨ÖÐҩʹÓÃÍⲿ±äÁ¿Ê±£¬Õâ¸öÍⲿ±äÁ¿Ò²ÒªÎªstaticÀàÐÍ£¨Õâµã²»ÄÑÀí½â£©¡£
2. final¹Ø¼ü×Ö
¹ÊÃû˼Ò壬final¼´×îºóµÄ£¬×îÖյģ¬²»¿É¸Ä±äµÄ¡£Êµ¼ÊÉÏ£¬ÔÚjavaÖУ¬finalµÄ×÷ÓÃÒ²»ù±¾ÉÏÊÇÕâÑùµÄ£¬ÆäÔÒò¿ÉÄÜÊdzöÓÚЧÂÊ»òÉè¼Æ¡£final¹Ø¼ü×Ö¿ÉÒÔÓ¦ÓÃÓÚÊôÐÔ£¬·½·¨ºÍÀà¡£µ±È»ÔÚÕâÈý¸ö·½ÃæµÄÓ¦ÓÃÊÇÓÐϸ΢²î±ðµÄ¡£
(1)finalÊý¾Ý
ʹÓÃfinalÊý¾Ý£¬Ä¿µÄÊÇÏë¸æËß±àÒëÆ÷Õâ¸öÊý¾ÝÒ»¾³õʼ»¯¾Í²»»áÔٸı䡣
¶ÔÓÚ»ù±¾ÀàÐÍ£¬finalʹÊýÖµºã¶¨²»±ä£¬Ò»¸ö¼ÈÊÇstaticÓÖÊÇfinalµÄ×Ö¶Î
Ïà¹ØÎĵµ£º
keytoolÉú³ÉÖ¤Êé
ÑéÖ¤ÊÇ·ñÒÑ´´½¨¹ýͬÃûµÄÖ¤Êé
keytool -list -v -alias tomcat -keystore "%JAVA_HOME%/JRE/LIB/SECURITY/CACERTS" -storepass changeit
ɾ³ýÒÑ´´½¨µÄÖ¤Êé
keytool -delete -alias tomcat -keystore "%JAVA_HOME%/JRE/LIB/SECURITY/CACERTS" -storepass changeit
´´½¨Ö¤Êé
1.·þÎñ ......
δÍê³É ´ýÍêÉÆ
public class MagicCube {
/**
* Áù¸öÃæµÄϱêÖµ
* ¡õ5
* ¡õ¡õ¡õ¡õ 1234 ÕâËĸöÁ¬ÌåÕý·½ÐÎÏòºó˳ʱÕë°üΧ ÐγÉͲ״ È»ºó °Ñ5ºÍ6¿ÛÉÏ ¾ÍÐγÉÕý·½Ìå
* ¡õ6
*/
public static void main(String[] args) {
MagicCube mb = new MagicCube();
int i = 0;
for (Face f : mb.faces ......
2009Äê10ÔÂ25ÈÕ£¬µÃÒ»Êéµê200ÔªÂòÁËËı¾Êéj2se»ù´¡½Ì³Ì£¬j2eeÓ¦Óÿª·¢Ïê½â£¬javaÏîÄ¿¿ª·¢È«³Ìʵ¼£¬java web¿ª·¢ËÙѧ±¦µäÊ鿪ʼ
2010Äê2ÔÂ3ÈÕ£¬µÚÒ»Ì×»ùÓÚú¿ó°²È«¹ÜÀíµÄÈí¼þÄ£Ðͼ°Æ䲿·Ö´úÂë³ÉÐÍ
Èý¸öÔ£¬ÕâÊÇÒ»³¡Ø¬ÃΣ¬²»¹ýÕâÈý¸öÔ£¬ÓÖÊÇÒ»ÖÖ¾ªÏ²ºÍ¿ìÀÖ
´ÓÊý¾ÝÀàÐÍ£¬Óï·¨½á¹¹£¬jdk ¹ýÑ»·£¬´³Êý×飬¼¯ºÏ£¬µü´ú£¬¶ÓÁУ ......
1.²ð·Ö×Ö·û´®
Óöµ½ÌØÊâ×Ö·û£¬±ÈÈ磺¶Ô‘$’·ûºÅ£¬¾ÍÓ¦¸ÃʹÓÑ\\$’£¬ºó×ܽá¿ÉÒÔ¼Ó¸ö·½À¨ºÅÈç "[.]"¡£
2.±éÀúHASHMAP
Iterator itr = map.keySet().itrator();
while(itr.hasNext())
{
Object temp1 = itr.next();
Object temp2 = tab.get(temp1);
}
......