<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-12  評論-0  文章-1  trackbacks-0
      2011年11月22日
    the super keyword in java generic programming is used to declare a template of a specific type. e.g.
    List<? super MyClass> list = new LinkedList<AnyTypeDerivedByMyClass>();
    posted @ 2012-12-31 15:35 Sam Zheng 閱讀(243) | 評論 (0)編輯 收藏
    int (*test(char *(*)(void)) (int); declares a function named "test" which accepts a pointer to a function accepting no parameter and returning a char pointer, the function "test" returns a pointer to a function which accepts a integer parameter and returns a integer.
    Note: a declaration declares either a variable(pointer) or function(pointer), if its name is followed by left parentheses, it is a function, otherwise it is a variable(pointer).
    posted @ 2012-09-20 14:38 Sam Zheng 閱讀(127) | 評論 (0)編輯 收藏
    if you don't feel comfortable with your code, it's time to refactor/re-think about it.
    posted @ 2012-08-31 11:36 Sam Zheng 閱讀(159) | 評論 (0)編輯 收藏
    don't get trapped when reading source code of a complex module, first figure out what the module does/its main functionality and its interfaces, once you get into details, you cannot see the module as a whole and forget its main functionality, if you recognize you are trapped in details, try to come out and focus on interfaces, top->down->top->down
    posted @ 2012-08-15 16:07 Sam Zheng 閱讀(154) | 評論 (0)編輯 收藏
    The crucial part in design/programming, is to break down complex things, anything should be easy when broken down to manageable pieces, and, only when broken down, can it be easy. when doing so, the most important thing is to think about the granularity and the relationship between every pieces/modules, again, reasonability.
    posted @ 2012-04-18 12:10 Sam Zheng 閱讀(143) | 評論 (0)編輯 收藏
    when analyzing/programming, think about reasonability against requirements
    posted @ 2012-04-17 12:55 Sam Zheng 閱讀(313) | 評論 (0)編輯 收藏
    1. what does the program/module/class/method do?
    2. what is its input, if any?
    3. what is its output, if any?
    for a class, understanding its lifecycle is crucial:
    1. how is it created? by who? from a factory? what are the parameters required to create it?
    2. does it have any enforced lifecycle methods? e.g. initialize, dispose..., who is responsible to call these methods, in which order?
    3. what it can do at each stage of its lifecycle?
    4. who is going to use it/what is its client?

    posted @ 2012-03-09 10:52 Sam Zheng 閱讀(236) | 評論 (0)編輯 收藏
    An interface or a class should only do things that it knows, never do things it is not sure about. to define the responsibility of an interface/class clearly and precisely is critical.
    posted @ 2012-02-27 14:12 Sam Zheng 閱讀(168) | 評論 (0)編輯 收藏
    The main difference between SoftReference and WeakReference is that GC uses different algorithm to determine when to reclaim the objects they refer to, they can be used interchangablely in most situation.

           
            // soft reference
            o = new Object();
            ReferenceQueue
    <Object> sq = new ReferenceQueue<Object>();
            SoftReference
    <Object> sf = new SoftReference<Object>(o, sq);
            System.out.println(sf.get());
            o 
    = null;
            
            System.gc();
            r 
    = (Reference) sq.poll();
            
    if (r != null) {
                System.out.println(r.get());
            }

            // weak reference
            Object o = new Object();
            ReferenceQueue
    <Object> q = new ReferenceQueue<Object>();
            WeakReference
    <Object> w = new WeakReference<Object>(o, q);
            System.out.println(w.get());
            o 
    = null;
            System.gc();
            
            Reference r 
    = (Reference) q.poll();
            
    if (r != null) {
                System.out.println(r.get());
            }

            
    // phantom reference
            o = new Object();
            ReferenceQueue
    <Object> pq = new ReferenceQueue<Object>();
            PhantomReference
    <Object> pf = new PhantomReference<Object>(o, sq);
            System.out.println(pf.get());
            o 
    = null;
            
            System.gc();
            r 
    = (Reference) pq.poll();
            
    if (r != null) {
                System.out.println(r.get());
            }
           


    from http://www.ibm.com/developerworks/library/j-refs/

    The SoftReference class

    A typical use of the SoftReference class is for a memory-sensitive cache. The idea of a SoftReference is that you hold a reference to an object with the guarantee that all of your soft references will be cleared before the JVM reports an out-of-memory condition. The key point is that when the garbage collector runs, it may or may not free an object that is softly reachable. Whether the object is freed depends on the algorithm of the garbage collector as well as the amount of memory available while the collector is running.

    The WeakReference class

    A typical use of the WeakReference class is for canonicalized mappings. In addition, weak references are useful for objects that would otherwise live for a long time and are also inexpensive to re-create. The key point is that when the garbage collector runs, if it encounters a weakly reachable object, it will free the object the WeakReference refers to. Note, however, that it may take multiple runs of the garbage collector before it finds and frees a weakly reachable object.

    The PhantomReference class

    The PhantomReference class is useful only to track the impending collection of the referring object. As such, it can be used to perform pre-mortem cleanup operations. A PhantomReference must be used with the ReferenceQueue class. The ReferenceQueue is required because it serves as the mechanism of notification. When the garbage collector determines an object is phantomly reachable, the PhantomReference object is placed on its ReferenceQueue. The placing of the PhantomReference object on the ReferenceQueue is your notification that the object the PhantomReference object referred to has been finalized and is ready to be collected. This allows you to take action just prior to the object memory being reclaimed.

    posted @ 2012-01-08 13:06 Sam Zheng 閱讀(127) | 評論 (0)編輯 收藏
    Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
    posted @ 2012-01-07 22:06 Sam Zheng 閱讀(371) | 評論 (0)編輯 收藏
    JAAS generally has the following two steps:
    1, Authentication: define principals,  implement LoginModule and callback handler, associate designated principals with the subject object in the commit method of LoginModule implementation, configure the module implementation in a login configuration file, i.e
    Sample {
       sample.module.SampleLoginModule required debug=true;
    };

    lc = new LoginContext("Sample", new MyCallbackHandler());
    Subject s = lc.getSubject();
    Subject.doAs(s, new PrivilegedAction(){...}); // the authenticated subject s will be associated with the current access control context.

    2. Authorization: write policy file to grant principals access right to any critical resources. e.g.
    grant
            Principal sample.principal.SamplePrincipal "testUser" {

       permission java.util.PropertyPermission "java.home", "read";
       permission java.util.PropertyPermission "user.home", "read";
       permission java.io.FilePermission "foo.txt", "read";
    };
    posted @ 2011-12-31 14:32 Sam Zheng 閱讀(133) | 評論 (0)編輯 收藏
    to decouple modules or sub systems: define interfaces and dependencies between modules
    posted @ 2011-11-22 12:24 Sam Zheng 閱讀(100) | 評論 (0)編輯 收藏
    主站蜘蛛池模板: 亚洲乱码在线卡一卡二卡新区| 久久精品国产亚洲7777| 亚洲福利视频网址| 男女作爱在线播放免费网站| 亚洲午夜未满十八勿入网站2| aa在线免费观看| 亚洲成AV人片一区二区| 久久国产精品免费视频| 亚洲宅男永久在线| 国产精品永久免费10000| 久久狠狠爱亚洲综合影院| 成人免费午夜在线观看| 亚洲AV成人片无码网站| 成人亚洲网站www在线观看| 一级毛片人与动免费观看| 亚洲国产另类久久久精品| 久章草在线精品视频免费观看| 亚洲视频一区二区在线观看| 午夜国产精品免费观看| 亚洲av中文无码字幕色不卡| 丁香亚洲综合五月天婷婷| 最好免费观看高清在线| 亚洲youjizz| 亚洲精品综合久久| 免费不卡在线观看AV| 国产亚洲中文日本不卡二区| 亚洲av无码成人精品区| 最好免费观看高清在线| 亚洲精品国产日韩| 亚洲日本韩国在线| 2019中文字幕免费电影在线播放| 亚洲AV综合色区无码二区爱AV| 青青青国产免费一夜七次郎 | 中文字幕免费视频精品一| 久久亚洲精品中文字幕| 国产精品冒白浆免费视频| 永久免费AV无码网站国产 | 久久亚洲国产成人影院网站| 99蜜桃在线观看免费视频网站| 亚洲国产欧美日韩精品一区二区三区| 伊人久久大香线蕉亚洲|