生活还在继续!!!

星期三 五月 07, 2008

scjp摘要chapter8:inner class

inner class:普通的inner class,static ,method local,anonymous [Read More]

星期日 四月 20, 2008

scjp摘要chapter6:String对象

JVM为String常量分配了一个单独的内存区域叫做"String constants pool" [Read More]

scjp摘要chapter5中的一段代码

String getRandomName(){
    int i = (int)(Math.random()*5);
    String name = new String[]{"Fred","Bob","Chris","James","Spy"}[i];
    return name;
}

星期五 四月 18, 2008

scjp摘要:chapter4

第三章看完了,没有什么需要特别注意的,都是偶知道的东东。刚刚在看第四章,前面是condition flow,是if/else,switch,for,do/while,while也都没有什么需要特别留意的部分。往下讲了些异常的知识,“异常”也接触过不少,似懂非懂的感觉。

java中的异常都是由java.lang.Throwable衍化而来,衍生为Error和Exception两个分支。Exception又演变为RunTimeException和其他的Excption(不从RunTimeException衍生的异常).
RunTimeException是最常听到的名词了,运行期异常是可以通过修改代码就可以解决的异常;
Error是非程序本身问题而引起的出错,象jvm崩溃,资源耗尽等等,非人力可以解决的;
其他异常则指象IOException之类的异常。

异常可以分为已检查异常checked和未检查异常unchecked。
Error和RunTimeException及他们的子类都是未检查异常
其他的Exception则属于已检查异常

在我们的程序中有时可能只有try和finally方法,而没有catch方法,此时try中的异常是如何处理的呢?
java中我们可以抛出该异常propageting uncaught exception
方法调用过程是保存在stack中的,我们假设stack是向上增长的:我们的程序从main方法开始执行,main方法调用方法a,方法a调用方法b,方法b调用方法c,在stack中就似下面这样:
c
b
a
main
这样如果在方法c中产生未捕获的异常,他将该异常传给了b,b传给了c,直至main。所以如果异常没有在方法中被处理的话,异常将从main中抛出,jvm也就被halt了。

Each method must either handle all checked exception by supplying a catch clause or list each unhandled checked exception as a thrown exception.This rule is referred  to as Java's handle or declare requirement.
<hr></hr>

因为我们并不需要catch方法抛出的所有异常,那么我们该catch哪些异常呢?
我们可以在方法声明时给出答案:
public void method(int i) throws MyException1,MyException2{}
就像方法声明时我们必须规定方法的形参个数及类型和返回类型一样,我们也必须给出方法可能抛出的异常;即便我们的方法中不会抛出异常,但是如果方法中调用了另一个可能产生异常的方法,如果我们不handle的话,我们就需要传递该异常。但是运行期异常是例外,因为RuntimeException是未检查异常,是我们的一些mistake,只是我们还不知道具体是什么。
unchecked exceptions donot have to be specified or handled.


星期一 四月 14, 2008

Time to wait is so tedious

I have left my last employer for a long time.And i had email my job interview on internet for a while.I also got some chance for interviews.But everytime it all ended up with no excuse.I know i wasn't excellent,but i would be,if i get a change ,i swear.
Last week,i got a interview.I think that's what i want.I have strong will to get in the company,but i dont have  strong confidence.I wish i can get through it.In that interview ,i answered everything i knew.Talk about what i had done;talk in english and so on.
Oh god,i really need that job.

星期四 四月 10, 2008

scjp摘录:chapter 2

编译器解析import的顺序,接口多继承 [Read More]

星期三 四月 09, 2008

protected修饰符

protected=inheritance [Read More]

It's my asset.

This is my first English Webblog.I wish i can continue to do it everyday. [Read More]