2006年8月10日

          一直有留意Firefox對IE的沖擊,不過以前用IE也并沒覺得有什么大問題,就一直用下來。

          直到最近的IE老出問題,公司派的本本裝的是win2000,用久了里面的IE經常會彈出一個crash的對話框(似乎在XP里就很少見),然后所有打開的IE窗口都只能關閉,解決無方,于是想到了Firefox,試用一下,第一感覺是非???,不管是load firefox還是打開新的網頁,基本上都是文字刷一下就出來,圖片則延遲了點,不過還是比IE做得好:) 很多小的細節都考慮得比較符合用戶的操作習慣,比如工具欄有一個下載的管理器,管理最近下載的咚咚,不用第三方軟件,而且Firefox比IE小巧多了(4.8M),Simple is beautiful,呵呵,I like it.
          posted @ 2006-08-20 23:26 響 閱讀(167) | 評論 (1)編輯 收藏
           

          Q If Java uses the pass-by reference, why won't a swap function work?

          AYour question demonstrates a common error made by Java language newcomers. Indeed, even seasoned veterans find it difficult to keep the terms straight.

          Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.

          Take the badSwap() method for example:


          public void badSwap(int var1, int var2)
          {
          ??int temp = var1;
          ??var1 = var2;
          ??var2 = temp;
          }

          When badSwap() returns, the variables passed as arguments will still hold their original values. The method will also fail if we change the arguments type from int to Object, since Java passes object references by value as well.

          Now, here is where it gets tricky:


          public void tricky(Point arg1, Point arg2)
          {
          ??arg1.x = 100;
          ??arg1.y = 100;

          ??Point temp = arg1;
          ??arg1 = arg2;
          ??arg2 = temp;
          }

          public static void main(String [] args)
          {
          ??Point pnt1 = new Point(0,0);
          ??Point pnt2 = new Point(0,0);
          ??System.out.println("X: " + pnt1.x + " Y: " +pnt1.y);
          ??System.out.println("X: " + pnt2.x + " Y: " +pnt2.y);
          ??System.out.println(" ");
          ??tricky(pnt1,pnt2);
          ??System.out.println("X: " + pnt1.x + " Y:" + pnt1.y);
          ??System.out.println("X: " + pnt2.x + " Y: " +pnt2.y);??
          }

          If we execute this main() method, we see the following output:


          X: 0 Y: 0
          X: 0 Y: 0

          X: 100 Y: 100
          X: 0 Y: 0

          The method successfully alters the value of pnt1, even though it is passed by value; however, a swap of pnt1 and pnt2 fails! This is the major source of confusion. In the main() method, pnt1 and pnt2 are nothing more than object references. When you pass pnt1 and pnt2 to the tricky() method, Java passes the references by value just like any other parameter. This means the references passed to the method are actually copies of the original references. Figure 1 below shows two references pointing to the same object after Java passes an object to a method.


          Figure 1. After being passed to a method, an object will have at least two references

          Java copies and passes the reference by value, not the object. Thus, method manipulation will alter the objects, since the references point to the original objects. But since the references are copies, swaps will fail. As Figure 2 illustrates, the method references swap, but not the original references. Unfortunately, after a method call, you are left with only the unswapped original references. For a swap to succeed outside of the method call, we need to swap the original references, not the copies.


          Figure 2. Only the method references are swapped, not the original ones

          O'Reilly's Java in a Nutshell by David Flanagan (see Resources) puts it best: "Java manipulates objects 'by reference,' but it passes object references to methods 'by value.'" As a result, you cannot write a standard swap method to swap objects.

          Resources

          posted @ 2006-08-17 22:00 響 閱讀(297) | 評論 (0)編輯 收藏
           
          http://www.physics.orst.edu/~rubin/nacphy/brian/socket.html
          另外關于Java network的一些基礎的教程:
          http://java.sun.com/docs/books/tutorial/networking/index.html
          posted @ 2006-08-17 10:01 響 閱讀(715) | 評論 (0)編輯 收藏
           
          http://www-128.ibm.com/developerworks/cn/java/j-jtp05273/
          不過翻譯得比較爛,還是看英文吧:
          http://www-128.ibm.com/developerworks/library/j-jtp05273.html
          posted @ 2006-08-10 11:02 響 閱讀(232) | 評論 (0)編輯 收藏
           
          主站蜘蛛池模板: 铁岭县| 兴文县| 德令哈市| 麻城市| 富阳市| 克拉玛依市| 洱源县| 台州市| 东兰县| 潞西市| 马尔康县| 吴江市| 莱西市| 吉水县| 辽中县| 新巴尔虎左旗| 阜城县| 德惠市| 出国| 高阳县| 凤山市| 沐川县| 上犹县| 乐亭县| 延吉市| 安达市| 论坛| 台中县| 长沙市| 化隆| 桐梓县| 上思县| 泽库县| 沭阳县| 湘阴县| 博湖县| 湟中县| 容城县| 措勤县| 鹤岗市| 西青区|