java程序设计第四讲教案
- 格式:doc
- 大小:69.50 KB
- 文档页数:17
JAVA程序设计_教案教案:JAVA程序设计课程目标:1.了解JAVA的基本结构和语法;2.掌握JAVA的常用数据类型和运算符;3.能够编写简单的JAVA程序;4.培养学生的编程思维和解决问题的能力。
教学内容:第一课:JAVA基础知识介绍(20分钟)1.什么是JAVA?2.JAVA的特点及应用领域。
3.JAVA开发工具的选择和安装。
4.第一个JAVA程序。
第二课:JAVA基本语法(30分钟)1.变量的声明和赋值。
2.数据类型和运算符。
3. 流程控制结构:if-else 语句、switch-case 语句、for 循环、while 循环。
4.函数的定义和调用。
第三课:面向对象编程(40分钟)1.类和对象的概念。
2.类的属性和方法。
3.构造方法和析构方法。
4.封装、继承和多态。
5.类的继承和实现接口。
第四课:字符串和数组(30分钟)1.字符串的基本操作:连接、比较、截取、替换。
2.数组的定义和初始化。
3.数组的访问和遍历。
4.常见的数组操作:排序、查找、插入、删除。
第五课:异常处理(20分钟)1.异常处理的概念和作用。
2. try-catch-finally 语句的使用。
3.自定义异常类。
第六课:文件操作(30分钟)1.文件的读取和写入。
2.文件的创建、删除和重命名。
3.文件的复制和移动。
教学方法:1.理论教学结合实际案例,让学生能够将所学知识应用到实际问题中。
2.引导学生主动思考和解决问题,培养学生的自学能力和解决问题的能力。
3.引入互动环节,让学生参与到教学中来,激发学生的兴趣和积极性。
教学工具:1.讲义和教材。
2.电脑、投影仪和黑板。
3. JAVA 开发工具(如 Eclipse 或 IntelliJ IDEA)。
评估方式:1.课后作业:每堂课布置合适的编程作业,考察学生对所学知识的掌握和应用能力。
2.课堂练习:在课堂上通过问答、小组讨论等方式进行互动,检验学生对知识的理解和运用能力。
3.期末考试:根据教学内容和目标,出一份综合性的考试,测试学生的综合能力。
第4章类与对象的4.4节-4.6节,本次课是第4章的第2次课。
基本内容:❖类与程序的基本结构❖参数传值❖对象的组合重点类与程序的基本结构、参数传值。
难点参数传值、尤其是引用类型参数的传值。
§4.4 类与程序的基本结构一个Java应用程序(也称为一个工程)是由若干个类所构成,这些类可以在一个源文件中,也可以分布在若干个源文件中,如图4.12所示。
例子5 中一共有三个Java源文件(Example4_5.java Rect.java Lader.java ,需要打开记事本三次,分别编辑、保存这三个Java源文件),其中Example4_5.java是含有主类的Java 源文件。
Java应用程序从主类的main方法开始执行。
在编写一个Java应用程序时,可以编写若干个Java源文件,每个源文件编译后产生一个类的字节码文件。
Rect.javapublic class Rect {double width; //矩形的宽double height; //矩形的高double getArea() {double area = width*height;return area;}}Lader.javapublic class Lader {double above; //梯形的上底double bottom; //梯形的下底double height; //梯形的高double getArea() {return (above+bottom)*height/2;}}Example4_5.javapublic class Example4_5 {public static void main(String args[]) {Rect ractangle = new Rect();ractangle.width = 109.87;ractangle.height = 25.18;double area=ractangle.getArea();System.out.println("矩形的面积:"+area);Lader lader = new Lader();lader.above = 10.798;lader.bottom = 156.65;lader.height = 18.12;area = lader.getArea();System.out.println("梯形的面积:"+area);}}§4.5 参数传值方法中最重要的部分之一就是方法的参数,参数属于局部变量,当对象调用方法时,参数被分配内存空间,并要求调用者向参数传递值,即方法被调用时,参数变量必须有具体的值。
教案首页周次 日期 课时序课题字符串处理 字符串是 Java 应用程序中最常用的数据类型,要求学生 能够理解字符串的基本概念和使用情况 String、StringBuffer 类;命令行参数 String、StringBuffer 类;命令行参数 第六章 字符串处理(3*45‘) 第一节 类 String 字符串(40‘) 第二节 类 StringBuffer 字符串(40‘) 第三节 main 方法的命令行参数(25‘) 第四节 字符串应用举例(30‘)教学目的 要 重 难 求 点 点教学过程 设 及 时间分配 计教学场所 或教学方法 作 业使用 教具课 后 记授课教师1第六章 字符串处理从本章开始介绍的是 Java 的应用,与前面几章有所不同,以后将主要讲授程 序范例,让学生增强应用能力,而此前主要是讲授理论知识为主。
字符串是字符的序列,它是组织字符的基本数据结构。
对于大多数程序员来说 都是很重要的。
Java 将字符串当作对象来处理。
Java 语言中的包 ng 封装了 final 类 String 和 StringBuffer 类。
6.1 6.1.1类 String 字符串 类 String 字符串的定义String 类是字符串常量类,String 对象建立后不能修改。
以前使用的每个字符 串常量(用双引号括起来的一串字符串)实际上都是 String 对象。
构造方法有: String() Initializes a newly created String object so that it represents an empty character sequence.String(byte[] bytes) Construct a new String by converting the specified array of bytes using the platform's default character encoding.String(byte[] ascii, int hibyte) Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a character-encoding name or that use the platform's default encoding.String(byte[] bytes, int offset, int length) Construct a new String by converting the specified subarray of bytes2using the platform's default character encoding.String(byte[] ascii, int hibyte, int offset, int count) Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a character-encoding name or that use the platform's default encoding.String(byte[] bytes, int offset, int length, String enc) Construct a new String by converting the specified subarray of bytes using the specified character encoding.String(byte[] bytes, String enc) Construct a new String by converting the specified array of bytes using the specified character encoding.String(char[] value) Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.String(char[] value, int offset, int count) Allocates a new String that contains characters from a subarray of the character array argument.String(String value) Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.String(StringBuffer buffer) Allocates a new string that contains the sequence of characters currently3contained in the string buffer argument.利用这些构造函数来定义 String 对象。
例题。
讲授书上 6.1 例题。
6.1.2 类 String 的常用方法学习好程序设计,主要是靠自己自学,老师教基础,给学生打根基。
因为新的 语言,新的技术每天都在出现,自己不学,永远会落后。
具体的 Java 语言的应用,学生应该自己多看看帮助,虽然是英文,但也必须 多看,这样才能提高。
A:类 String 字符串的比较 : 有如下方法,对每个方法做介绍 public boolean equals(Object anObject) 比较两个字符串是否相同, 大小写有区别。
如果相同, 则返回 true, 否则返回 false。
这里说明一下“ ” 方法的区别。
这里说明一下“=”号和 equal 方法的区别。
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Overrides: equals in class Object Parameters: anObject - the object to compare this String against.Returns: true if the String are equal; false otherwise.public boolean equalsIgnoreCase(String anotherString) 比较两个字符串是否相同,但是忽略大小写。
如果相同,返回 true,如果不相同,4返回 false。
Compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case.Parameters: anotherString - the String to compare this String against.Returns: true if the argument is not null and the Strings are equal, ignoring case; false otherwise. public int compareTo(String anotherString) 比较两个字符串大小, 通过返回的整数值指明当前字符串与参数字符串的大小关 系。
若调用的串对象比参数串对象大,返回正整数;反之,返回负整数。
相等返 回 0。
返回情况:若比较的两个字符串有不同的字符,则总左边数起的第一个不同字符 的大小即为返回值; 若比较的两个字符串的各个位置的字符都相同, 而长度不同, 则返回值为长度差。
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true.This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string5whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value:this.charAt(k)-anotherString.charAt(k)If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:this.length()-anotherString.length()Parameters: anotherString - the String to be compared.Returns: the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument.Throws: NullPointerException - if anotherString is null. public boolean startsWith(String prefix) 比较当前字符串是否是以 prefix 开头。