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. 如何打造一款五星级的 APP ?

    移动互联网大潮来袭!据统计,2015 年平均每天有 1000 个新的应用上架,而这些应用的现状可以说是鱼龙混杂,同是每个人的眼光.品味.意识和利益都不同,因此每人眼中的应用也是不同的.在巨大的市场竞争 ...

  2. Energy Minimization

    zoj2539:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2539 题意:公式第一项只要当xi=0时才会有作用,第二项只 ...

  3. MYSQL常用命令集合

    1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqld ...

  4. 实例模拟struts核心流程

    Struts,经典框架之一,每个java  web 开发人员都应该晓得它的大名.这里,我就用一个简单实例来模拟一下struts的核心流程.具体实例如下: 主界面: 点击提交后,程序根据具体的actio ...

  5. Supporting Multiple Screens 翻译 支持各种屏幕(上)

    Supporting Multiple Screens 支持各种各样的屏幕尺寸.屏幕密度 Android runs on a variety of devices that offer differe ...

  6. 【HDOJ】2255 奔小康赚大钱

    最大二分图匹配,O(n^3). /* 2255 */ #include <iostream> #include <algorithm> #include <cstdio& ...

  7. TCP/IP TELNET & SSH

    快速导航 远程登录示例 关于远程登录? 嵌入? 用来控制远程服务器上运行的应用程序字符? 转义? 操作方式? 关于SSH? 远程登录示例 关于远程登录? 网络虚拟终端(Network Virtual ...

  8. 连接池 BoneCPDataSource

    一篇连接池不错的文章 http://blog.csdn.net/vincent_czz/article/details/7646392

  9. 在Ant Build文件中使用正则表达式替换文件内容

    这需要在build文件中使用<replaceregexp>标签, 这个标签的使用大概是这个样子的: <replaceregexp file="${src}/build.pr ...

  10. SRM 440(1-250pt, 1-500pt)

    DIV1 250pt 题意:小球从一段折线斜坡上滚下来,告诉所用时间,求重力加速度. 解法:二分答案模拟即可. tag:二分,simulation // BEGIN CUT HERE /* * Aut ...