Java的代理模式例子
(1). 创建一个接口, 要代理的类和 代理类都将继承它
package stone;
public interface Image {
public void show();
}
(2). 创建要被代理的类:
package stone;
public class BigImage implements Image {
public BigImage() {
try {
Thread.sleep(3000); // 模拟大图片要用长时间来加载
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("loading big image ");
}
public void show() {
System.out.println("show image");
}
}
(3). 创建代理类
package stone;
public class TestProxy {
public static void main(String[] args) {
long start= System.currentTimeMillis();
Image image= new ImageProxy(null);
System.out.println("Load time:"+String.valueOf(System.currentTimeMillis()-start));
image.show();
System.out.println("Show time:"+String.valueOf(System.currentTimeMillis()-start));
}
}
(4). 运行测试类,测试代理模式:
package stone;
public class TestProxy {
public static void main(String[] args) {
long start= System.currentTimeMillis();
Image image= new ImageProxy(null);
System.out.println("Load time:"+String.valueOf(Syste
相关文档:
import javax.swing.JOptionPane;
public class San {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
&n ......
1. 简单、面向对象和为人所熟悉
java的简单首先体现在精简的系统上,力图用最小的系统实现足够多的功能;对硬件的要求不高,在小型的计算机上便可以良好的运行。和所有的新一代的程序设计语言一样,java也采用了面向对象技术并更加彻底,所有的java程序和applet程序均是对象,封装性实现了模块化和信息隐藏,继承性 ......
1. 先写一个Singleton的class
package stone;
public class Singleton {
private static Singleton instance;
private Singleton() {}
public static Singleton getInstance(){
if(instance==null)
&n ......
移位运算符
包括:
“>> 右移”;“<< 左移”;“>>> 无符号右移”
例子:
-5>>3=-1
1111 1111 1111 1111 1111 1111 1111 1011
1111 1111 1111 1111 1111 1111 1111 1111
其结果与 Math.floor((double)- ......