ÓÉÒ»µÀÌâÀ´¿´java³õʼ»¯Ë³Ðò
½ñÌì¿´µ½Ò»µÀÌâÄ¿£¬ÊÇÕâÑùµÄ£º£¨ÎÒÔÚÀïÃæ´òÓ¡ÁËһЩÓï¾ä£¬ÏÈ×¢Ê͵ôÁË£©
class Singleton {
private static Singleton obj= new Singleton();
public static int counter1;
public static int counter2 = 2;
private Singleton() {
counter1++;
counter2++;
// System.out.println("Singleton counter1:" + counter1);
// System.out.println("Singleton counter1:" + counter2);
}
public static Singleton getInstance() {
// System.out.println(obj.counter2 + obj.counter1);
return obj;
}
}
public class Test {
public static void main(String[] args) {
// System.out.println("Singleton.counter1:" + Singleton.counter1);
// System.out.println("Singleton.conuter2:" + Singleton.counter2);
// System.out.println("¾²Ì¬±äÁ¿¼°¹¹Ô캯ÊýÒѾ³õʼ»¯¸½ÖµÍê±Ï");
Singleton obj =Singleton.getInstance();
System.out.println("obj.counter1==" + obj.counter1);
System.out.println("obj.counter2==" + obj.counter2);
}
}
´òÓ¡µÄ½á¹ûΪ1¡¢2£»
µ±È»Èç¹û¶Ô³õʼ»¯Ë³ÐòºÜÁ˽âµÄÈË£¬»á¾õµÃÕâµÀÌâÆäʵ²»Õ¦µÄ¡£¡£ÏÂÃæÎÒ¸ø·ÖÎöÒ»ÏÂÕâµÀÌâ°É
Õâʱºò°Ñ×¢ÊÍ·Å¿ª£¬´òÓ¡½á¹ûÈçÏ£º
Singleton counter1:1
Singleton counter1:1
Singleton.counter1:1
Singleton.conuter2:2
¾²Ì¬±äÁ¿¼°¹¹Ô캯ÊýÒѾ³õʼ»¯¸½ÖµÍê±Ï
3
obj.counter1==1
obj.counter2==2
Ôڵõ½ÊµÀý»¯Ö®Ç°£¬³ÌÐòÏÈÈ¥ÔËÐÐËüµÄstatic±äÁ¿£¬Ò²¾ÍÊÇ×îÉÏÃæµÄµÚÒ»¾ä»°£¬ÓÉÕâ¾ä»°°Ñcounter1ºÍcounter2µÄÖµ±äΪ1£¬Ò»¿ªÊ¼ËüÃǶ¼Ä¬ÈÏΪ0£¬ÒòΪnew³öʵÀýÊÇÔÚstatic int counterºÍstatic int counter2֮ǰ¡£¡£³ÌÐòµÄÖ´ÐÐÊÇÓÐ˳ÐòµÄ£¬Ò²¾ÍÊDZäΪ1ºó£¬
public static int counter1;
public static int counter2 = 2;
ÕâÁ½²½ÓÖ¶Ô±äÁ¿ÖØи³Öµ£¬Òò´Ëµ¼ÖÂ×îºóµÄ½á¹ûÊÇ1¡¢2¡£¡£
ΪÁË֤ʵÎÒµÄÏë·¨£¬¿É°Ñprivate static Singleton obj= new Singleton();ÒƵ½µÚ¶þÌõÈ¥»òÕßµÚÈýÌõÈ¥£¬³öÀ´µÄ½á¹ûÊDz»Ò»ÑùµÄ¡£¡£
×ܽáһϳõʼ»¯µÄ˳Ðò£º1¡¢¾²Ì¬±äÁ¿£»2¡¢¾²Ì¬³õʼ»¯¿é£¬¼´ÓÃ{}£¬Ã»Óз½·¨ÃûÎÞ·µ»ØÖµ£»3¡¢±äÁ¿£»4¡¢³õʼ»¯¿é£»5¡¢¹¹ÔìÆ÷¡£
¾²Ì¬±äÁ¿µÄ¸³ÖµÓÐÒ»¶¨µÄÏȺó˳Ðò£¡
Ïà¹ØÎĵµ£º
ÔÚjavaÓïÖÐGC
¼´À¬»øÊÕ¼¯»úÖÆÊÇÖ¸jvmÓÃÓÚÊÍ·ÅÄÇЩ²»ÔÙʹÓõĶÔÏóËùÕ¼ÓõÄÄÚ´æ¡£javaÓïÑÔ²¢²»ÒªÇójvmÓÐgc£¬Ò²Ã»Óй涨gcÈçºÎ¹¤×÷¡£²»¹ý³£ÓõÄjvm¶¼ÓÐgc£¬¶øÇÒ´ó¶àÊýgc¶¼Ê¹ÓÃÀàËƵÄËã·¨¹ÜÀíÄÚ´æºÍÖ´ÐÐÊÕ¼¯²Ù×÷¡£
À¬»øÊÕ¼¯µÄÄ¿µÄÔÚÓÚÇå³ý²»ÔÙʹÓõĶÔÏó¡£gcͨ¹ýÈ·¶¨¶ÔÏóÊÇ·ñ±»»î¶¯¶ ......
1.дһ¸öðÅÝÅÅÐòµÄ³ÌÐò¡£
public class Sort
{
public static void main(String[] args)
{
&n ......
1.ʹÓÃjava.util.PropertiesÀàµÄload()·½·¨
¡¡¡¡
¡¡¡¡Ê¾Àý£º
Java´úÂë
InputStream in = lnew BufferedInputStream(new FileInputStream(name));
¡¡¡¡Properties p = new Properties();
¡¡¡¡p.load(in);
InputStream ......
ÔÚ½ñÄê11Ô·ݣ¬ºêÌìÈí¼þ¿ª·ÅÁ˹«Ë¾µÄ¿ªÔ´°æOA 1.2
beta°æ±¾£¬µÃµ½Í¬ÐÐÒÔ¼°ÆóÒµµÄÈÈÁÒÏìÓ¦£¬¹«Ë¾Ò²¼Ó½ôÁËÏÂÒ»²½µÄ¿ªÔ´µÄ²½·¥£¬ºêÌìÈí¼þ°ÑÏÖÐеÄÆóÒµ°æ1.2.1Ò²¶ÔËùÓÐÆóÒµ¿ª·ÅÔ´´úÂ루ÔÝʱ²»¶Ô¸öÈË¿ª
·Å£¬ËäȻĿǰÓкܶà¸öÈ˼°Èí¼þ¿ª·¢ÊÒÇ¿ÁÒÒªÇ󣩣¬ÆóÒµÖ»ÐèÒª»¨ÉÏÍòÔª×óÓÒ£¬¾Í¿ÉÒÔ¹ºÂò¸Ã°æ±¾µÄÈ«²¿´úÂ룬²¢»ñµÃÊÚȨ»ùÓÚ´ËÏ ......
JavaÐÂÊÖÁôÒ⣺Java±à³ÌÈýÊ®Ìõ¹æÔò
¡¡¡¡(1) ÀàÃûÊ××ÖĸӦ¸Ã´óд¡£×ֶΡ¢·½·¨ÒÔ¼°¶ÔÏ󣨾ä±ú£©µÄÊ××ÖĸӦСд¡£¶ÔÓÚËùÓбêʶ·û£¬ÆäÖаüº¬µÄËùÓе¥´Ê¶¼Ó¦½ô¿¿ÔÚÒ»Æ𣬶øÇÒ´óдÖм䵥´ÊµÄÊ××Öĸ¡£ÀýÈ磺
ThisIsAClassName
thisIsMethodOrFieldName
¡¡¡¡ÈôÔÚ¶¨ÒåÖгöÏÖÁ˳£Êý³õʼ»¯×Ö·û£¬Ôò´óдstati ......