十一 java面向对象程序设计(单态设计模式)
十一 java面向对象程序设计(单态设计模式)
/**
* 面向对象之六
* 单态模式设计
* 所谓类的单态设计模式,就是采取一定的方法保证在整个的软件系统中,对某个类只能存在一个对象实例,
* 并且该类只提供一个取得其对象实例的方法。
*/
class Single
{
private static int count = 0;
private Single()//首先将构造机定义成私有的.
{
System.out.println("contructor is calling...");
System.out.println("we creat " + (++count) + " object");
}
private static Single single = new Single();
//在该类内部产生一个对象,并将其定义为static,这样就只有一个对象了.
public static Single getSingle()
//提供一个静态方法(因为对象的引用时static的所以要定义成静态方法),返回这唯一的对象.
{
return single;
}
}
public class SingleTest {
public static void main(String[] args)
{
Single.getSingle();
Single.getSingle();
Single.getSingle();
Single.getSingle();
Single.getSingle();
}
}
/* ouput
contructor is calling...
we creat 1 object
*/
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
1 JAVA的反射,其实就是通过一个实例化的对象反过来去找到一个类的完整信息,比如对于如下的形式:
X x=new X();
x.getClass().getName();
这里就会输出这个类所在的完整信息,即"包名.类名";
最常用的三种实例化CLASS类对象
Class<?> c1 = null ; // 指定泛型
C ......
A flexible layout configurable with pattern string.
The goal of this class is to format
a LoggingEvent
and return the results as a String. The results depend on the conversion
pattern
.
The conversion pattern is closely related to the conversion pattern of the
printf function in C ......
九 java面向对象程序设计(this关键字)
/**
* 面向对象之四
* this关键字总结
*/
/*this关键字的第一种用法*/
//在方法中调用同类中的方法,这时的this可以省略.
class ThisPointer
{
public void function1()
{
System.out.println("function1 is calling...");
......