java大学教程pptreview.ppt
《java大学教程pptreview.ppt》由会员分享,可在线阅读,更多相关《java大学教程pptreview.ppt(77页珍藏版)》请在三一办公上搜索。
1、Java语言程序设计复习,周敏彤2005-11-21,提 纲,Java概述Java基本语法程序的流程控制数组类和对象类和对象(续)类和对象(续)异常Java 2 API规范线程Java I/O操作Java图形用户界面网络编程,基本知识65,应用知识35,复习方式,听课件,理解PPT中出现的程序,练习上机作业根据复习大纲,有选择的复习,考试题型,填空(20%),判断对错(20%),选择(10%)简答题(40%)改错(10%),第1讲 Java概述,Java的发展历程(oakjava)Java技术的含义编程语言(Programming Language)运行平台(Platform)Java语言的特
2、点*简单(Simple)面向对象(Object oriented)解释性(Interpreted)平台独立和可移植(Architecture neutral&Portable)鲁棒和安全(Robust&Secure)多线程(Multithreaded)分布式(Distributed)高性能(High performance)动态(Dynamic),第1讲 Java概述,Java程序的种类*Java应用程序(Java Application)独立的Java程序程序入口方法:public static void main(String args)Java小应用程序(Java Applet)在Web
3、浏览器中运行(内嵌Java虚拟机)特定标记 Java Script嵌入在HTML文件中的脚本语言特定标记 Netscape引入javascript,第1讲 Java概述,简单的Java程序*import;class HelloWorld public static void main(String args)System.out.println(“Hello World!”);如何编写、编译和运行?什么是“.java”文件?什么是”.class”文件?什么是Java应用程序?有哪些固定格式?哪些是关键词?如何注释?import、System、class的含义?,第2讲 Java基本语法,关键词
4、*abstract double int strictfp*boolean else interface super break extends long switch byte final native synchronized case finally new this catch float package throw char for private throws class goto*protected transient const*if public try continueimplements return void default import short volatile
5、do instanceof static while 注:*当前未被使用*用于Java2,第2讲 Java基本语法,标识符*常量、变量、数据类型、类和方法public class HelloWorld1 public static void main(String args)String message=“Hello World!”;myPrint(message);private static void myPrint(String s)System.out.println(s);字母(AZ、az)、特殊符号($、_)和数字(09)第1个符号不能为数字不能为关键词、true、false、nu
6、ll区分大小写,第2讲 Java基本语法,数据类型*基本类型(primitive)数字(number)整型(integers)字节整数(byte,8 bits):-128 127,0短整数(short,16 bits):-32768 32767,0整数(int,32 bits):-2147483648 2147483647,0长整数(long,64 bits):,0L实型(real numbers):浮点型(有效位数不同)单精度(float,32 bits):,0.0F双精度(double,64 bits):,0.0D字符(char,16-bit Unicode字符):u0000 uffff布
7、尔(boolean):true,false构造/引用类型(reference):数组(Array),类(class),接口(interface),第2讲 Java基本语法,常量与变量*int i=178;long l=8864L;(8864l)double d1=37.266;double d2=37.266D;(37.266d)double d3=26.77e3;float f=87.363F;(87.363f)char c=d;boolean b1=true;十进制、八进制、十六进制123、023、0 xFEfinal变量,第2讲 Java基本语法,变量定义域*if(.)int i=17;
8、.System.out.println(The value of i=+i);,第2讲 Java基本语法,运算符*算术运算符 加法运算符+“op1+op2”减法运算符-“op1-op2”乘法运算符*“op1*op2”除法运算符/“op1/op2”求模运算符%“op1%op2”计算余数关系运算符大于“op1 op2”大于等于=“op1=op2”小于“op1 op2”小于等于=“op1=op2”等于=“op1=op2”不等于!=“op1!=op2”,第2讲 Java基本语法,运算符*逻辑运算符逻辑与 42&15、43&1、42|15、42 15,第2讲 Java基本语法,运算符*移位运算符左移“o
9、p1 op2”无符号右移“op1 op2”int a=42;int aa=a 2;System.out.println(“aa=”+aa);条件运算符op1?op2:op3运算符的优先级,第2讲 Java基本语法,运算符*自增运算符(+)、自减运算符(-)“赋值”和“运算”的先后顺序,int i=10;int n=i+%5;,int i=10;int n=+i%5;,i=11,n=0,i=11,n=1,第2讲 Java基本语法,类型转换*隐型类型转换:自动类型转换(系统完成)宽化转换(widening conversion)byte j=60;short k=4;int l=31;long m
10、=4l;long result=0l;result+=j-8;result*=k+2;result/=m+1;result-=l;result%=m;显型类型转换:强制类型转换窄化转换(narrowing conversion)double a=1.5;float b=a;System.out.println(“b=+b);编译:“possible loss of precision”数据精度丢失数据丢失,第3讲 程序的流程控制,多个read方法的使用import;class Read1 public static void main(String args)throws IOExceptio
11、n char c;System.out.println(Please input a char:);c=();System.out.println(Received char=+c);import;class Read2 public static void main(String args)throws IOException byte b=new byte10;System.out.println(Received number=+System.in.read(b);,第3讲 程序的流程控制,多个read方法的使用import;class Read3 public static void
12、main(String args)throws IOException byte b=new byte10;System.out.println(Input 3 characters:”);System.out.println(“The number=”+System.in.read(b);System.out.println(Input 1 character:”);System.out.println(“The number=”+System.in.read(b,5,1);for(int i=0;i b.length;i+)System.out.print(bi+“”);,第3讲 程序的流
13、程控制,println和print方法的区别*是否存在“回车/换行”class Test public static void main(String args)boolean a=true;char b=A;int c=100;System.out.print(“a=”+a);(“b=”+b);(“c=”+c);,第3讲 程序的流程控制,方法重载*方法名相同,但方法的参数不同能不能根据方法返回值的不同实现重载?void f()int f()f();,第3讲 程序的流程控制,条件选择语句*if和if-else语句if语句的嵌套int a=1,b=2,c=3;if(ac)if(cb)System
14、.out.print(c);else System.out.print(a);,修改配对关系:if(ac)if(cb)System.out.print(c);else System.out.print(a);,默认Java虚拟机:if(ac)if(cb)System.out.print(c);else System.out.print(a);,第3讲 程序的流程控制,switch语句*switch(表达式)case 值1:语句序列;break;case 值2:语句序列;break;default:默认语句;,第3讲 程序的流程控制,switch语句*,public class Test pub
15、lic static void main(String args)int month=2,year=2000;int numDays=0;switch(month)case 1:case 3:case 5:case 7:case 8:case 10:case 12:numDays=31;break;case 4:case 6:,case 9:case 11:numDays=30;break;case 2:if(year%4=0),第3讲 程序的流程控制,循环控制语句*while循环do-while循环for循环import;class Test public static void main(
16、String args)throws IOException int i,n,sum=1;System.out.println(“Please input(09):”);n=();n-=48;for(i=1;i=n;i+)sum*=i;System.out.println(n+“!=”+sum);,第3讲 程序的流程控制,循环控制语句*循环的嵌套import;class Test public static void main(String args)throws IOException int n,sum,total=0;System.out.println(“Please input(09
17、):”);n=();n-=48;for(int j=1;j=n;j+)sum=1;for(int i=1;i=j;i+)sum*=i;total+=sum;(“各阶乘之和为:”+total);,第3讲 程序的流程控制,跳转语句*continue 结束本次循环break 跳出(中止)循环class Test public static void main(String args)for(int j=1;j 6;j+)if(j=3)break;System.out.print(“j=“+j);(“stop”);,第3讲 程序的流程控制,跳转语句*带标号的break语句class Test publ
18、ic static void main(String args)int j,k;Rep:for(j=8;j 1;j-)for(k=1;k”);,第3讲 程序的流程控制,跳转语句*带标号的continue语句class Test public static void main(String args)iLoop:for(int i=1;i=10)System.out.print(p+“”);else System.out.print(p+“”);();,第4讲 数组,一维数组的声明*方法1:类型 数组名;方法2:类型 数组名;注意类型是数组中元素的数据类型(基本和构造类型)数组名是一个标识符数组
19、声明后不能被访问,因未为数组元素分配内存空间String args;int a;double amount;char c;一维数组的创建*用new来创建数组为数组元素分配内存空间,并对数组元素进行初始化int i=new int3;,第4讲 数组,一维数组*class Test public static void main(String args)int i=new int3;float f=new float3;boolean b=new boolean3;char c=new char3;for(int j=0;j i.length;j+)System.out.println(ij);f
20、or(int j=0;j f.length;j+)System.out.println(fj);for(int j=0;j b.length;j+)System.out.println(bj);for(int j=0;j c.length;j+)System.out.println(cj);,第4讲 数组,一维数组的排序*public class Test public static void main(String args)int array=32,87,3,589,12,1076,2000,8,622,127;for(int i=array.length;-i=0;)for(int j=
21、0;j arrayj+1)int temp=arrayj;arrayj=arrayj+1;arrayj+1=temp;for(int i=0;i array.length;i+)System.out.print(arrayi+);,第4讲 数组,二维数组的声明*类型 数组名,例 int a;二维数组的创建*方法1:直接分配空间(new)int a=new int23;a00 a01 a02a10 a11 a12方法2:从最高维开始,为每一维分配空间int c=new int2;c0=new int4;c1=new int3;c00 c01 c02 c03c10 c11 c12,第4讲 数组,二
22、维数组*class Test public static void main(String args)int a=new int33;a00=1;a11=1;a22=1;(“数组a:”);for(int i=0;i a.length;i+)for(int j=0;jai.length;j+)System.out.print(aij+“”);();,第4讲 数组,二维数组的最高维*int a=1,2,3,3,4,5;a00=1 a01=2 a02=3a10=3 a11=4 a12=5 String cartoons=“Flint”,Fred“,Wim“,Pebbles“,Dino,Rub“,Ba
23、rn“,Bet,Bam,Jet“,Geo“,Jane“,Elroy“,Judy“,Rosie,Sco“,Sco“,Shag“,Velma“,Fred“,Dap;,第4讲 数组,数组的界限*起点和终点数组的长度:数组名.length起点:数组名0终点:数组名length-1int i=4,56,78,9,34;i.length 5i0 4ilength-1=i434ia 若a4 则?,第5讲 类和对象,面向对象编程的特点 用客观世界中描述事物的方法来描述程序中要解决的问题万事万物都是对象程序便是成堆的对象,彼此通过消息的传递,请求其他对象进行工作五个基本概念*对象 状态:指对象本身的信息行为:实
24、现对信息的访问消息对象之间的交互和通信是通过相互间发送消息来实现类类是对象的模板(template)/抽象一个对象是类的一个实例(instance)继承-树型结构多态性-不同的子类中同样的方法有不同的表现形式,第5讲 类和对象,多态性*,class Square extends Shape void draw()System.out.println(Square.draw();void erase()System.out.println(Square.erase()“);class Triangle extends Shape void draw()System.out.println(Tri
25、angle.draw();void erase()System.out.println(Triangle.erase();,class Shape void draw()void erase()class Circle extends Shape void draw()System.out.println(Circle.draw();void erase()System.out.println(Circle.erase();,第5讲 类和对象,类的定义格式*类修饰符 class 类名extends 父类名 implements 接口名 类型成员变量1;类型成员变量2;类型成员方法1(参数1,参
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 大学 教程 pptreview

链接地址:https://www.31ppt.com/p-6509743.html