隨筆-10  評論-3  文章-0  trackbacks-0
            2011年12月30日
          最近有customer說收不到我們系統發的email,查了一段時間,總算有所收獲,對SMTP也有了些許了解。

          一開始以為是我們郵件服務器IP被blacklist了或對方把我們的IP給禁了。于是就試了下用telnet SMTP測試下:

          telnet #customer.domain.com# 25

          EHCO sdfa

          MAIL FROM: <from@xxx.com>
          RCPT TO: <to@xxxxxx.com>
          DATA

          .
          QUIT

          結果測試我們是可以telnet到對方的SMTP server的,這樣發是可以發送成功的,即排除了對方把我們禁了的可能。可如果telnet到我們自己的SMTP server的話,就失敗了。

          telnet #own.domain.com# 25
          ...

          后來查了很久,原來是因為timeout的原因:我們用的IMSS gateway有timeout機制。查Log發現,連接對方SMTP SERVER無問題,MAIL FROM command也無問題,可就在RCPT TO 這個command超時了,超過30s都沒有response從對方SMTP SERVER回來,估計對方的SMTP SERVER不怎么好,parse和查找個email address (end user: to@xxxx.com)都要花很長時間。后來我們就timeout的參數,從30s調到60s,果然就可以了,估計對方SMTP server之行RCPT TO這個命令都花了30-40s。

          問題解決
          posted @ 2011-12-30 00:24 li40204 閱讀(189) | 評論 (0)編輯 收藏
            2011年4月20日
          Ubuntu vi 默認不支持鍵盤的方向鍵和Backspace鍵,很不方便,可以修改/etc/vim下面動vimrc.tiny,使其支持。

          vi /etc/vim/vimrc.tiny
          set compatible -> change to set nocompatible
          And add set backspace=2


          posted @ 2011-04-20 00:06 li40204 閱讀(347) | 評論 (1)編輯 收藏
            2010年12月10日

          1. Always keep data private.


          2. Always initialize data.

          3.
          Don't use too many basic types in a class.

          4.
          Not all fields need individual field accessors and mutators.

          5.
          Use a standard form for class definitions.

          6. Break up classes with too many responsibilities.


          7. Make the names of your classes and methods reflect their responsibilities.
          posted @ 2010-12-10 13:41 li40204 閱讀(172) | 評論 (0)編輯 收藏
              不知不覺又停了N天學習,看來堅持對偶來說真是難于登天啊。。。

          The javac compiler always looks for files in the current directory, but the java interpreter only looks into the current directory if the "." directory is on the class path. If you have no class path set, this is not a problem—the default class path consists of the "." directory. But if you have set the class path and forgot to include the "." directory, then your programs will compile without error, but they won't run.

          Features tagged as public can be used by any class. Private features can be used only by the class that defines them. If you don't specify either public or private, then the feature (that is, the class, method, or variable) can be accessed by all methods in the same package.

          Comment Extraction

          Here, docDirectory is the name of the directory where you want the HTML files to go. Follow these steps:

          1.
          Change to the directory that contains the source files you want to document. If you have nested packages to document, such as com.horstmann.corejava, you must be working in the directory that contains the subdirectory com. (This is the directory that contains the overview.html file if you supplied one.)

          2.
          Run the command


          javadoc -d docDirectory nameOfPackage

          for a single package. Or run


          javadoc -d docDirectory nameOfPackage1 nameOfPackage2...

          to document multiple packages. If your files are in the default package, then instead run


          javadoc -d docDirectory *.java





          posted @ 2010-12-10 12:00 li40204 閱讀(161) | 評論 (0)編輯 收藏
            2010年10月10日
          用System.out.printf方法進行格式化輸出;也可用String.format方法創建一個格式化的String, 而不需要打印輸出。

          日期格式設置參考Core Java, Volumn 1的P55頁,許多格式化規則與本地環境有關。

          java.util.Arrays類包含了用來操作數組(例如排序與搜索)的各種方法,常用方法如下:

          static String toString(type[] a)

          static void sort(type[] a)   //Quick Sort

          static int binarySearcch(type[] a, type v)

          static void fill(type[] a, type v)   //將數組的所有數據元素值設為v

          ....

          End of Chapter 3






          posted @ 2010-10-10 18:10 li40204 閱讀(166) | 評論 (0)編輯 收藏
            2010年10月2日
          Java讀取控制臺System.in 輸入相對麻煩點,要先構造一個Scanner對象,并與標準輸入流System.in關聯。(Scanner包含在包java.util中)

          Scanner in = new Scanner(System.in);
          System.out.println(
          "What is your name?");
          String name 
          = in.nextLine();  //讀整行,因為可能包括空格

          //Or
          //String name = in.next(); //以空白符為分隔
          //int age = in.nextInt();  //讀取整數

          使用Scanner時輸入是可見的,因此不適用從控制臺讀取密碼。Console類可以實現這個目的。

                  Console cons = System.console();
                  
                  
          //Method prototype:
                  
          //static String readLine(String prompt, Objectargs)
                  
          //顯示字符串prompt并且讀取用戶輸入直到輸入行結束, args參數用來提供輸入格式
                  String username = cons.readLine("User name: ");
                  
                  
          //Method prototype:
                  
          //static char[] readPassword(String prompt, Objectargs)
                  
          //用戶輸入不可見
                  char[] pwd = cons.readPassword();



          posted @ 2010-10-02 17:57 li40204 閱讀(441) | 評論 (0)編輯 收藏
           

          Java中有8種基本數據類型:int, short, long, byte, float, double, char, boolean

          Java中,整型的范圍與運行java代碼的機器無關。在C/C++程序中,int類型占用的字節可能會因不同機器不同操作系統而不同;而在java中,各種整型的存儲需求已經被明確定義(int: 4 bytes; short: 2 bytes; long: 8 bytes; byte: 1 byte),從而實現了平臺無關性。

          常用整型、浮點型常量:

          Integer.MAX_VALUE

          Ingeger.MIN_VALUE

          Double.POSITIVE_INFINITY (正無窮大)

          Double.NEGATIVE_INFINITY (負無窮大)

          Double.NaN (Not a number)

          PS: 判斷一個特定值是否等于Double.NaN:

          if (x == Double.NaN)    //is never true

          Should use:

                   if (Double.isNaN(x)) // check whether x is “Not a number”

          char 類型用于表示Unicode編碼的字符單元。Unicode可表示為16進制值,從"u0000"uffff

          關于Unicode: Unicode出現前,已經有了很多的字符編碼標準(如美國的ASCII, 西歐的ISO 8859-1, 俄羅斯的KOI-8, 中國的GB118030BIG-5etc),這樣造成了兩個問題:a). 對于給定的代碼值,不同的編碼方案下可能對應不同的字母; b). 采用大字符集的語言其編碼長度可能不同,e.g., 有些常用的字符采用單字節編碼,而另一些字符則需要兩個或更多字節。設計Unicode就是為了解決這些問題。但遺憾的是,經過一段時間,Unicode字符超過了65536個,現在,連16位的char類型也已經不能滿足所有Unicode字符的需求了。強烈建議不要在程序中用char類型。

          當將一個字符串和一個非字符串的值進行拼接時,后者被轉換成字符串。E.g:

                 int age = 24;

                 String s = “abce” + age; //age被轉換成字符串,結果為“abcd24”。

          采用字符串連接的方式時,每次連接字符串,都會構建一個新的String對象,既耗時又浪費空間。可以使用StringBuilder代替:

                  StringBuilder builder = new StringBuilder();
                  builder.append(ch/str);
          其前身是StringBuffer。StringBuffer效率稍低,但支持多線程。StringBuilder不支持多線程,從而效率也較高。
          posted @ 2010-10-02 17:22 li40204 閱讀(212) | 評論 (0)編輯 收藏
            2010年9月28日

          Command: jar xvf file.zip 用于解壓文件。Java庫源文件在JDK中保存為src.zip,可用該命令解壓。
           

          Javac將.java文件編譯成.class文件,發送到jvm, jvm執行編譯器存放在.class文件中的字節碼。

          運行applet:1). 直接用瀏覽器打開html,該html里包含applet。2). appletviewer ***.html。applet嵌入到html的寫法如下:

          <html>
               <head></head>
               <body>
                      ......
                      <applet code = "WelcomeApplet.class" width="400" height="200">
                           <param name = "greeting" value="Welcome to core java!" />
                      </applet>
               </body>
          <html>

          posted @ 2010-09-28 00:40 li40204 閱讀(185) | 評論 (0)編輯 收藏
            2010年9月27日
              只有注冊用戶登錄后才能閱讀該文。閱讀全文
          posted @ 2010-09-27 23:25 li40204 閱讀(78) | 評論 (0)編輯 收藏
            2009年7月28日

                  要判讀String是否為空字符串,比較簡單,只要判斷該String的length是否為0就可以,或者直接用方法isEmpty()來判斷。

                  但很多時候我們也會把由一些不可見的字符組成的String也當成是空字符串(e.g, space, tab, etc),這時候就不能單用length或isEmpty()來判斷了,因為technically上來說,這個String是非空的。這時候可以用String的方法trim(),去掉前導空白和后導空白,再判斷是否為空。

                  例如:

           1public class TestEmpty
           2{
           3    public static void main(String[] args){
           4        String a = "       ";
           5        
           6        // if (a.isEmpty())
           7        if (a.trim().isEmpty())
           8        {
           9            System.out.println("It is empty");
          10        }

          11        else 
          12        {
          13            System.out.println("It is not empty");
          14        }

          15    }

          16}

          17
          18

          結果當然是:It is empty



          PS:Java Doc

          public String trim()

          Returns a copy of the string, with leading and trailing whitespace omitted.
          posted @ 2009-07-28 22:34 li40204 閱讀(11714) | 評論 (2)編輯 收藏
          僅列出標題  
          主站蜘蛛池模板: 闽侯县| 大名县| 南丰县| 镇远县| 南阳市| 平阴县| 怀来县| 喀喇沁旗| 日喀则市| 邢台市| 三门峡市| 罗定市| 潜江市| 深州市| 香港| 邢台市| 明溪县| 延津县| 湛江市| 南丰县| 霍林郭勒市| 潍坊市| 通化县| 三穗县| 樟树市| 清河县| 威海市| 溧阳市| 定结县| 嘉善县| 铜川市| 凌云县| 高阳县| 永吉县| 平远县| 禄丰县| 克山县| 张家界市| 阿拉善盟| 宿州市| 江油市|