網頁

2010年4月23日 星期五

useful command

  • $ find ../../../../MMI/UI_ESIM/porting/PL_Java -iname "*.c" -exec basename "{}" \; | sed -e 's/\.c/\.o/g' | xargs -r rm

  • $ find . -iname "iextutil.o" -o -iname "iamsengine.o" -o -iname "kjava_sys_ext.o" | xargs -r rm

  • $ svn status | grep -v '?' | cut -b 2- | sed -e 's,\\,/,g' | xargs -r cp --parents -t ../patch_0427_release_merge/

  • $ find . -maxdepth 1 ! -iname "pl_java*" | xargs -r rm -rf

  • $ find . -maxdepth 1 ! -iname "build*" -a ! -name '.' | xargs -r rm -rf

  • $ diff -u -r --ignore-matching-lines=".*\$Id.*" parts_simon/ parts_ting/ | tee diff4.patch

  • $ svn diff -c 80580 --diff-cmd diff -x '-u -w -B -t --tabsize=4' > svg_update_hi_diff.log

2010年4月20日 星期二

svn command

generate svn diff (unified) file:
  • svn diff -r PREV:COMMITTED $SVN_LINK > svn.patch
  • svn diff -c $REVISION_NUMBER $SVN_LINK > svn.patch
  • $ svn diff -c 80580 --diff-cmd diff -x '-u -w -B -t --tabsize=4' > svg_update_hi_diff.log


apply diff file:
  • patch --verbose --dry-run -p0 < svn.patch


copy local modified files
  • svn status | grep -v '?' | cut -b 2- | sed -e 's,\\,/,g' | xargs -r cp --parents -t ../patch_0427_release_merge/


retrieve modified files in a commit:
  • svn update -r PREV
  • svn update -r HEAD | sed 's,\\,/,g' | cut -b 2- | xargs -r cp --parents -t $DEST


show the latest n svn commit log:
  • svn log -l n -v

Nested Classes

Why Use Nested Classes?

There are several compelling reasons for using nested classes, among them:
  • It is a way of logically grouping classes that are only used in one place.
  • It increases encapsulation.
  • Nested classes can lead to more readable and maintainable code.



Java Gossip: 內部類別(Inner class)
  • 使用內部類別的好處在於可以直接存取外部類別的私用(private)成員,舉個例子來說,在視窗程式中,您可以使用內部類別來實作一個事件傾聽者類別,這個視窗傾聽者類別可以直接存取視窗元件,而不用透過參數傳遞。
  • 另一個好處是,當某個Slave類別完全只服務於一個Master類別時,我們可以將之設定為內部類別,如此使用Master類別的人就不用知道 Slave的存在。



So what are inner classes good for anyway?

The advantages of inner classes can be divided into three categories:
  • an object-oriented advantage,
  • an organizational advantage, and
  • a call-back advantage.

2010年4月14日 星期三

Calling Overridden Methods

While learning Java about overriding methods, I suddenly thought that was it possible to invoke a method, which has been overridden by subclass, of the base class?

After googling it, I found Marco had the same question:

public class MainProgram {
    public static void main(String[] args) {
        Beta b = new Beta();
    
        // I want to invoke Alpha.foo() but
        // on the Beta instance.
        // I want to cancel the dynamic binding that
        // makes Beta.foo() get called instead
        // b.super.foo() <--- obviously doesn't compile
    }
}

class Alpha {
    public void foo() {
        System.out.println("inside Alpha.foo()");
    }
}

class Beta extends Alpha {
    public void foo() {
        System.out.println("inside Beta.foo()");
    }
}

As discussed in this thread[1], "It is Beta's decision whether it wants to use Alpha's foo() or its own, not the calling code's. Allowing code outside the Beta class to influence the binding of its methods breaks the concepts of polymorphism and encapsulation."

In another discussion thread[2], "You can't call the super method in other objects - that would violate encapsulation. The whole point is that the object controls what its overridden methods do."

That is, there is no way to call an overridden method directly in Java.

2010年4月6日 星期二

Evaluation Order

Evaluation Order

The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.

It is recommended that code not rely crucially on this specification. Code is usually clearer when each expression contains at most one side effect, as its outermost operation, and when code does not depend on exactly which exception arises as a consequence of the left-to-right evaluation of expressions.


/**
 * expression evaluation order test
 */

public class EvaluationOrder {
    public static void main(String [] args) {
        int i = 2;
        int j = i * (i=3);
        System.out.println(j);
    }
}

/*

$ java EvaluationOrder
6

*/


/*
 *  expression evaluation order test
 */

int main( void )
{
    int i = 2;
    int j = i * (i=3);
    printf("%d\n", j);
}

/*
gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

$ ./EvaluationOrder.exe
9

*/

2010年4月2日 星期五

Operator associativity

http://en.wikipedia.org/wiki/Operator_associativity

In programming languages and mathematical notation, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. Operators may be left-associative, right-associative or non-associative. The associativity and precedence of an operator depends on the programming language in question.

Consider the expression a ~ b ~ c. If the operator ~ has left associativity, this expression would be interpreted as (a ~ b) ~ c and evaluated left-to-right. If the operator has right associativity, the expression would be interpreted as a ~ (b ~ c) and evaluated right-to-left. If the operator is non-associative, the expression might be a syntax error, or it might have some special meaning.

Many programming language manuals provide a table of operator precedence and associativity; see, for example, the table for C and C++.