随笔-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 阅读(176) | 评论 (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 阅读(329) | 评论 (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 阅读(157) | 评论 (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 阅读(147) | 评论 (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 阅读(142) | 评论 (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 阅读(428) | 评论 (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 阅读(194) | 评论 (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 阅读(168) | 评论 (0)编辑 收藏
  2010年9月27日
    只有注册用户登录后才能阅读该文。阅读全文
posted @ 2010-09-27 23:25 li40204 阅读(71) | 评论 (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 阅读(11686) | 评论 (2)编辑 收藏
仅列出标题