Java琐记---细碎知识的补充

System.out.println(Boolean.parseBoolean(null));//false

System.out.println(Boolean.parseBoolean("1"));//false

System.out.println(Boolean.parseBoolean("0"));//false

System.out.println(Boolean.parseBoolean("true"));//true

System.out.println(new Integer(0) instanceof Object);//true 子类是父类的实例 ,instance 前边是实例,后边是类型

//System 的相关内容重定向到日志文件

static{//加在类中的静态

PrintStream newout = new PrintStream(new FileOutputStream(new File("C:/log.log")));

System.setOut(newout);

System.setErr(newout);

}

PipedInputStream

PipedOutputStream

特点:

读取管道流和写入管道流可以进行连接。

连接方式:

1,通过两个流对象的构造函数。

2,通过两个对象的 connect 方法。

通常两个流在使用时,需要加入多线程技术,也就是让读写同时运行。

注意;对于 read 方法。该方法是阻塞式的,也就是没有数据的情况,该方法会等

待。

//Serializable

Java的serialization提供了一种持久化对象实例的机制。当持久化对象时,可能有一个特殊的对象数据成员,我们不想用serialization机制来保存它。为了在一个特定对象的一个域上关闭serialization,可以在这个域前加上关键字transient。当一个对象被序列化的时候,transient型变量的值不包括在序列化的表示中,然而非transient型的变量是被包括进去的。

//线程打印结果的不确定

public class Test  extends Thread{

String hello ="hello1";

@Override

public void run() {

// TODO Auto-generated method stub

hello="hello2";

}

public static void main(String[] args) {

Test t = new Test();

Thread thread=new Thread(t);

System.out.println(thread.getId());

System.out.println(Thread.currentThread().getId());

t.start();

for (int i=0; i < 10; i++){

System.out.println(t.hello);//打印结果不确定 ,一次是hello1 ,一次是hello2

}

}

}

猜你喜欢

转载自plpone.iteye.com/blog/2197701