OOP with Java 通知 Project 7, 6 月 14 日晚 9 点 本周四上机课正常进行 答疑 本周三, 周五下午 1:00 3:00, 理科楼 B911 6 月 12 日考试 ( 随堂 ) 下午 1:00-3:00 教书院 218

Similar documents
OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

OOP with Java 通知 Project 3: 4 月 19 日晚 9 点

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

OOP with Java 通知 Project 4: 推迟至 4 月 25 日晚 9 点

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

OOP with Java 通知 Project 7 :6 月 14 日晚 9 点 6 月 5 日复习 6 月 12 日考试

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 Project 7 :6 月 27 日晚 9 点 6 月 14 日复习 6 月 21 日考试 答疑 6 月 20 日 13 : : 00 理科楼 B911

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料

OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢

OOP with Java 通知 Project 6: 6 月 6 日晚 9 点

OOP with Java 通知 Project 6: 5 月 24 日晚 9 点

OOP with Java 通知 Project 6: 5 月 30 日晚 9 点

OOP with Java 通知 Project 2 提交时间 : 3 月 21 日晚 9 点 作业提交格式 学习使用 文本编辑器 cmd, PowerShell (Windows), terminal(linux, Mac)

EJB-Programming-4-cn.doc

chp6.ppt

OOP with Java 通知 Project 6: 5 月 24 日晚 9 点

软件工程文档编制

Microsoft Word - 01.DOC

untitled

无类继承.key

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

3.1 num = 3 ch = 'C' 2

《大话设计模式》第一章

模板

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:


JavaIO.PDF

javaexample-02.pdf

untitled

Java

Microsoft Word - 新1-12.doc

EJB-Programming-3.PDF

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

untitled

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

슬라이드 1

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基

Microsoft PowerPoint - plan08.ppt

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

untitled

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

拦截器(Interceptor)的学习

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

Guava学习之Resources

D C 93 2

java2d-4.PDF

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

2009年9月全国计算机等级考试二级Java真题及答案

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

使用MapReduce读取XML文件

Microsoft PowerPoint - 6. 用户定义类型User-defined Datatypes.ppt [兼容模式]

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

while ((ch = fr.read())!= -1) { System.out.print((char) ch); fr.close(); 例 3: 用 BufferedReader 读 TXT 文件 public class FileReaderDemo3 { public static v

FileMaker 16 ODBC 和 JDBC 指南

untitled

提问袁小兵:

基于CDIO一体化理念的课程教学大纲设计

RUN_PC連載_12_.doc

2. AOP 底层技术实现 小风 Java 实战系列教程 关键词 : 代理模式 代理模型分为两种 : 1) 接口代理 (JDK 动态代理 ) 2) 子类代理 (Cglib 子类代理 ) 需求 :CustomerService 业务类, 有 save,update 方法, 希望在 save,updat

CC213

javac: 负 责 的 是 编 译 的 部 分, 当 执 行 javac 时, 会 启 动 java 的 编 译 器 程 序 对 指 定 扩 展 名 的.java 文 件 进 行 编 译 生 成 了 jvm 可 以 识 别 的 字 节 码 文 件 也 就 是 class 文 件, 也 就 是 ja

概述

ebook55-13

chap07.key

Java第一天 年4月23日

// 获取并集 // set1.addall(set2); // 获取交集 set1.retainall(set2); // 打印操作结果 set1.foreach(o -> System.out.println(o)); 运行结果如图 6-1 所示 图 6-1 运行结果 三 案例总结 1 Coll

c_cpp

Microsoft PowerPoint - course2.ppt

FileMaker 15 ODBC 和 JDBC 指南

Microsoft Word - 第5章.doc

FY.DOC

C/C++语言 - C/C++数据

二 Synchronized 1. Java 语 言 的 关 键 字, 当 它 用 来 修 饰 一 个 方 法 或 者 一 个 代 码 块 的 时 候, 能 够 保 证 在 同 一 时 刻 最 多 只 有 一 个 线 程 执 行 该 段 代 码 2. 当 两 个 并 发 线 程 访 问 同 一 个

新版 明解C++入門編

IoC容器和Dependency Injection模式.doc

尽 管 Java 语 言 是 在 C++ 语 言 基 础 上 发 展 起 来 的, 但 是 有 别 于 C++,Java 是 一 种 纯 粹 的 面 向 对 象 语 言 (Object-oriented language) 在 像 Java 这 样 纯 粹 的 面 向 对 象 语 言 中, 所 有

