Java面试题
2013-07-07 15:43
134 查看
交通灯系统
面向对象设计把我一个重要的经验:谁拥有数据,谁就对外提供操作这些数据的方法。
典型案例:
球从绳子的一端移动到了另一端:
两块石头磨成一把石刀,石刀可以砍树,砍成木材,木材做成椅子
StoneKnife knifeFactory(Stone first,Stone second);
Material stoneKnife.cut(Tree tree);
Chair chairFactory(Material material);
JDK1.5以后创建线程的新方法:线程池
定时器:
银行业务调度系统:
有三种对应类型的客户:VIP客户,普通客户,快速客户,异步随机生成各种类型的客户,各类型客户在其对应窗口按顺序依次办理业务
各类型客户在其对应窗口按顺序依次办理业务,准确地说,应该是窗口依次叫号。
面向对象设计把我一个重要的经验:谁拥有数据,谁就对外提供操作这些数据的方法。
典型案例:
球从绳子的一端移动到了另一端:
class Rope { privatePoint start; privatePoint end; publicRope(Point start,Point end){ this.start=start; this.end=end; } publicPoint nextPoint(Point currentPoint){ /* 通过两点一线的数学公式可以计算出当前点的下一个点, 如果当前点是终止点,则返回null,如果当前点不是线上的点,则抛出异常*/ return null; } } class Ball{ private Rope rope; private Point currentPoint; public Ball(Rope rope,PointstartPoint){ this.currentPoint=startPoint; this.rope=rope; } public void move(){ currentPoint=rope.nextPoint(currentPoint); System.out.println("小球移动到了"+currentPoint); } }
两块石头磨成一把石刀,石刀可以砍树,砍成木材,木材做成椅子
StoneKnife knifeFactory(Stone first,Stone second);
Material stoneKnife.cut(Tree tree);
Chair chairFactory(Material material);
JDK1.5以后创建线程的新方法:线程池
//模拟车辆不断随机上路的过程 ExecutorServicepool = Executors.newSingleThreadExecutor(); pool.execute(new Runnable(){ publicvoid run(){ for(int i=1;i<1000;i++){ try { Thread.sleep((new Random().nextInt(10) +1) * 1000); }catch(InterruptedException e) { e.printStackTrace(); } vechicles.add(Road.this.name + "_" + i); } } });
定时器:
ScheduledExecutorService timer = Executors.newScheduledThreadPool(1); timer.scheduleAtFixedRate( new Runnable(){ publicvoid run(){ if(vechicles.size()>0){ boolean lighted = Lamp.valueOf(Road.this.name).isLighted(); if(lighted){ System.out.println(vechicles.remove(0) + " is traversing !"); } } } }, 1, 1, TimeUnit.SECONDS);
银行业务调度系统:
有三种对应类型的客户:VIP客户,普通客户,快速客户,异步随机生成各种类型的客户,各类型客户在其对应窗口按顺序依次办理业务
各类型客户在其对应窗口按顺序依次办理业务,准确地说,应该是窗口依次叫号。
相关文章推荐
- 经典面试题 详细解析Java中抽象类和接口的区别
- 【转载】JAVA --String类笔试面试题
- java ---- 面试题
- 转载华硕2008年Java面试题
- 黑马程序员 Java自学总结二十二 张老师7K面试题之银行业务调度系统
- 面试题:Java中对象序列化接口(Serializable)的意义
- Java面试题-基础知识
- 由一道面试题来看Java的类加载顺序
- Java面试题之四
- Java常见面试题(一)一些零碎的知识点
- Java常量池详解之抓狂的面试题
- 【Java面试题】之泛型相关
- Java面试题-基础篇一
- 【面试题】JAVA 一个线程依赖另外一个线程的结果
- 【Java】Java常见面试题(一)一些零碎的知识点
- 各大IT公司算法和数据结构面试题整理Java实现
- JAVA面试题(选择题)
- 疯狂Java学习笔记(59)-----------50道Java线程面试题
- JAVA面试题——编程题
- java面试题记录