Here is the code:

 /*
Some class,such as a config file,need to be only one.So we need to control the instance.
1,private the constructor and create only one instance in the class itself.
2,provide a method for the others to get the 'only one' instance.
*/
package kju.obj; import static kju.print.Printer.*;
public class SingletonDemo {
public static void main(String[] args) {
SingleConfig con01 = SingleConfig.getInstance();
SingleConfig con02 = SingleConfig.getInstance();
println("con01 color : " + con01.getColor());
println("con02 set color : ");
con02.setColor("Blue");
println("con01 color : " + con01.getColor());
/*
con01 color : Orange
con02 set color :
con01 color : Blue
*/
}
} class SingleConfig {
private String color = "Orange";
private static SingleConfig s = new SingleConfig(); private SingleConfig() {}
public static SingleConfig getInstance() {
return s;
} public void setColor(String color) {
this.color = color;
} public String getColor() {
return color;
}
}

And the corresponds the code above:

Simple screenshot that explains the singleton invocation.的更多相关文章

  1. Simple screenshot that explains the non-static invocation.

    Here is the code: /* Instance invocation in the memory: */ package kju.obj; import static kju.print. ...

  2. recursive - simple screenshot but detail principle.

    the code below demonstates the principle of the'recursive-call' that the programing beginner may be ...

  3. Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#

    原文链接地址: http://csharpindepth.com/Articles/General/Singleton.aspx#unsafe Implementing the Singleton P ...

  4. c# 几种singleton 实现

    http://csharpindepth.com/Articles/General/Singleton.aspx#introduction 4th在线看 https://www.manning.com ...

  5. Implementing the Singleton Pattern in C#

    Table of contents (for linking purposes...) Introduction Non-thread-safe version Simple thread safet ...

  6. Burp Suite教程(英文版)

    In this article, we are going to see another powerful framework that is used widely in pen-testing. ...

  7. Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程

    原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...

  8. [学习笔记]设计模式之Facade

    写在前面 为方便读者,本文已添加至索引: 设计模式 学习笔记索引 Facade(外观)模式定义了一个高层接口,它能为子系统中的一组接口提供一个一致的界面,从而使得这一子系统更加容易使用.欢迎回到时の魔 ...

  9. 《PHP 设计模式》翻译完毕

    翻译进度请见:https://laravel-china.org/docs/php-design-patterns/2018?mode=sections 设计模式不仅代表着更快开发健壮软件的有用方法, ...

随机推荐

  1. Cow Contest

    poj3660:http://poj.org/problem?id=3660 题意:一些奶牛之间进行编程比赛,每头牛都有一个编程能力.如果a的能力比b的能力高,则a总能打败b .现在给你一些牛之间的比 ...

  2. highestAvailable比较灵活,毕竟大多数功能不需要系统最高权限(四种方法:屏蔽UAC,右键以管理员身份运行,增加manisfest,制作数字证书)

    打开VS2005.VS2008.VS2010工程,查看工程文件夹中的Properties文件夹下是否有app.manifest这个文件:如没有,按如下方式创建:鼠标右击工程在菜单中选择“属性”,点击工 ...

  3. Haskell递归

    maximum 函数取一组可排序的 List(属于 Ord Typeclass) 做参数,并回传其中的最大值.想想,在命令式风格中这一函数该怎么实现.很可能你会设一个变量来存储当前的最大值,然后用循环 ...

  4. Microsoft Internet Explorer 内存破坏漏洞(CVE-2013-3193)(MS13-059)

    漏洞版本: Microsoft Internet Explorer 6 - 10 漏洞描述: BUGTRAQ ID: 61678 CVE(CAN) ID: CVE-2013-3193 Windows ...

  5. java常见错误云集与注意事项

    1.安装Eclipse时,尽量jdk不要用jre,jdk包含jre j JDK就是Java Development Kit.简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环 ...

  6. MongoDB性能优化指南

    一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存在system.indexes 中,且默认总是为_id创建索引,它的索引使用基本和MySQL 等关系型数据库一样.其实可以这样说说,索引 ...

  7. Google财经

    本博文的主要内容有 .Google财经的介绍   .市场    .新闻 .投资组合新闻   .投资组合 1.Google财经的介绍 https://zh.wikipedia.org/wiki/Goog ...

  8. Drawing Lines - SGU 135(简单递推)

    求N条直线最多能把一个平面分成几部分. 代码如下: ========================================================================== ...

  9. c盘没有新建修改权限的,执行下面命令

    cmd中执行: icacls c:\ /setintegritylevel M

  10. Spring3 M2 quartz-2.1.7 解决bean不能注入问题

    我们要达到这样的效果 public class CancelUnpaidOrderTask implements Job { @Autowired private AppOrderService or ...