Java语言培训教案课件

上传人:我*** 文档编号:144933738 上传时间:2020-09-14 格式:PPT 页数:306 大小:2.20MB
返回 下载 相关 举报
Java语言培训教案课件_第1页
第1页 / 共306页
Java语言培训教案课件_第2页
第2页 / 共306页
Java语言培训教案课件_第3页
第3页 / 共306页
Java语言培训教案课件_第4页
第4页 / 共306页
Java语言培训教案课件_第5页
第5页 / 共306页
点击查看更多>>
资源描述

《Java语言培训教案课件》由会员分享,可在线阅读,更多相关《Java语言培训教案课件(306页珍藏版)》请在金锄头文库上搜索。

1、第一章 Java语言概述,华中科技大学IBM技术中心 2008,主要内容提要,Java程序的开发环境,Java程序相关问题,Java语言的主要特性,Java语言的发展历史,Java程序的开发过程,HUST ,HUST public int x, y; /constructor public Spot() x = -1; y = -1; size = 1; /methods for access to the size instance variable public void setSize(int newSize) if (newSize = 0) size = newSize; publi

2、c int getSize() return size; ,HUST . spot = new Spot();,HUST g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1);,HUST spot.setSize(RADIUS); spot.x = event.getX(); spot.y = event.getY(); repaint(); public void mouseClicked(MouseEvent event) public void mouseReleased(MouseEvent event) public void mou

3、seEntered(MouseEvent event) public void mouseExited(MouseEvent event) ,HUST int i; double pi = 3.1415926; String name;,HUST boolean b = 1;,原始类型,HUST ,HUST if ( i 0) int i = 20; System.out.println(“The value of i = ” + i); System.out.println(“The value of i = ” + i);,HUST ,final int blankfinal; . . .

4、 blankfinal = 0;,HUST Rectangle rect_one = new Rectangle(origin_one, 100, 200); Rectangle rect_two = new Rectangle(50, 100); / 显示rect_one的宽、高以及面积 System.out.println(Width of rect_one: + rect_one.width); System.out.println(Height of rect_one: + rect_one.height); System.out.println(Area of rect_one: +

5、 rect_one.area(); rect_two.origin = origin_one; /设置rect_two的位置 / 显示rect_two的位置 System.out.println(X Position of rect_two: + rect_two.origin.x); System.out.println(Y Position of rect_two: + rect_two.origin.y); / 移动rect_two并且显示它的新位置 rect_two.move(40, 72); System.out.println(X Position of rect_two: + r

6、ect_two.origin.x); System.out.println(Y Position of rect_two: + rect_two.origin.y); ,HUST public int y = 0; public Point(int x, int y) this.x = x; this.y = y; ,Point origin_one = new Point(23, 94);,HUST Point origin_two = new Point(23, 94);,Point origin_one = new Point(23, 94); Point origin_two =ori

7、gin_two;,HUST public int height = 0; public Point origin; public Rectangle() origin = new Point(0, 0); public Rectangle(Point p) origin = p; public Rectangle(int w, int h) this(new Point(0, 0), w, h); public Rectangle(Point p, int w, int h) origin = p; width = w; height = h; . ,一个类可以包含多个构造器,这种情况成为构造

8、器的重载 同一个类中的多个构造器通过参数的数目及类型的不同来区分,HUST static int share_data; class Demo ABCD a,b,c,d; /实例化 ,HUST System.out.println(Height of rect_one: + rect_one.height); int height=new Rectangle().height;,HUST 或者 objectReference.methodName();,System.out.println(Area of rect_one: + rect_one.area(); rect_two.move(4

9、0, 72); int areaOfRectangle = new Rectangle(100, 50).area();,HUST / 超出对象作用域 ,引用变量引用了其它对象或引用了空对象 StringBuffer s = new StringBuffer(“test1”); s = new StringBuffer(“test2”); / 引用了新的对象 s = null; / 引用为空,HUST myRect.width = 40; myRect.height = 50; System.out.println(myRects area is + myRect.area(); ,HUST

10、Rectangle rectangle = new Rectangle(point, 20, 20); point = null;,HUST Character a2 = new Character(a); Character b = new Character(b); int difference = pareTo(b); if (difference = 0) System.out.println(a is equal to b.); else if (difference 0) System.out.println(a is greater than b.); System.out.pr

11、intln(a is + (a.equals(a2) ? equal : not equal)+ to a2.); System.out.println(The character + a.toString() + is + (Character.isUpperCase(a.charValue() ? upper : lower)+ case.); ,程序的输出: a is less than b. a is equal to a2. The character a is lowercase.,HUST Character b = new Character(a);,下列boolean表达式的

12、值是true还是false? (1)pareTo(b)=0 (2)a.equals(b) (3)a=b,HUST 此外,也可根据String类的构造函数创建String对象: String name = new String(“Petter”); 对于程序任何位置出现的双引号标记的字符串,系统都会自动创建一个String对象。 可通过String对象的方法对字符串进行操作,HUST s=s+“defg; System.out.println(s); ,程序运行结果是abc还是abcdefg?,HUST str = str + “ 当修改操作频繁,或字符串的值很大时,会额外分配大量内存 因此,J

13、ava语言引入了一个StringBuffer类,用来表示内容可以扩充和修改字符串对象,HUST StringBuffer dest = new StringBuffer(s);,HUST int len = palindrome.length();,HUST char aChar = anotherPalindrome.charAt(9);,HUST String roar = anotherPalindrome.substring(11, 15);,HUST private char pathSeparator, extensionSeparator; public Filename(Str

14、ing str, char sep, char ext) fullPath = str; pathSeparator = sep; extensionSeparator = ext; public String extension() int dot = fullPath.lastIndexOf(extensionSeparator); return fullPath.substring(dot + 1); public String filename() int dot = fullPath.lastIndexOf(extensionSeparator); int sep = fullPat

15、h.lastIndexOf(pathSeparator); return fullPath.substring(sep + 1, dot); public String path() int sep = fullPath.lastIndexOf(pathSeparator); return fullPath.substring(0, sep); ,HUST System.out.println(Extension = + myHomePage.extension(); System.out.println(Filename = + myHomePage.filename(); System.out.println(Path = + myHomePage.path(); ,程序输出: Extension = html Filename = index Path = /home/mem,HUST Float floatTwo = Float.valueOf(1.0); Double doubleOne = new Double(1.0); int difference = floatOpareTo(floatTwo); if (difference = 0) System.out.println(floatOne is equal to flo

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > PPT素材/模板

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号