Swing-02.pdf

Microsoft PowerPoint - string_kruse [兼容模式]

Strings

Java 1 Java String Date

北 风 网 讲 师 原 创 作 品 ---- 仅 供 学 员 内 部 交 流 使 用 前 言 吾 尝 终 日 而 思 矣, 不 如 须 臾 之 所 学 也 ; 吾 尝 跂 而 望 矣, 不 如 登 高 之 博 见 也 登 高 而 招, 臂 非 加 长 也, 而 见

Transcription:

OOP with Java Yuanbin Wu cs@ecnu

OOP with Java 通知 Project 7, 6 月 14 日晚 9 点 本周四上机课正常进行 答疑 本周三, 周五下午 1:00 3:00, 理科楼 B911 6 月 12 日考试 ( 随堂 ) 下午 1:00-3:00 教书院 218

OOP with Java 题目类型 : 选择 : 30% 问答 : 30% 编程 : 40%

OOP with Java 复习 面向对象编程的要素 Java 类型 Java 控制结构 类 Java 包 访问控制 类的复用 Upcasting 和多态 抽象类和接口 内部类 异常 容器 I/O 语言基础类类型间关系错误处理应用

面向对象编程概述 对象的基本要素 : 状态, 行为, 类型 数据成员方法成员类型关系

面向对象编程概述 对象的状态 数据成员 对象的行为 方法 访问控制 ( 封装 ): public, private, protected 对象的类型 类与类的对象 基本类型与 class

面向对象编程概述 对象 vs. 类型 类型 Light on() off() bright() dim() 对象 Light m = new Light(); m.on(); Light n = new Light(); n.off();

面向对象编程概述 对象的类型 如何通过以后的类型定义新的类型? 组合 : has-a 继承 : is 不同类型间的关系 基本类型之间的转换关系 Autoboxing, unboxing Upcasting, downcasting

Java 类型 Java 类型 : 基本类型, 数组, 类 定义, 创建, 使用

Java 类型 基本类型 boolean, char, byte, short, int, long, float, double 基本类型的封装 Boolean, Character, Byte, Short, Integer, Long, Float, Double 定义 创建 int a = 1, double d = 1.0; 使用 int b = a * 2;

