LINUKS BLOG

Make progress is the topic for ever...

My Photo
Name:
Location: China

It's a fans of computer/ Computer is my favorite/ Making progress is the topic for ever...

Monday, April 30, 2007

runtime exception

17.Question:

给我一个你最常见到的runtime exception。

Answer:

ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException,
ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException

Yesterday:

...

Tiny:

关于编程当中的字段的理解,比如说在Calendar这个类中,有一个字段叫DATE
那么你就可以这样来使用:new Calendar.get(Calendar.DATE),但前提是Calendar类必需要有get()方法.当然了,谁也不会笨得像我啦.

Friday, April 27, 2007

Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

16.Question:

Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

Answer:

Set里的元素是不能重复的,那么用iterator()方法来区分重复与否。equals()是判读两个Set是否相等。

  equals()和==方法决定引用值是否指向同一对象equals()在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。

Yesterday:

关于JPanel的add方法

JPanel panel;
panel=new JPanel(new BorderLayout());
panel.add(label,BorderLayou.CENTER);

Add a label to a JPanel.First of all ,you should set the layout of the JPanel.After that,you can lay the label on the JPanel as the Layout.

Tiny find:

The more you think,the more you will get.

Thursday, April 26, 2007

Overload和Override的区别

15.Question:

Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?

Answer:

方法的重写Overriding和重载Overloading是Java多态性的不同表现。重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。Overloaded的方法是可以改变返回值的类型。

Yesterday:

关于JLabel的构造方法摘要及某参数:
JLabel();
JLabel(Icon image);
JLabel(Icon image,int horizontalAlignment);
JLabel(String text);
JLabel(String text,Icon icon,int horizontalAlignment);
JLabel(String str,int horizontalAlignment);

JLabel.RIGHT JLabel.CENTER JLabel.LEFT are the int horizontalAlignment 's argument.

Tiny find:

Maybe it is familiar with the JLabel in the daily time, and thinking of you are know about it .But ,when you see the detailed explain ,you will find you are unfamiliar with it .The JLabel is a great example, i thought i can use it at first until i look up it in the JAVA 5.0 API document.

Wednesday, April 25, 2007

length()方法?

14.Question:

数组有没有length()这个方法? String有没有length()这个方法?

Answer:  

数组没有length()这个方法,有length的属性。 String有length()这个方法。

Yesterday:

I find the chance is coming to make my own program.The java programming is a process to use other people's wheel.Don't create the new wheel if the wheel exsit.It 's the java's thinking forever.

Tiny find:

Always find the big logic in the life ,but find the tiny less.In the morning ,workmate with me to have the breakfast. He let me to see the small flower in the rockery. Indeed,the flower is small ,but beautiful. Be custom to care about the big aspect in the life ,work ,and study,but less to care the tiny aspect.

Java有没有goto?

13.Question:

Java有没有goto?

Answer:

  Goto?java中的保留字,现在没有在java中使用。

Yesterday:

If i can't collect little time in the daily life,maybe there is no enough time for me to use.

Tiny find:

...

Monday, April 23, 2007

sleep() 和 wait() 有什么区别?

12.Question:

sleep() 和 wait() 有什么区别?

Answer:

sleep()方法是使线程停止一段时间的方法。在sleep 时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非(a)“醒来”的线程具有更高的优先级,(b)正在运行的线程因为其它原因而阻塞。

  wait()是线程交互时,如果线程对一个同步对象x 发出一个wait()调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。

Yesterday:

The harvests yesterday is small. I find i should practise to do more than one thing in a time again.

Tiny find:

There is no much the whole time to learn.And even have the whole time to use,i can't insist on studying by heart for a long time.It's wasting time not only for the whole time,and also for the study efficiency.Many time , i will be tired studying when the long time to do one thing.The best example is the preparation for the master test last year.

Two small mistake

11.Question:

short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错?

