隨筆-8  評論-0  文章-0  trackbacks-0
            2005年8月10日
           
          public class NullPointerException
          extends RuntimeException

          當一個應用在需要一個對象的地方試圖使用 null 時拋出。它們包括:

          • 調用一個 null 對象的實例方法。
          • 訪問或修改一個 null 對象的域。
          • null 作為一個數組,使用它的長度。
          • null 作為一個數組,訪問或修改它的插口。
          • null 作為一個 Throwable 值拋出。

          應用應該拋出該類的實例,指示其它對 null 對象的非法使用。






          構造子索引

          NullPointerException()
          構造一個沒有詳細消息的 NullPointerException
          NullPointerException(String)
          構造一個具有指定詳細消息的 NullPointerException




          構造子

          NullPointerException
           public NullPointerException()
          
          構造一個沒有詳細消息的 NullPointerException

          NullPointerException
           public NullPointerException(String s)
          
          構造一個具有指定詳細消息的 NullPointerException

          參數:
          s - 詳細消息。

          posted @ 2005-08-25 13:43 hegen 閱讀(1024) | 評論 (0)編輯 收藏
           Single inheritance precludes some useful and correct designs.The problems of multiple inheritance arise from multiple inheritance of implememtion, but in many cases multiple inheritance is used to inhert a number of abstract contracts and perhaps one concrete implementtation.Providing a means to inherit an abstract contract without inheriting an implementation allows the typing benefits of multiple inheritance without the problems of multiple implementation inheritance.The inheritance of an abstract contract is termed interface inhertiance.
          posted @ 2005-08-25 02:14 hegen 閱讀(188) | 評論 (0)編輯 收藏
           看完了程功的故事后,感到只有穩扎穩打才是真,只有努力才能成功,我是笨鳥,笨鳥只有以勤補拙,笨鳥是要先飛的.
          posted @ 2005-08-18 00:44 hegen 閱讀(175) | 評論 (0)編輯 收藏
          Garbage Collection
          State the behavior that is guaranteed by the garbage collection system and write code that explicitly makes objects eligible for collection.
          1.    Garbage collection is a mechanism for reclaiming memory from objects that are no longer in use, and making the memory available for new objects.
          2.    An object being no longer in use means that it can’t be referenced by any ‘active’ part of the program.
          3.    Garbage collection runs in a low priority thread. It may kick in when memory is too low. No guarantee.
          4.    It’s not possible to force garbage collection. Invoking System.gc may start garbage collection process.
          5.    There are no guarantees that the objects no longer in use will be garbage collected and their finalizers executed at all. gc might not even be run if the program execution does not warrant it. Thus any memory allocated during program execution might remain allocated after program termination, unless reclaimed by the OS or by other means.
          6.    There are also no guarantees on the order in which the objects will be garbage collected or on the order in which the finalizers are called.
          7.    Circular references do not prevent objects from being garbage collected.
          8.    We can set the reference variables to null, hinting the gc to garbage collect the objects referred by the variables. Even if we do that, the object may not be gc-ed if it’s attached to a listener. (Typical in case of AWT components) Remember to remove the listener first.
          9.    All objects have a finalize method. It is inherited from the Object class.
          10.    finalize method is used to release system resources other than memory. (such as file handles and network connections) The order in which finalize methods are called may not reflect the order in which objects are created. Don’t rely on it. This is the signature of the finalize method.
          protected void finalize() throws Throwable { }
          In the descendents this method can be protected or public. Descendents can restrict the exception list that can be thrown by this method.
          11.    finalize is called only once for an object. If any exception is thrown in finalize, the object is still eligible for garbage collection (at the discretion of gc)
          12.    gc keeps track of unreachable objects and garbage-collects them, but an unreachable object can become reachable again by letting know other objects of its existence from its finalize method (when called by gc). This ‘resurrection’ can be done only once, since finalize is called only one for an object.
          13.    finalize can be called explicitly, but it does not garbage collect the object.
          14.    finalize can be overloaded, but only the method with original finalize signature will be called by gc.
          15.    finalize is not implicitly chained. A finalize method in sub-class should call finalize in super class explicitly as its last action for proper functioning. But compiler doesn’t enforce this check.
          16.    System.runFinalization can be used to run the finalizers (which have not been executed before) for the objects eligible for garbage collection.
          17.    Local variables in methods go out of scope when the method exits. At this point the methods are eligible for garbage collection. Each time the method comes into scope the local variables are re-created.  
          18.    Java uses a "mark sweep garbage collection algorithm, which traverses all the object references, marking any objects that are referred to and then garbage collecting any objects that are unmarked.
          19.    Java allows you to add a finalize() method to any class. The finalize() method will be called before the garbage collector sweeps away the object. In practice, do not rely on the finalize method for recycling any resources that are in short supply - you simply cannot know when this method will be called.


          In the exam point of view :
          ??You must be able to identify when an object is available for gc - you have either set it to null or you
          have "redirected" the variable that was originally referring to it, so that it now refers to a different
          object.
          ??if you have a reference to an object say, A and then you pass A as an argument to some constructor -
          new obj(A); - then even if you null your reference - A=null; - you can't say that A is available for
          gc. So just follow the references and when they drop to zero you know its eligible/available for gc,
          not that it will happen.


          I can not full understand these statements which are above.



          eg,
          1. obj = new Jo();
          2. obj.doSomething();
          3. obj = new Jo(); //Same as obj=null;
          4. obj.doSomething();

          Object a = new Object();
          Object a=null; //Now the object created in 1st line is available for gc
          Object a=new Object();
          a = new Object(); //same.
          // Now original object created in line 1 is available for gc and a new
          object is now out there referenced by "a".

          Aclass a = new Aclass(); // Object 1
          Aclass b= new Aclass(); // Object 2
          Aclass c = new Aclass(); // Object 3
          a=b; // now we have no valid object reference to object "a" and it will be
          // garbage collected sometime after this statement. But when?......
          a=c;
          c=null; // no garbage collection will be eligible since
          // "a" still refers to Object 3
          a=null; // now object "c" is eligible for gc since it always had a valid reference.
          // Should "b" go out of scope; then we would possibly have eligibility for gc.
          // there might still be other references to object "b" preventing the collection.
          posted @ 2005-08-11 13:46 hegen 閱讀(243) | 評論 (0)編輯 收藏

          Text Color Codes

          In order to change text colors, you will need two things:

          1. A command to change the text.
          2. A color (hex) code.


          Changing Full-Page Text ColorsYou have the ability to change full-page text colors over four levels:

          <TEXT="######"> -- This denotes the full-page text color.

          <LINK="######"> -- This denotes the color of the links on your page.

          <ALINK="######"> -- This denotes the color the link will flash when clicked upon.

          <VLINK="######"> -- This denotes the colors of the links after they have been visited.

          These commands come right after the <TITLE> commands. Again, in that position they affect everything on the page. Also... place them all together inside the same command along with any background commands. Something like this:

          < BODY BGCOLOR="######" TEXT="######" LINK="######" VLINK="######">

          Please note: When you write these codes, you can write them with a # sign in front of the hex code or not. It used to be that that was required, but not any more. I still use it just because I started that way. You may want to just go with the six-digit code. Also make sure to place a space between each command and be sure to enclose it in quotation marks, like so:

          <VLINK="#FFFFFF">

          問題:
            上面的那幾個東西還沒有搞懂.不知道什么用?


          Changing Specific Word ColorBut I only want to change one word's color!

          You'll use a color (hex) code to do the trick. Follow this formula:

          <FONT COLOR="######">text text text text text</FONT>

          It's a pain in the you-know-where, but it gets the job done. It works with all H commands and text size commands. Basically, if it's text, it will work.


          posted @ 2005-08-10 20:48 hegen 閱讀(327) | 評論 (0)編輯 收藏

          Please note:
          "Aqua" and "Cyan" produce the same color: 00FFFF
          "Fuchsia" and "Magenta" produce the same color: FF00FF

          Aliceblue
          F0F8FF
          Antiquewhite
          FAEBD7
          Aqua
          00FFFF
          Aquamarine
          7FFFD4
          Azure
          F0FFFF
          Beige
          F5F5DC
          Bisque
          FFE4C4
          Black
          000000
          Blanchedalmond
          FFEBCD
          Blue
          0000FF
          Blueviolet
          8A2BE2
          Brown
          A52A2A
          Burlywood
          DEB887
          Cadetblue
          5F9EA0
          Chartreuse
          7FFF00
          Chocolate
          D2691E
          Coral
          FF7F50
          Cornflowerblue
          6495ED
          Cornsilk
          FFF8DC
          Crimson
          DC143C
          Cyan
          00FFFF
          Darkblue
          00008B
          Darkcyan
          008B8B
          Darkgoldenrod
          B8860B
          Darkgray
          A9A9A9
          Darkgreen
          006400
          Darkkhaki
          BDB76B
          Darkmagenta
          8B008B
          Darkolivegreen
          556B2F
          Darkorange
          FF8C00
          Darkorchid
          9932CC
          Darkred
          8B0000
          Darksalmon
          E9967A
          Darkseagreen
          8FBC8F
          Darkslateblue
          483D8B
          Darkslategray
          2F4F4F
          Darkturquoise
          00CED1
          Darkviolet
          9400D3
          deeppink
          FF1493
          Deepskyblue
          00BFFF
          Dimgray
          696969
          Dodgerblue
          1E90FF
          Firebrick
          B22222
          Floralwhite
          FFFAF0
          Forestgreen
          228B22
          Fuchsia
          FF00FF
          Gainsboro
          DCDCDC
          Ghostwhite
          F8F8FF
          Gold
          FFD700
          Goldenrod
          DAA520
          Gray
          808080
          Green
          008000
          Greenyellow
          ADFF2F
          Honeydew
          F0FFF0
          Hotpink
          FF69B4
          Indianred
          CD5C5C
          Indigo
          4B0082
          Ivory
          FFFFF0
          Khaki
          F0E68C
          Lavender
          E6E6FA
          Lavenderblush
          FFF0F5
          Lawngreen
          7CFC00
          Lemonchiffon
          FFFACD
          Lightblue
          ADD8E6
          Lightcoral
          F08080
          Lightcyan
          E0FFFF
          Lightgoldenrodyellow
          FAFAD2
          Lightgreen
          90EE90
          Lightgrey
          D3D3D3
          Lightpink
          FFB6C1
          Lightsalmon
          FFA07A
          Lightseagreen
          20B2AA
          Lightskyblue
          87CEFA
          Lightslategray
          778899
          Lightsteelblue
          B0C4DE
          Lightyellow
          FFFFE0
          Lime
          00FF00
          Limegreen
          32CD32
          Linen
          FAF0E6
          Magenta
          FF00FF
          Maroon
          800000
          Mediumauqamarine
          66CDAA
          Mediumblue
          0000CD
          Mediumorchid
          BA55D3
          Mediumpurple
          9370D8
          Mediumseagreen
          3CB371
          Mediumslateblue
          7B68EE
          Mediumspringgreen
          00FA9A
          Mediumturquoise
          48D1CC
          Mediumvioletred
          C71585
          Midnightblue
          191970
          Mintcream
          F5FFFA
          Mistyrose
          FFE4E1
          Moccasin
          FFE4B5
          Navajowhite
          FFDEAD
          Navy
          000080
          Oldlace
          FDF5E6
          Olive
          808000
          Olivedrab
          688E23
          Orange
          FFA500
          Orangered
          FF4500
          Orchid
          DA70D6
          Palegoldenrod
          EEE8AA
          Palegreen
          98FB98
          Paleturquoise
          AFEEEE
          Palevioletred
          D87093
          Papayawhip
          FFEFD5
          Peachpuff
          FFDAB9
          Peru
          CD853F
          Pink
          FFC0CB
          Plum
          DDA0DD
          Powderblue
          B0E0E6
          Purple
          800080
          Red
          FF0000
          Rosybrown
          BC8F8F
          Royalblue
          4169E1
          Saddlebrown
          8B4513
          Salmon
          FA8072
          Sandybrown
          F4A460
          Seagreen
          2E8B57
          Seashell
          FFF5EE
          Sienna
          A0522D
          Silver
          C0C0C0
          Skyblue
          87CEEB
          Slateblue
          6A5ACD
          Slategray
          708090
          Snow
          FFFAFA
          Springgreen
          00FF7F
          Steelblue
          4682B4
          Tan
          D2B48C
          Teal
          008080
          Thistle
          D8BFD8
          Tomato
          FF6347
          Turquoise
          40E0D0
          Violet
          EE82EE
          Wheat
          F5DEB3
          White
          FFFFFF
          Whitesmoke
          F5F5F5
          this color model is about html
          posted @ 2005-08-10 20:37 hegen 閱讀(225) | 評論 (0)編輯 收藏

          實例形式的變壓器模式的類圖定義如下。


          圖2. 實例變壓器模式的類圖定義

          在圖1可以看出,模式所涉及的成員有:
          • 目標(Target)。這就是我們所期待得到的接口。目標可以是實的或抽象的類。

          • 源(Adaptee)。現有需要適配的接口。

          • 變壓器(Adapter)。變壓器類是本模式的核心。變壓器把源接口轉換成目標接口。 顯然,這一角色必須是實類。

            本模式的示范代碼如下:

          package com.javapatterns.adapter;
          public interface Target {
              /**
               * Class Adaptee contains operation sampleOperation1.
               */
              void sampleOperation1();
              /**
               * Class Adaptee doesn't contain operation sampleOperation2.
               */
              void sampleOperation2();
          }
          
          代碼清單4. Target的源代碼。

          package com.javapatterns.adapter;
          public class Adapter implements Target {
          public Adapter(Adaptee adaptee){
                  super();
                  this.adaptee = adaptee;
              }
              public void sampleOperation1(){
                  adaptee.sampleOperation1();
              }
              public void sampleOperation2(){
                  // Write your code here
              }
              private Adaptee adaptee;
          }
          
            代碼清單5. Adapter的源代碼。

          package com.javapatterns.adapter;
          public class Adaptee {
              public void sampleOperation1(){}
          }
          
          代碼清單6. Adaptee的源代碼。

            實例形式的變壓器模式的效果

            第一、 一個變壓器可以把多種不同的源適配到同一個目標。換言之,同一個變壓器可以把源類和它的子類都適配到目標接口。

            第二、 與類形式的變壓器模式相比,要想置換源類的方法就不容易。如果一定要置換掉源類的一個或多個方法,就只好先做一個源類的子類, 將源類的方法置換掉,然后再把源類的子類當作真正的源進行適配。

            第三、 雖然要想置換源類的方法不容易,但是要想增加一些新的方法則方便得很。 而且新增加的方法同時適用于所有的源。


          利用變壓器模式指方為圓

            中國古代有趙高指鹿為馬的故事。鹿與馬有很多相似之處,沒見過的人本就分辨不清,指一指可能沒什么大不了的。 指方為圓是否太過?非也。本例就是要指方為圓,需要的只是變壓器模式這個魔術手指(Magic Finger)。

            變壓器模式在本例子的類圖如下。


          圖6. 指方為圓的變壓器模式類圖

          package com.javapatterns.adapter.cube2ball;
          public class Cube
          {
              public Cube(double width)
              {
                  this.width = width;
              }
              public double calculateVolume()
              {
               return width * width * width;
              }
              public double calculateFaceArea()
              {
                  return width * width;
              }
              public double getWidth()
              {
                  return this.width;
              }
              public void setWidth(double width)
              {
                  this.width = width;
              }
              private double width;
          }
          
          代碼清單8. Cube類的源代碼。。

          package com.javapatterns.adapter.cube2ball;
          public interface BallIF
          {
              double calculateArea();
              double calculateVolume();
              double getRadius();
              void setRadius(double radius);
          }
          
          代碼清單9. BallIF接口的源代碼。

          package com.javapatterns.adapter.cube2ball;
          public class MagicFinger implements BallIF
          {
              public MagicFinger(Cube adaptee)
              {
                  super();
                  this.adaptee = adaptee;
                  radius = adaptee.getWidth();
              }
              public double calculateArea()
              {
                  return PI * 4.0D * ( radius * radius );
              }
              public double calculateVolume()
              {
                  return PI * 4.0D/3.0D * ( radius * radius * radius );
              }
              public double getRadius()
              {
               return radius;
              }
              public void setRadius(double radius)
              {
               this.radius = radius;
              }
              private double radius = 0;
              private static final double PI = 3.14D;
              private Cube adaptee;
          }
          
          代碼清單10. MagicFinger類的源代碼。

            如果讀者還記得中學的數學的話,應該可以看出,我們的指方為圓系統其實還是有道理的。它接受一個正方體, 返還此正方體的內切球,也就是能放進此正方體的最大的球。

            顯然,本例子里,我們使用的是實例形式的變壓器模式。這樣做的好處是,如果一旦我們決定不僅要支持正方體, 而且要支持四面體等多面體,我們可以使用同一個MagicFinger類,而不必針對每一個多面體都建立一個MagicFinger類。 這樣也比較符合“魔術手指”這個名字。
          posted @ 2005-08-10 18:40 hegen 閱讀(279) | 評論 (0)編輯 收藏
          主站蜘蛛池模板: 额尔古纳市| 安丘市| 泗阳县| 寿宁县| 四子王旗| 德昌县| 同德县| 剑川县| 龙江县| 临夏市| 云阳县| 涞源县| 开远市| 思茅市| 山阳县| 乐清市| 济南市| 淮阳县| 宣威市| 徐水县| 正宁县| 乡城县| 阿拉善左旗| 行唐县| 博罗县| 东乡| 石林| 玛曲县| 周至县| 灌阳县| 肃北| 阿尔山市| 永善县| 海林市| 龙井市| 文登市| 佛教| 当雄县| 房山区| 沾益县| 晋中市|