Java期末复习讲义.docx
《Java期末复习讲义.docx》由会员分享,可在线阅读,更多相关《Java期末复习讲义.docx(10页珍藏版)》请在冰点文库上搜索。
Java期末复习讲义
Java复习讲义
一、基础知识
1、面向对象程序设计
2、Java语言的特点
3、Java语言的运行环境
4、Java程序分类
1)Application
2)Applet
5、基本数据类型
1)基本数据类型
byteintshortlong
floatdouble
char
boolean
2)类型转换
隐式转换(自动)int+double+char
显式转换(强制类型转换)
intI;
I=(int)3.14;
6、数组
1)一维
inta[];
int[]a;
a=newint[];
a={1,6,32,11};
2)多维(以二维为例)
inta[][];
int[][]a;
7、方法的控制流程
1)分支结构
ifswitch
2)循环结构
while
do-while
for
breakcontinue
二、Java的类定义
1、类的含义
2、类定义格式
3、类成员
数据成员
方法
4、对象创建
5、类成员的访问
classStudent{
intsno;
Stringname;
intage;
publicvoidshow(){
System.out.println(sno+","+name+","+age);
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Studentstu=newStudent();
stu.sno=1;
stu.name="zhangsan";
stu.age=21;
stu.show();
}
}
6、构造方法
classStudent{
intsno;
Stringname;
intage;
publicStudent(intsno,Stringname,intage){
this.sno=sno;
this.name=name;
this.age=age;
}
publicStudent(){}
publicvoidshow(){
System.out.println(sno+","+name+","+age);
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Studentstu=newStudent(1,"zhangsan",21);
Studentstu1=newStudent();
stu.show();
}
}
7、修饰词的用法
(一)
1)Static
classStudent{
intsno;
Stringname;
intage;
publicStudent(intsno,Stringname,intage){
this.sno=sno;
this.name=name;
this.age=age;
}
publicStudent(){}
publicvoidshow(){
System.out.println(sno+","+name+","+age);
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Studentstu=newStudent(1,"zhangsan",21);
Studentstu1=newStudent();
stu.show();
}
}
2)public访问权限
public,private,protected,默认
8、包的知识
1)什么是包
2)包的引入
3)定义包
三、异常处理
1、异常的概念
2、异常处理的方法
1)try{……}
catch(){……}
finally{}
2)抛出throw,throws
publicvoidf()throwsException{
}
publicvoidf(){
throw
}
3、自定义异常
四、继承(类的重用)
1、什么是继承
2、继承的语法
classFather{
privateinta;
intb;
voidf(){}
}
classSonextendsFather{
intd;
voidff(){}
}
4、成员变量的隐藏
classFather{
inta=3;
intb;
voidf(){System.out.println(a);}
}
classSonextendsFather{
inta=5;
voidff(){
System.out.println(a);
System.out.println(super.a);
}
}
5、方法的覆盖(方法的重写)
classFather{
inta=3;
intb;
voidf(){System.out.println("我是父亲的方法");}
}
classSonextendsFather{
inta=5;
voidf(){System.out.println("我是儿子的方法");}
voidff(){
f();
super.f();
}
}
注意:
区别方法的重载
6、继承关系下的构造方法
classA{
inta;
publicA(inti){a=i;}
publicA(){}
}
classBextendsA{
intb;
publicB(inti,intj){
super(i);
b=j;
}
publicB(){
super();
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Aobj1=newA(3);
Bobj2=newB(4,6);
}
}
6、修饰词
(二)final
●放在成员变量前面,相当于变量的值不能被修改
●放在方法前面,子类不能重写这个方法
●放在类的前面,该类不能派生子类
五、类的组合
1、组合的语法
2、组合和继承的区别
classPoint{
intx,y;
}
classCircle{
Pointp;
intradius;
}
3、既有类的继承,又有类的组合,构造方法如何调用
六、抽象类
1、
abstractclassA{
publicvoidf1(){....}
publicvoidf2(){}
abstractpublicvoidf3();//抽象方法
abstractpublicvoidf4();
}
classBextendsA{
publicvoidf3(){....}
publicvoidf4(){....}
}
2、举例说明
七、接口
八、多态
1、什么是塑型
2、塑型的应用
3、方法的查找
4、多态的概念
5、动态绑定
6、构造方法与多态
九、输入输出
1、I/O流的概念
2、常用的输入输出流类
3、读写文本文件
4、读写二进制文件
十、多线程的概念