十一 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表示降序排列
......
private static boolean isValidDate(String strValue ) {//20091001字符串
int d = Integer.parseInt(strValue.substring(6, 8));
int m = Integer.parseInt(strValue.substring(4, 6));
int y = Integer.parseInt(strValue.subst ......
通常,我们为了避免内存溢出等问题,需要设置环境变量
JAVA_OPTS -Xms256M -Xmx512M 等,【对于服务器,一般都设置成一样的】
但是有的时候可能这样的设置还会不行(比如,当Server应用程序加载较多类时,即jvm加载类时,永久域中的对象急剧增加,从而使jvm不断调整永久域大小,为了避免调整),你可以使 ......
九 java面向对象程序设计(this关键字)
/**
* 面向对象之四
* this关键字总结
*/
/*this关键字的第一种用法*/
//在方法中调用同类中的方法,这时的this可以省略.
class ThisPointer
{
public void function1()
{
System.out.println("function1 is calling...");
......