Java 类型 class 定义创建使用 class MyType { int i; double d; char c; void set(double x); double get(); MyType a = new MyType(); int b = a.i; a.set(); a.get();

Java 类型 数组 定义初始化使用 int a[ ]; int [ ]a; MyType [ ]m; MyType [ ][ ]m; // 静态初始化 int [ ]a = {1, 2, 3, 4, 5; int [ ][ ] a= { {1,2,3, {4, 5, 6 ; // 动态初始化 1 int [ ]a = new int[5]; // 动态初始化 2 MyType [ ]a = new MyType[] { new MyType(), new MyType(), new MyType() ; int b = a[1]; int len = a.length;

Java 类型 引用 对象的名字 同一个对象可以有不同的名字 绝大多数使用指针实现 题目 : int [ ] a = new int[]{1,2,3; int [ ] b; b = a; b[0] = 4; System.out.println(a[0]);

Java 类型 不可变类型 一旦创建不能改变 String, Integer, final 关键字 final 数据, 方法, 参数, 类 static final final 数据初始化

Java 控制结构 操作符 == 与 equals() 字符串连接操作 : += 控制语句 条件与 boolean for each 题目 : int [ ] a = new int[2]{1,2; System.out.println(a[0] + a[1] + ); System.out.println( + a[0] + a[1] );

类 普通成员 静态成员 静态数据 所有对象共享数据 静态方法 main 函数 public class StaticTest { double d; static int i = 1; static void display() { System.out.println( Hello ); public static void main(string [ ]args) { display(); StaticTest.display(); StaticTest s = new StaticTest(); System.out.println(s.i); System.out.println(StaticTest.i)

类 类的数据成员 this 关键字 在类的非静态方法中, 返回调用该方法的对象的引用 super 关键字 在子类对象中包含的父类对象的引用 数据成员的初始化 初始化的值 初始化的顺序 静态成员 / 非静态成员 子类成员 / 父类成员 构造函数

类 类的方法 构造函数 名称与类名称相同, 无返回值, 为类的静态方法 默认构造函数 public class MyType { int i; double d; char c; void set(double x) { d = x; double get() { return d; public static void main(string [ ]args) { MyType m = new MyType(); MyType n = new MyType(); m.set(1); n.set(2);

类 类的方法 重载 方法名相同, 参数类型 / 数量不同 如何区分不同的函数? 函数名 + 参数列表 重写 子类重写父类的方法

类 类的销毁 垃圾回收 1. 仅回收 new 创建的内存. 2. 是否回收, 何时回收由 Java 虚拟机控制.

Java 包 什么是 Java 包 一组类的集合, 共享一个名字空间 如何使用包 import 语句 如何定义包 package 语句 包结构与目录结构 如何编译包

Java 访问控制 四种访问控制类型 package access 默认包 public private protected

类的复用 如何通过已有类定义新的类? 组合 将已有的类作为新类的数据成员 继承 新类包含已有类的方法和数据 并可修改 / 增添 ( 重写 ) 如何实现? 隐含一个父类对象 class MyType { public int i; public double d; public char c; public void set(double x) { d = x; public double get() { return d; public class MyCompType { private MyType m = new MyType(); private String s; public MyCompType(){ s = new String( Hello ); public class MySubType extends MyType{ public static void main(string [ ]args){ MySubType ms = new MySubType(); ms.set(1.0); System.out.println(ms.get()); System.out.println(ms.i);

类的复用 子类可以定义新的方法 / 数据 protected 关键字 子类可以修改父类的方法 : 重写 class MyType { public int i; public double d; public char c; public void set(double x) { d = x; public double get() { return d; public class MySubType extends MyType{ public void set(double x){ i = (int)x; public double get() { return i; public static void main(string [ ]args){ MySubType ms = new MySubType(); ms.set(1.0); System.out.println(ms.get()); System.out.println(ms.i); System.out.println(ms.d);

类的复用 super 关键字 子类的对象包含一个隐藏的父类对象 在子类中, super 用来指代父类对象的引用 子类, 父类的构造函数调用顺序 Object 类 所有类都是 Object 类的子类 Object B MyType A MySubType

Upcasting 和多态 Upcasting 子类是一种父类 父类出现之处子类也可使用 class A{ class B{ A a = new A(); B b = new B(); // A a = new B(); compile error class A{ class B extends A{ A a = new A(); B b = new B(); A a = new B(); // upcasting

Upcasting 和多态 class Instrument { public void play() { static void tune(instrument i) { //... i.play(); public class Wind extends Instrument { public static void main(string[] args) { Wind flute = new Wind(); Instrument.tune(flute);

Upcasting 和多态 多态 子类重写了父类方法 f() 当使用父类引用访问子类对象时, 调用 f() 将绑定到子类的方法

Upcasting 和多态 class Instrument { public void play(int note) { System.out.println( Instrument.play() + n); public class Wind extends Instrument { public void play(int note) { System.out.println( Wind.play() + n); public class Music { public static void tune(instrument i) { i.play(); public static void main(string []args){ Wind flute = new Wind(); Stringed violin = new Stringed(); Brass frenchhorn = new Brass(); tune(flute); tune(violin); tune(frenchhorn); public class Stringed extends Instrument { public void play(int note) { System.out.println( Stringed.play() + n); public class Brass extends Instrument { public void play(int note) { System.out.println( Brass.play() + n);

Upcasting 与多态 interface DifferentiableFunction { double eval(double x); double diff(double x); 数值计算 class Linear implements DifferentiableFunction { public double eval(double x) { // public double diff(double x) { // class Sin implements DifferentiableFunction { public double eval(double x) { // public double diff(double x) { // class Quadratic implements DifferentiableFunction { public double eval(double x) { // public double diff(double x) { // public class NewtonRoot { public static double findroot(differentiablefunction f) { // newton method... public static void main(string []args){ Linear l = new Linear(); Sin s = new Sin(); Quatratic q = new Quatratic(); findroot(l); findroot(s); findroot(q);

Upcasting 与多态 例子 : ArrayList a = new ArrayList(); a.add( Hello ); catch(exception e)

接口与抽象类 抽象方法 (abstract method) 仅提供方法的名称, 参数和返回值没有具体实现 使用 abstract 关键字 抽象类 (abstract class) 包含抽象方法的类称为抽象类 不完整, 不能实例化 ( 创建对象 ), 必须被继承 class Instrument { public void play(int note) { System.out.println( Instrument.play() + n); 普通方法 abstract class Instrument { public abstract void play(int note) ; 抽象方法

接口与抽象类 abstract class Instrument { public abstract void play(int note) ; public class Wind extends Instrument { public void play(int note) { System.out.println( Wind.play() + n); public class Stringed extends Instrument { public void play(int note) { System.out.println( Stringed.play() + n); public class Brass extends Instrument { public void play(int note) { System.out.println( Brass.play() + n); public class Music { public static void tune(instrument i) { i.play(); public static void main(string []args){ Wind flute = new Wind(); Stringed violin = new Stringed(); Brass frenchhorn = new Brass(); tune(flute); tune(violin); tune(frenchhorn); Upcasting 与多态

接口与抽象类 接口 只有方法的名称, 参数和返回值没有方法的实现 interface/implement 关键字

接口与抽象类 abstract class Instrument { public abstract void play(int note); public abstract String what(); interface Instrument { void play(int note) ; String what(); class Stringed extends Instrument { public void play(int note) { System.out.println( Stringed.play() + n); public String what() {return Stringed ; class Stringed implements Instrument { public void play(int note) { System.out.println( Stringed.play() + n); public String what() {return Stringed ; 继承 : 1. extends 关键字 2. 父类, 子类关系 3. class, extends 接口 : 1. implements 关键字 2. 接口, 实现关系 3. interface, implements

接口与抽象类 一个类实现多个接口 Interface Plane void fly() Interface Boat void sail() implements Seaplane void fly() void sail()

接口与抽象类 interface Plane { void fly(); interface Boat { void sail(); class Seaplane implements Plane, Boat { public void fly(){ System.out.println( Fly! ); public void sail(){ System.out.println( Sail! );

接口与抽象类 Upcasting 与多态 interface CanFight { void fight(); interface CanSwim { void swim(); interface CanFly { void fly(); class ActionCharacter { public void fight() { class Hero extends ActionCharacter Implements CanFight, CanSwim, CanFly{ public void fly() { public void swim() { public class Adventure { public static void t(canfight x) { x.fight(); public static void u(canswim x) { x.swim(); public static void v(canfly x) { x.fly(); public static void w(actioncharacter x) { x.fight(); public static void main(string []args) { Hero h = new Hero(); t(h); u(h); v(h); w(h);

接口与抽象类 实现多个接口 父类只能有一个普通类 / 抽象类 Abstract or Concrete Base class interface 1 interface 2 interface n Base class methods interface 1 interface 2... interface n Methods of the derived class

接口与抽象类 扩展接口 interface A { interface B extends A{ interface D { interface D extends A, C{

内部类 内部类 (Inner class) 定义在一个类的内部 与组合不同 帮助隐藏实现细节 class Outer{ class Inner{... Inner class... Composition class Outer{ Inner in = new Inner();... class Inner{.

public class Sequence{ private Object[] items; private int next = 0; public Sequence (int size) {items = new Object[size]; public void add(object x){ if (next < items.length) items[next++] = x; private class SequenceSelector implements Selector{ private int i = 0; public boolean end() {return i == items.length; public Object current () {return items[i]; public void next() { if(i < items.length) i++; public Selector selector(){ return new SequenceSelector(s); public static void main(string []args){ Sequence seq = new Sequence(10); for (int i = 0; i < 10; ++i) seq.add(integer.tostring(i)); Selector s = seq.selector(); while(!s.end()) { System.out.println(s.current() + ); s.next(); interface Selector{ boolean end(); Object current(); void next(); 1. Sequence 类包含内部类 SequenceSelector 2. 内部类实现接口 Selector 3. 内部类能访问 Sequence 的 private 成员 4. 内部类为 private 5. 内部类的对象隐藏包含一个外部类对象的引用 - 多数情况下由编译器自动完成 upcasting: Object / selector()

内部类 内部类和外部类的关系 内部类的对象隐含了一个引用, 指向包含它的外部类对象 如何在内部类中访问外部类对象的引用? OuterClassName.this 如何创建内部类的对象 在外部类的方法中 : 直接创建 其他地方 : OuterClassObject.new

匿名内部类 ( 匿名类 ) 匿名类 没有名字的内部类, 没有构造函数, 同时定义和创建 必须继承某个类, 或实现某个接口 public class Parcel{ public Contents contents(){ return new Contents() { // anonymous inner class definition private int i = 11; public int value() {return i; ; public static void main(string []args){ Parcel p = new Parcel(); Contents c = p.contents(); public interface Contents{ int value(); 创建一个实现 Contents 的匿名类 语法解释 1. ; 为 return 语句的分号 2. 在 return 语句中定义匿名类 - 实现 Contents 接口 - 花括号内部 3. 创建一个改匿名类的对象 - new Content () {

匿名类 匿名类 public class Parcel{ public Contents contents(){ return new Contents() { // anonymous inner class definition private int i = 11; public int value() {return i; ; public class Parcel{ class PContents implements Contents{ private int i = 11; public int value() {return i; public Contents contents(){ return new PContents() ; public static void main(string []args){ Parcel p = new Parcel(); Contents c = p.contents(); public static void main(string []args){ Parcel p = new Parcel(); Contents c = p.contents();

容器 Collection Map List Set Queue HashMap TreeMap LinkedHashMap

容器 容器与泛型 public class ApplesAndOrangesWithGenerics { public static void main(string[] args) { ArrayList<Apple> apples = new ArrayList<Apple>(); for(int i = 0; i < 3; i++) apples.add(new Apple()); // Compile error! // apples.add(new Orange()); for(int i = 0; i < apples.size(); i++) apples.get(i).id(); for(apple c: apples) System.out.println(c.id());

容器 upcasting 和多态 class GrannySmith extends Apple { class Gala extends Apple { class Fuji extends Apple { class Braeburn extends Apple { public class GenericsAndUpcasting { public static void main(string[] args) { ArrayList<Apple> apples = new ArrayList<Apple>(); apples.add(new GrannySmith()); apples.add(new Gala()); apples.add(new Fuji()); apples.add(new Braeburn()); for(apple c : apples) System.out.println(c);

容器 List 实现原理 接口 : add(), remove(), get() 迭代器 LinkedList 与 Queue 接口 Collection List Set Queue ArrayList LinkedList

容器 Set, Queue 基本接口及使用 HashSet Map 基本接口及使用 HashMap

异常 抛出异常 throw 处理异常 try, catch, finally 异常对象 Exception 类的子类

异常 Upcasting 与多态 class SimpleException extends Exception { public class InheritingExceptions { public static void main(string[] args) { try { System.out.println("Throw SimpleException from f()"); throw new SimpleException(); catch(exception e) { System.out.println("Caught it!"); System.out.println(e); System.out.println(e.printStackTrace(System.out));

异常 从方法中抛出异常 方法的异常说明 :throws 中断当前方法的执行, 返回抛出的异常对象, 在该方法的调用路径上寻找合适的 catch.

异常 bar() throws Type1Exception, Type2Exception{ throw new Type1Exception (); throw new Type2Exception (); foo() { try{ bar(); catch (Type1Exception e){... catch (Type2Exception e){...

I/O I/O 流 InputStream/Reader read() OutputStream/Writer write() 抽象 : 数据的来源 / 数据的目的地 ByteArrayStream, FileStream...

I/O import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception; public class CopyBytes { public static void main(string[] args) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("xanadu.txt"); out = new FileOutputStream("outagain.txt"); int c; while ((c = in.read())!= -1) out.write(c); finally { if (in!= null) in.close(); if (out!= null) out.close();

I/O 装饰器 FilterInputStream/FilterOutputStream BufferedInputStream DataInputStream

I/O Upcasting 和多态 FileInputStream fin = new FileInputStream("xanadu.txt"); BufferedInputStream bf = new BufferedInputStream(fin); DataInputStream din = new DataInputStream(bf); din.read(); din.readint(); din.readdouble(); FileOutputStream fout = new FileOutputStream("xanadu.txt"); BufferedOutputStream bf = new BufferedOutputStream(fout); DataOutputStream dout = new DataOutputStream(bf); dout.write(1); dout.writeint(10); dout.writedouble(3.14);

泛型 如何定义泛型类, 泛型接口 class Apple { public class Holder<T> { private T a; public Holder(T a) { this.a = a; public void set(t a) { this.a = a; public T get() { return a; public static void main(string[] args) { Holder<Apple> h = new Holder<Apple>( new Apple()); Apple a = h.get(); public interface Generator<T> { T next(); public class Fibonacci implements Generator<Integer> { private int count = 0; public Integer next() { return fib(count++); private int fib(int n) { if(n < 2) return 1; return fib(n-2) + fib(n-1); public static void main(string[] args) { Fibonacci gen = new Fibonacci(); for(int i = 0; i < 18; i++) System.out.print(gen.next() + " ");

考试内容将不包含 char 的 unicode 表示 赋值左值表达式, 右值表达式 垃圾回收的实现原理 嵌套类, 适配器模式, 工厂模式 TreeSet, LinkedHashSet, TreeHashMap, LinkedHashMap 的实现原理 RTTI, type erasure, 被限定类型的泛型, 通配符