文档介绍:QI. How could Java classes direct program messages to the system console, but error messages, say to a file?・
Java中如何将程序信息导航到系统的console,而把错误信息放入到一个file 中?
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device・ By defauIt, they both point at the system console. This how the standard output could be re-directed:
Stream st 二 new Stream(new FileOutputStream(""));
System. setErr(st); System. setOut(st);
系统有一个展现标准输出的out变量,以及一个负责标准错误设置的err变量, 默认情况下这两个变量都指向系统的console,这就是标准输出如何能被改变方向 (就是改变信息的输出位置)。
Q2. What's the difference between an interface and an abstract class?抽象类和接口的区别:
A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multipie inheritance・ On the other hand, you can implement multipie interfaces in your class.
抽象类中可能会含有带有方法体的一般方法,而这在接口中是不允许的。用抽 象类的时候得去继承它,但是java中是不允许多继承的,相反的(另一方面),可 一对接口多实现
Q3・ Why would you use a synchronized block vs. synchronized method? 同步锁和同步方法相比较,为什么使用同步锁?
A. Synchronized blocks place locks for shorter periods than synchronized
Q4. Explain the usage of the keyword transient?解释transient
A. This keyword does not have to be de-serialized, this its data type (i
・e.
indicates that the value of this member variable serialized with the object. When the class will be variable will be initialized with a defauIt value of zero for integers)・
这个关键字显示该成员变量的值不需要和对象一同序列化,当这个对象被序列 化的时候,这个变量就会用其所属类型的默认值来初始化。(初始为变量所属类型 的默认值)
* Q5. How can you force garbage collection?如何强制垃圾回收?(就是 如何自己手动处理垃圾回收)
A. You can't force GC, but could request it by calling System. gc()・ JVM does not guarantee that GC will be started immediately.
你不能强制使用一个gc,但是可以调用System. gc()来向其发出请求,但是jvm 并不保证gc立刻被调用。
Q6. How do you know if an explicit object casting is needed?
什么时候需要强制类型转换?
A. If you assign a superclass object to a variable o