欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    java大学教程pptrev.ppt

    • 资源ID:6509744       资源大小:287.49KB        全文页数:77页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    java大学教程pptrev.ppt

    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语言的特点*简单(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浏览器中运行(内嵌Java虚拟机)特定标记 Java Script嵌入在HTML文件中的脚本语言特定标记 Netscape引入javascript,第1讲 Java概述,简单的Java程序*import java.lang.System;class HelloWorld public static void main(String args)System.out.println(“Hello World!”);如何编写、编译和运行?什么是“.java”文件?什么是”.class”文件?什么是Java应用程序?有哪些固定格式?哪些是关键词?如何注释?import、System、class的含义?,第2讲 Java基本语法,关键词*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 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、null区分大小写,第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布尔(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;.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基本语法,运算符*移位运算符左移“op1 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=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 java.io.IOException;class Read1 public static void main(String args)throws IOException char c;System.out.println(Please input a char:);c=(char)System.in.read();System.out.println(Received char=+c);import java.io.IOException;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 java.io.IOException;class Read3 public static void 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讲 程序的流程控制,println和print方法的区别*是否存在“回车/换行”class Test public static void main(String args)boolean a=true;char b=A;int c=100;System.out.print(“a=”+a);System.out.print(“b=”+b);System.out.print(“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.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 public 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 java.io.IOException;class Test public static void main(String args)throws IOException int i,n,sum=1;System.out.println(“Please input(09):”);n=System.in.read();n-=48;for(i=1;i=n;i+)sum*=i;System.out.println(n+“!=”+sum);,第3讲 程序的流程控制,循环控制语句*循环的嵌套import java.io.IOException;class Test public static void main(String args)throws IOException int n,sum,total=0;System.out.println(“Please input(09):”);n=System.in.read();n-=48;for(int j=1;j=n;j+)sum=1;for(int i=1;i=j;i+)sum*=i;total+=sum;System.out.println(“各阶乘之和为:”+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);System.out.println(“stop”);,第3讲 程序的流程控制,跳转语句*带标号的break语句class Test public 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+“”);System.out.println();,第4讲 数组,一维数组的声明*方法1:类型 数组名;方法2:类型 数组名;注意类型是数组中元素的数据类型(基本和构造类型)数组名是一个标识符数组声明后不能被访问,因未为数组元素分配内存空间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);for(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=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讲 数组,二维数组*class Test public static void main(String args)int a=new int33;a00=1;a11=1;a22=1;System.out.println(“数组a:”);for(int i=0;i a.length;i+)for(int j=0;jai.length;j+)System.out.print(aij+“”);System.out.println();,第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“,Barn“,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讲 类和对象,面向对象编程的特点 用客观世界中描述事物的方法来描述程序中要解决的问题万事万物都是对象程序便是成堆的对象,彼此通过消息的传递,请求其他对象进行工作五个基本概念*对象 状态:指对象本身的信息行为:实现对信息的访问消息对象之间的交互和通信是通过相互间发送消息来实现类类是对象的模板(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(Triangle.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,参数2,)方法体;类型成员方法2(参数1,参数2,)方法体;,第5讲 类和对象,类的定义格式类修饰符 class 类名 extends 父类名 implements 接口名 常见的类修饰符*public:Declares that the class can be used by any class regardless of its package(无任何限制)无修饰:a class can be used only by other classes in the same package(仅仅能被同一个包中的其他类引用)abstract:Declares that the class cannot be instantiated(声明该类不能被实例化,抽象类)final:Declares that the class cannot be subclassed(声明该类不能有子类),第5讲 类和对象,类的定义格式类修饰符 class 类名 extends 父类名 implements 接口名 继承与实现*extends:继承的关系implements:实现哪些接口(interface)的方法,实现多重继承,第5讲 类和对象,类成员的访问修饰符*publicprivateprotected无修饰staticfinal,第5讲 类和对象,静态变量和静态方法*类的变量/方法,独立于类的对象,可以直接根据类名调用class S static int A=12,B=34;static void print();class Test public static void main(String args)System.out.println(“A=“+S.A+“B=“+S.B);S.print();,第5讲 类和对象,成员方法的访问*,class Test public static void main(String args)double d_product;Area myArea;myArea=new Area();d_product=myArea.product();System.out.println(“myArea的面积是:”+d_product);,class Area Area();double width,height;void set(double w,double h)width=w;height=h;double product()return width*height;,第5讲 类和对象,方法参数的传值(pass by value)*基本类型与复合类型参数传递的结果不同,第5讲 类和对象,class Example Example();int u,v;void compute(int x,int y)int i,j;for(i=1;i=x;i+)j=y+i;System.out.print(j+“”);void p()u=3;v=2;compute(u,v);System.out.println();u+=v;v*=u;compute(u,v);public static void main(String args)Example A=new Example();A.p();,第5讲 类和对象,方法重写*子类重写(重新定义)父类的方法,class Father void display();,class Son extends Father void display();,Father f=new Father();f.display();,Son s=new Son();s.display();,第6讲 类和对象(续),对象的创建*创建对象/实例化对象new Apple a=new Apple();(创建对象)对象的实例化通过构造方法(constructor)来实现构造方法的名字与类名相同构造方法没有返回值构造方法可以有多个,构成方法的重载(overload),第6讲 类和对象(续),对象的创建*,第6讲 类和对象(续),默认构造方法*例 class Apple int color;Apple a=new Apple();对象实例的判断*(null)例 Apple a;if(a=null)System.out.println(“Day dream”);,第6讲 类和对象(续),对象的引用*通过对象引用对象的成员变量和成员方法,class Square int a,h;Square()a=10;h=20;Square(int x,int y)a=x;h=y;Square(Square r)a=r.width();h=r.height();int width()return a;int height()return h;void set(int x,int y)a=x;h=y;,第6讲 类和对象(续),对象的释放*周期性地释放不再被引用的对象,自动完成自动垃圾回收,第7讲 类和对象(续),继承*父类与子类的关系(extends)子类可调用父类的方法和变量,子类可增加父类中没有的方法和变量子类可重新定义父类的静态/实例变量子类可重新定义父类的静态/实例方法,第7讲 类和对象(续),抽象类*一个未完成的类,抽象类不能被实例化子类继承抽象类时,必须重写抽象方法,否则仍为抽象类仅仅抽象类可以包含抽象方法(abstract methods)抽象方法:仅仅申明了方法,但未实现有访问修饰词返回值类型方法名参数列表无方法体,第7讲 类和对象(续),抽象类*,abstract class Point int x=1,y=1;void move(int dx,int dy)x+=dx;y+=dy;alert();abstract void alert();,abstract class ColoredPoint extends Point int color;,class SimplePoint extends Point void alert(),Point p=new SimplePoint();,第7讲 类和对象(续),接口*接口是对abstract类的进一步扩展接口中的方法都是未实现的(类似于抽象方法),目的是在实现接口的类之间建立一种协议接口中的变量都是常量public interface Months int JANUARY=1,FEBRUARY=2,MARCH=3,APRIL=4,MAY=5,JUNE=6,JULY=7,AUGUST=8,SEPTEMBER=9,OCTOBER=10,NOVEMBER=11,DECEMBER=12;,第7讲 类和对象(续),interface Figure double half=0.5,pi=3.14159;void parameter();void area();,class Triangle implements Figure double b,h;Triangle(double u,double v)b=u;h=v;public void parameter()System.out.println(b+“+h);public void area()System.out.println(half*h*b);,class Circle implements Figure double x,y,r;Circle(double u,double v,double m)x=u;y=v;r=m;public void parameter()System.out.println(x+“+y+“+r);public void area()System.out.println(pi*r*r);,Triangle t=new Triangle(2,3);Circle c=new Circle(4,5,6);Figure f=t,c;for(int i=0;i f.length;i+)fi.parameter();fi.area();,第7讲 类和对象(续),包*使Java类更容易发现和使用防止命名冲突进行访问控制 层次结构,package org.jalpha;public class HelloWorld.,第8讲 异常,Java语言利用异常来使程序获得处理错误的能力(error-handling)异常处理机制异常处理器(exception handler)trycatchfinally异常的抛出(throw),一个try语句必须带有至少一个catch语句块或一个finally语句块,第8讲 异常,import java.io.IOException;class Test static char getChar()throws IOException char c=(char)System.in.read();return c;public static void main(String args)try char c=getChar();System.out.println(c);catch(IOException e)System.out.println(e);,第9讲 Java 2 API规范,java.lang.System类数组复制*,class Test public static void main(String args)int a=2,4,6,8;int b;int c=1,3,5,7,9;b=a;System.arraycopy(a,1,c,0,3);System.out.print(“数组a:”);for(int i=0;i a.length;i+)System.out.print(ai+“”);System.out.println();System.out.print(“数组b:”);for(int i=0;i b.length;i+)System.out.print(bi+“”);System.out.println();,System.out.print(“数组c:”);for(int i=0;i c.length;i+)System.out.print(ci+“”);System.out.println();,第9讲 Java 2 API规范,java.lang.System类程序退出*,public static void main(String args);if()System.exit(0);,第9讲 Java 2 API规范,基本类型和字符串(String)之间的转换,int i=123;String s1=Integer.toString(i);String s2=Integer.toString(i,10);String s3=Integer.toString(i,2);String s4=Integer.toString(i,8);String s5=Integer.toString(i,16);String s6=Integer.toBinaryString(i);String s7=Integer.toHexString(i);String s8=Integer.toOctalString(i);,12312311110111737b11110117b173,第9讲 Java 2 API规范,java.lang.String类字符串判断字符串相等*,String s1=java语言;String s2=JavA语言;System.out.println(s1.equals(s2);System.out.println(s1.equalsIgnoreCase(s2);System.out.println(pareTo(s2);System.out.println(pareToIgnoreCase(s2);,第9讲 Java 2 API规范,java.lang.String类字符串其他*,String s1=java语言;String s2=JavA语言;System.out.println(s1.length();System.out.println(s2.length();System.out.println(s1.substring(0,4);System.out.println(s1.substring(4);System.out.println(s2.substring(0,4);System.out.println(s2.substring(4);System.out.println(s1.charAt(0);,第9讲 Java 2 API规范,java.lang.String类字符串其他*,String s=“java语言”;System.out.println(s.indexOf(a);System.out.println(s.indexOf(a,2);System.out.println(s.indexOf(“a”);System.out.println(s.indexOf(“语言”);System.out.println(s.lastIndexOf(a);System.out.println(s.lastIndexOf(v,1);System.out.println(s.lastIndexOf(“语言”);System.out.println(s.lastIndexOf(“v”,2);,第10讲 线程,线程(Thread)*线程是进程中一个“单一的连续控制流程”/执行路径一个进程可拥有多个并行的线程一个进程中的所有线程共享相同的内存单元/内存地址空间可以访问相同的变量和对象通信、数据交换、同步操作用途从提高程序执行效率的考虑最大限度地利用CPU效率应用在多处理器系统(SMP-Symmetric MultiProcessing)执行异步或后台处理等Client/Server设计中的服务器端,如每个用户请求建立一个线程,实现多个请求同时并发图形用户界面(GUI)的设计中提高事件响应的灵敏度,第10讲 线程,线程创建的两种方式*“Subclassing Thread and Overriding run”继承java.lang.Thread类,重写run()方法“Implementing the Runnable Interface”实现java.lang.Runnable接口线程的同步*synchronizedwait()/notifyAll()/notify(),第11讲 Java I/O操作,I/O来源*控制台(console,如DOS窗口)打印/读入文件(file)读/写网络接口(TCP/UDP端口)读/写以流(stream)的方式对数据进行操作*两种流的定义(读取信息的基本数据单位)*字节流(byte stream):一个字节(8-bit)一个字节读/写字符流(character stream):一个字符一个字符读/写(具有特定字符编码的数据),第11讲 Java I/O操作,读/写流的一般流程*读(Reading)open a stream/打开读出流while more information/判断 read information/读close the stream/关闭流写(Writing)open a stream/打开写入流while more information/判断 write information/写close the stream/关闭流,第11讲 Java I/O操作,文件读/写操作*FileInputStream/FileOutputStream(字节流)FileReader/FileWriter(字符流),import java.io.*;public class CopyBytes public static void main(String args)throws IOException FileInputStream in=new FileInputStream(“original.txt”);FileOutputStream out=new FileOutputStream(“result.txt”);int c;while(c=in.read()!=-1)out.write(c);in.close();out.close();,第11讲 Java I/O操作,java.io.File类*文件和目录的路径名目录管理,import java.io.File;public class DirList public static void main(String args)File path=new File(.);String list=path.list();for(int i=0;i list.length;i+)System.out.println(listi);,第11讲 Java I/O操作,java.io.File类*文件属性操作,import java.io.*;import java.util.*;public class AttrDemo2 public static void main(String args)throws IOException File testfile=new File(test

    注意事项

    本文(java大学教程pptrev.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开