Answer:

 short s1 = 1; s1 = s1 + 1;有错,s1是short型,s1+1是int型,不能显式转化为short型。可修改为s1 =(short)(s1 + 1) 。short s1 = 1; s1 += 1正确。

Yesterday:

I thought of a new idea to practise my programming ability.Although the idea is small,but i insist that if i persisted i will be succeed.

I thought that i should make a program from a little program.Such as a notebook, a calendar,even a small clock.And i use the new knowledge from the daily study.And little by little, i should learn it by heart and make the program bigger.

Tiny:

Making a detailed comment for my program.Some time, not only me,many programmers don't have the custom to make detailed comments for his program.He think that it is too simple to make comment.But it is difficulty for the other programmers to understand his code.Even that he can't understand his own code when he have the first balance.

Accord to the above, i should improve my custom not to others,but only for me.

Saturday, April 21, 2007

Think much,do less

Thinking much,but do less all day.Aim a goal,and make a plan,do a little for it everyday.Don't think it is slow,you will find the progress when your dream come true.And i find a fault i have: i usually think the big logic of the life, but think less about the tiny in the daily life.

Especially,when you read the blog i wrote,you will find there are less slight described of the daily thing.

The details less in my thinking,maybe it is the biggest failure in recent nine years.

To practise this aspect in thinking ,and make up for it, i decide to add a piece of blog in the daily record.

1.Yesterday: ...

2.Tiny find:

Using the bluetooth of my T-mobile 575 to connect with PC by bluetooth adapter.Leave out the big aspect of the spesific operation, record a small point. When the mobile's ActiveSync connect to the PC, the PC's ActiveSync's port must be the com port which is the same with the set of the bluetooth adapter driver.For example , the two set are the same COM3 meantime.

Thursday, April 19, 2007

Math.round()的用法

9.Question:

Math.round(11.5)等於多少? Math.round(-11.5)等於多少?

Answer:

Math.round(11.5)返回(long)12,Math.round(-11.5)返回(long)-11;

Wednesday, April 18, 2007

The understand of the lesson from the web

All the time recently, record the knowledge points of the j2se base.And there is no fresh thing for my practice.However from the lesson of Mrs sun, i realized some thinking for the java learning. For example, i have to do some small program,though there's no one direct me,and i know nothing in fact. And also , i can accumulate the programming model to practise in the reality.One day learn a little,but learn it in the heart and practise it usually.Maybe this is the programming model what is call.

卓越不是单一的一种举动,而是一种习惯.

Tuesday, April 17, 2007

String s = new String("xyz");创建了几个String Object?

9.Question:

String s = new String("xyz");创建了几个String Object?

Answer:

两个对象,一个是“xyx”,一个是指向“xyx”的引用对象s。

Sunday, April 15, 2007

GC是什么? 为什么要有GC?

8.Question:

GC是什么?为什么要有GC?

Answer:

GC是垃圾收集器。Java 程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一:

  System.gc()
  Runtime.getRuntime().gc()

Friday, April 13, 2007

理解构造器--构造器和方法的区别

摘要

要学习Java,你必须理解构造器。因为构造器可以提供许多特殊的方法,这个对于初学者经常混淆。但是,构造器和方法又有很多重要的区别。

我们说构造器是一种方法,就象讲澳大利亚的鸭嘴兽是一种哺育动物。(按:老外喜欢打比喻,我也就照着翻译)。要理解鸭嘴兽,那么先必须理解它和其他哺育动物的区别。同样地,要理解构造器,那么就要了解构造器和方法的区别。所有学习java的人,尤其是对那些要认证考试的,理解构造器是非常重要的。下面将简单介绍一下 ,最后用一个表作了些简单的总结。


功能和作用的不同

构造器是为了创建一个类的实例。这个过程也可以在创建一个对象的时候用到:Platypus p1 = new Platypus();

相反,方法的作用是为了执行java代码。


修饰符,返回值和命名的不同

