`
jaesonchen
  • 浏览: 311656 次
  • 来自: ...
社区版块
存档分类
最新评论
文章列表
public class Evis {   static Evis instance = new Evis();   static final String START = new String("START") + " " + Evis.END;   static final String END = "END";   static String start = new String("start") + " " + Evis.end;   static String end = ...
package com.jaeson.javastudy.designpattern; /** * java io 的字节/字符流 转换使用了adapter模式,InputStreamReader、OutputStreamWriter * * 将一个类的接口转换成客户希望的另外一个接口。Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 * * 类适配器:Adapter extends Adaptee implements IService * 使用场景:当你想使用一个已经存在的类,而它的接口不符合你的需求。 * * ...
interface IService { public void execute(); } public class Decorator implements IService { private IService service; public Decorator(IService service) { this.service = service; } @Override public void execute() { this.doSomething(); this.service.execute(); } privat ...
import java.util.Iterator; interface IComponent { public void operate(); public void add(IComponent component); public void remove(IComponent component); public Iterator<IComponent> iterator(); public void setDepth(int depth); public int getDepth(); } public class Composit ...

bridge模式

import java.io.Serializable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; interface IConnection { public void query(String sql); } interface IDriver { public DIALECT getDialect();   public IConnection getConnection(); } public class Bridge { public static voi ...
public class Flyweight { public static void main(String[] args) { IConnection con = ConnectionPool.getInstance().getConnection(); con.query("select * from user"); ConnectionPool.getInstance().release(con); } } class ConnectionPool { private List<IConnection& ...

接口和类

接口中的方法自动是public abstract 的.   * 接口优先于抽象类:   java提供了两种机制可以用来定义允许多个实现的类型:接口和抽象类。   最明显的区别在于,抽象类允许包含某些方法的实现,接口则不允许。   更重要的区别在于,为了实现抽象类定义的类型,类必须成为抽象类的子类。   因为java只允许单继承,所以抽象类受到了极大的限制。   因为java允许实现多个接口,现有的类很容易被更新以实现新的接口。   接口是定义混合类型的理想选择,接口允许我们构造非层次结构的类型框架。   通过包装类(Decorator模式),接口使得安全地增强现有类的功能成为可能。   ...

java io

import java.io.*; public class IOStreamExample { public static void main(String[] args) { BufferedReader in = null; BufferedWriter out = null; BufferedInputStream bin = null; BufferedOutputStream bout = null; try { //写入字符文件 out = new BufferedWriter(new FileWrite ...

java运算符

public class TypeCast { public static void main(String[] args) { short i1 = 10; short i2 = 20; i1 = (short) (i1 + i2); //必须显式cast 回short,否则编译错误 i1 = (short) (i1 >> 2); i1 += i2; //+=运算符会自动将运算结果cast为 运算符左边的类型,所以不需要显式cast int i3 = 100; i3 = (int) (i3 + 100L); //当运算数类型比 ...
import java.util.*; public class MethodDesign { private Date startday; public MethodDesign() { } public MethodDesign(Date startday) { if(startday == null) throw new IllegalArgumentException("startday can not be null"); //保护性拷贝 this.startday = new Date(startday.getT ...
public class Concurrency { //方法一:使用volatile关键字,不能执行互斥访问,但能保证看到其他线程修改的结果。 private static volatile boolean stopRequested; //方法二:使用同步synchronized关键字,可以看到其他线程修改的结果(必须同步 ...
import java.util.*; public class CommonProgram { enum Suit { CLUB, DIAMOND, HEART, SPADE } enum Rank { ACE, DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING } private static final Random rnd = new Random(); //了解和使用标准类库及其API的功能 //Boolean.getBoolean(name)返回Sys ...
public class CompositionOverInheritance { public static void main(String[] args) { InstrumentedSet<String> st = new InstrumentedSet<String>(new HashSet<String>()); InstrumentedSet<String> st1 = new InstrumentedSet<String>(new HashSet<String>()); st.addA ...
public class Singleton { private static Singleton instance = new Singleton(); private Singleton() { } public static Singleton getInstance() { return instance; } public void service() { System.out.println("Singleton.service..."); } public static void main(St ...
public class FinalAndPrivate { @SuppressWarnings("all") public static void main(String[] args) { Parent p = new Parent(); p.call(); p.call2(); p.print(); p.staticMethod(); System.out.println("====================================="); Parent psub = ...
Global site tag (gtag.js) - Google Analytics