构造器和方法在下面三个方便的区别:修饰符,返回值,命名。和方法一样,构造器可以有任何访问的修饰: public, protected, private或者没有修饰(通常被package 和 friendly调用). 不同于方法的是,构造器不能有以下非访问性质的修饰: abstract, final, native, static, 或者 synchronized。


返回类型也是非常重要的。方法能返回任何类型的值或者无返回值(void),构造器没有返回值,也不需要void。


最后,谈谈两者的命名。构造器使用和类相同的名字,而方法则不同。按照习惯,方法通常用小写字母开始,而构造器通常用大写字母开始。构造器通常是一个名词,因为它和类名相同;而方法通常更接近动词,因为它说明一个操作。


"this"的用法

构造器和方法使用关键字this有很大的区别。方法引用this指向正在执行方法的类的实例。静态方法不能使用this关键字,因为静态方法不属于类的实例,所以this也就没有什么东西去指向。构造器的this指向同一个类中,不同参数列表的另外一个构造器,我们看看下面的代码:


public class Platypus {


String name;


Platypus(String input) {

name = input;

}


Platypus() {

this("John/Mary Doe");

}


public static void main(String args[]) {

Platypus p1 = new Platypus("digger");

Platypus p2 = new Platypus();

}

}

在上面的代码中,有2个不同参数列表的构造器。第一个构造器,给类的成员name赋值,第二个构造器,调用第一个构造器,给成员变量name一个初始值 "John/Mary Doe".

在构造器中,如果要使用关键字this,那么,必须放在第一行,如果不这样,将导致一个编译错误。


 
"super"的用法

构造器和方法,都用关键字super指向超类,但是用的方法不一样。方法用这个关键字去执行被重载的超类中的方法。看下面的例子:


class Mammal {

void getBirthInfo() {

System.out.println("born alive.");

}

}


class Platypus extends Mammal {

void getBirthInfo() {

System.out.println("hatch from eggs");

System.out.print("a mammal normally is ");

super.getBirthInfo();

}

}

在上面的例子中,使用super.getBirthInfo()去调用超类Mammal中被重载的方法。


构造器使用super去调用超类中的构造器。而且这行代码必须放在第一行,否则编译将出错。看下面的例子:


public class SuperClassDemo {

SuperClassDemo() {}

}


class Child extends SuperClassDemo {

Child() {

super();

}

}

在上面这个没有什么实际意义的例子中,构造器 Child()包含了 super,它的作用就是将超类中的构造器SuperClassDemo实例化,并加到 Child类中。


编译器自动加入代码

编译器自动加入代码到构造器,对于这个,java程序员新手可能比较混淆。当我们写一个没有构造器的类,编译的时候,编译器会自动加上一个不带参数的构造器,例如:public class Example {}

编译后将如下代码:


public class Example {

Example() {}

}

在构造器的第一行,没有使用super,那么编译器也会自动加上,例如:


public class TestConstructors {

TestConstructors() {}

}

编译器会加上代码,如下:


public class TestConstructors {

TestConstructors() {

super;

}

}

仔细想一下,就知道下面的代码


public class Example {}

经过会被编译器加代码形如:


public class Example {

Example() {

super;

}

}


继承


构造器是不能被继承的。子类可以继承超类的任何方法。看看下面的代码:

public class Example {


public void sayHi {


system.out.println("Hi");


}

Example() {}


}

public class SubClass extends Example {


}


类 SubClass 自动继承了父类中的sayHi方法,但是,父类中的构造器 Example()却不能被继承。

总结



主题

构造器

方法



功能

建立一个类的实例

java功能语句



修饰

不能用bstract, final, native, static,
or synchronized




返回类型

没有返回值,没有void

有返回值,或者void



命名

和类名相同;通常为名词,大写开头

通常代表一个动词的意思,小写开头



this

指向同一个类中另外一个构造器,在第一行

指向当前类的一个实例,不能用于静态方法



super

调用父类的构造器,在第一行

调用父类中一个重载的方法



继承

构造器不能被继承

方法可以被继承



编译器自动加入一个缺省的构造器

自动加入(如果没有)

不支持



编译器自动加入一个缺省的调用到超类的构造器

自动加入(如果没有)

不支持

什么时候用assert

7. Question:

什么时候用assert。

Answer:

断言是一个包含布尔表达式的语句,在执行这个语句时假定该表达式为 true。如果表达式计算为 false,那么系统会报告一个 AssertionError。它用于调试目的:

assert(a > 0); // throws an AssertionError if a <= 0

  断言可以有两种形式:

  assert Expression1 ;
  assert Expression1 : Expression2 ;

  Expression1 应该总是产生一个布尔值。
  Expression2 可以是得出一个值的任意表达式。这个值用于生成显示更多调试信息的 String 消息。
断言在默认情况下是禁用的。要在编译时启用断言,需要使用 source 1.4 标记:

  javac -source 1.4 Test.java

  要在运行时启用断言,可使用 -enableassertions 或者 -ea 标记。
  要在运行时选择禁用断言,可使用 -da 或者 -disableassertions 标记。
  要系统类中启用断言,可使用 -esa 或者 -dsa 标记。还可以在包的基础上启用或者禁用断言。

  可以在预计正常情况下不会到达的任何位置上放置断言。断言可以用于验证传递给私有方法的参数。不过,断言不应该用于验证传递给公有方法的参数,因为不管是否启用了断言,公有方法都必须检查其参数。不过,既可以在公有方法中,也可以在非公有方法中利用断言测试后置条件。另外,断言不应该以任何方式改变程序的状态。

Tuesday, April 10, 2007

不能敷衍了事

不知道为什么这几天,准确的说是这几年来,我学会了敷衍了事.学习,敷衍了事.生活,敷衍了事.工作,敷衍了事......好像这一切的一切都跟我无关似的.什么叫糊弄,像我这样子就叫.有些时候不知道为什么,感觉这样挺好,反正事不关已,高高挂起.但是有些时候,明明是自己的事,却又表现得与自己毫无关系似的.

就说这学习吧,有些时候也知道是为自己学,别人帮不了自己.当然有些时候也试图去迫使自己去学.可是呢,心并没有真的钻进去.这也许叫浮躁,但是这样于人于已,唉,还是不要说是于人了,于已来说是毫无益处的.

生活,有些时候只是觉得没什么意思.不知道为什么,总是觉得有些人很虚伪,很事故.但这就是生活,也有的人这样告诉我.可是难道非要让人都这样的去改变,有些时候真的不想这样去变,感觉有些恶心.

工作,也许是不如意吧.可能是因为现实与想像和计划的情况有差距吧.但话又说回来了,什么都是在不断的追求当中吧.只不不断得追求得来自己想要的东西时,才能算是一种安慰吧.

但是,无论如何,都不能毫无理由的敷衍了事啊!

Monday, April 09, 2007

Collection & Collections

6.Question:

Collection 和 Collections的区别。

Answer:

Collections是个java.util下的类,它包含有各种有关集合操作的静态方法。
 Collection是个java.util下的接口,它是各种集合结构的父接口。

Go home

There was no update in my blog in the five days. Five days ago,i went home for my father's phone.Dad asked me to go home.Although i went home after the new year one month ago,the words of dad's have some power to me .Not for other,only because the raise loving-kindness. Home is home for ever,not because your excellent or unexcellent.

Tuesday, April 03, 2007

HashMap和Hashtable

5.Question:

HashMap和Hashtable的区别。

Answer:

都属于Map接口的类,实现了将惟一键映射到特定的值上。

  HashMap 类没有分类或者排序。它允许一个 null 键和多个 null 值。

  Hashtable 类似于 HashMap,但是不允许 null 键和 null 值。它也比 HashMap 慢,因为它是同步的。

Sunday, April 01, 2007

& And &&

4.Question:

&和&&的区别?

Answer:

&是位运算符。&&是布尔逻辑运算符。