山东大学java高级程序设计语言15年重点考点_第1页
山东大学java高级程序设计语言15年重点考点_第2页
山东大学java高级程序设计语言15年重点考点_第3页
山东大学java高级程序设计语言15年重点考点_第4页
山东大学java高级程序设计语言15年重点考点_第5页
已阅读5页,还剩100页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、高级(goj)程序设计语言复习课共一百零五页内容(nirng)试题类型每章重点(zhngdin)、考点知识点串讲共一百零五页试题(sht)类型选择题基本概念40分左右读程序写结果:30分左右编程题:定义使用(shyng)类、数组、链表、递归、循环等 30分左右共一百零五页Chapter 1 Introduction教学内容:计算机基础知识硬件系统、软件系统、网络、java编程语言概览(i ln)、程序开发过程、面向对象编程基本思想考点:基本概念共一百零五页Chapter 2 Data and Expressions教学内容:高级语言中变量的概念与应用,简单数据类型,表达式和操作符,数据类型的转

2、换,数据输入(shr)方法等目的: 对软件设计中的数据的表达方法有一个初步的认识。考点:简单数据类型及其存储方法,string的应用,表达式求值、类型转换、boolean运算的短路共一百零五页 Chapter 3: Using Classes and Objects;Chapter 4: Writing Classes教学内容:对象的创建与应用。类的定义,方法的设计方法,方法参数的数据传递,构造方法的设计。数学类,基础类,string类的方法等重点:对象的概念,引用方法,内存存储形式;类的定义;方法的定义;实参与形参的概念及传递,构造方法。熟悉String的使用;包装类的使用;了解包装类,基础

3、类库,格式化输出类,枚举类型等。难点:对象的引用方法,简单(jindn)数据类型与对象类型在进行实参与形参之间的传递时的不同考点:类定义,方法设计,参数传递,数学类。共一百零五页Chapter 5 Conditionals and Loops教学内容:三种控制流程的设计(shj)方法:顺序、分支、循环。目的: 基于前面数据类型及表达式的学习,能够编写简单的算法。重点: 布尔类型数据、运算符及表达式求值的理解与应用;不同数据类型进行比较方式的不同;分支与循环语句结合进行复杂问题的解决;考点:全部内容共一百零五页Chapter 6: Object-Oriented Design教学内容: 软件开发

4、过程的各个阶段活动,类的分析以及类之间关系(gun x)的设计方法,接口的设计,有关静态类,静态变量,静态方法的概念。方法的重载。重点:学习如何从实际问题需要出发进行类的分析与设计。实例变量的多种类型(简单类型,引用类型等),static修饰符的作用,方法重载的意义和用法。难点: 不同实例变量在内存里的存储方式,引用方式;静态类,变量,方法的特点,重载后方法的调用。考点:静态修饰符的作用,重载方法的设计。共一百零五页Chapter 8: Inheritance 教学内容: 类的继承,抽象类的概念。各种访问控制符(public private protected)的区别。父类、派生类的存储模式,

5、派生类创建过程的内存状态。多态的概念及其应用意义(yy)。类的继承层次,派生子类的多类型问题。利用接口实现多态性。重点:子类与父类在不同访问控制符标示的实例变量、方法的继承与访问关系,创建子类时,隐含创建父类的概念。多态概念的进一步强化与应用。 考点:类的继承,抽象类的概念,多态的实现。共一百零五页Chapter 7: Arrays (课件Lecture 8)教学内容: 数组的概念,数组的存储模式,数组的应用(数组元素(yun s)为简单类型、对象类型,实例变量为数组类型,方法的参数为数组元素(yun s)或数组名,返回值为数组元素(yun s)或数组名等),多维数组的概念与应用。重点: 掌握

6、数组的内涵,数组与简单变量,类之间的关系与区别。数组在作为实参或形参时的正确应用。考点:全部内容 共一百零五页Chapter 9 Searching & Sorting教学内容:从对数组的几类搜索和排序算法(sun f)入手,体会面向对象里多态的特征与用途;重点: 折半查找算法,选择排序或插入排序算法的掌握。考点:至少掌握一种搜索和排序算法 共一百零五页Chapter 10 Exception (课件Lecture 10)教学内容: 异常的概念,java里的异常处理机制。异常的几种(j zhn)处理方法与相应的语句,系统异常类层次,异常类的设计。重点: 异常处理在应用程序中的重要性,如何将过去

7、学过的算法设计重新用异常处理机制设计。可处理的异常与不可处理的异常。难点:用异常处理机制设计的方法,在进行多层次递进调用时,不同层次里进行不同的异常处理(catch或propagating)过程。考点:java的异常处理机制,几种典型的(系统)异常类 共一百零五页 Chapter 12 Recursion教学内容:递归的概念,如何用递归进行算法的设计,几个典型的递归例题(递归的应用)重点(zhngdin): 递归的基本设计规律,什么样的问题适用于递归考点: 对递归算法的理解能依据代码读懂算法,给出结果。共一百零五页 Chapter 13LinkList重点: 动态数据结构(sh j ji u)

8、的概念,链表的设计,基本操作(遍历,结点插入与删除等)考点:链表的基本操作共一百零五页标示(bio sh)符表达式赋值语句共一百零五页标示(bio sh)符共一百零五页1-17IdentifiersIdentifiers are the words a programmer uses in a programAn identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar signIdentifiers cannot begin with a digitJava is

9、case sensitive - Total, total, and TOTAL are different identifiersBy convention, programmers use different case styles for different types of identifiers, such astitle case for class names - Lincolnupper case for constants - MAXIMUM共一百零五页1-18IdentifiersSometimes we choose identifiers ourselves when

10、writing a program (such as Lincoln)Sometimes we are using another programmers code, so we use the identifiers that he or she chose (such as println)Often we use special identifiers called reserved words that already have a predefined meaning in the languageA reserved word cannot be used in any other

11、 way共一百零五页表达式、赋值语句(yj)共一百零五页2-20ExpressionsAn expression is a combination of one or more operators and operandsArithmetic expressions compute numeric results and make use of the arithmetic operators:If either or both operands used by an arithmetic operator are floating point, then the result is a fl

12、oating pointAdditionSubtractionMultiplicationDivisionRemainder+-*/%共一百零五页2-21Division and RemainderIf both operands to the division operator (/) are integers, the result is an integer (the fractional part is discarded)The remainder operator (%) returns the remainder after dividing the second operand

13、 into the first14 / 3 equals8 / 12 equals4014 % 3 equals8 % 12 equals28共一百零五页2-22Operator PrecedenceOperators can be combined into complex expressionsresult = total + count / max - offset;Operators have a well-defined precedence which determines the order in which they are evaluatedMultiplication, d

14、ivision, and remainder are evaluated prior to addition, subtraction, and string concatenationArithmetic operators with the same precedence are evaluated from left to right, but parentheses can be used to force the evaluation order共一百零五页2-23Operator PrecedenceWhat is the order of evaluation in the fo

15、llowing expressions?a + b + c + d + e1432a + b * c - d / e3241a / (b + c) - d % e2341a / (b * (c + (d - e)4123共一百零五页2-24Assignment RevisitedThe assignment operator has a lower precedence than the arithmetic operatorsFirst the expression on the right handside of the = operator is evaluatedThen the re

16、sult is stored in thevariable on the left hand sideanswer = sum / 4 + MAX * lowest;1432共一百零五页2-25Assignment RevisitedThe right and left hand sides of an assignment statement can contain the same variableFirst, one is added to theoriginal value of countThen the result is stored back into count(overwr

17、iting the original value)count = count + 1;共一百零五页2-26Increment and DecrementThe increment and decrement operators use only one operandThe increment operator (+) adds one to its operandThe decrement operator (-) subtracts one from its operandThe statementcount+;is functionally equivalent tocount = co

18、unt + 1;共一百零五页2-27Increment and DecrementThe increment and decrement operators can be applied in postfix form:count+or prefix form:+countWhen used as part of a larger expression, the two forms can have different effectsBecause of their subtleties, the increment and decrement operators should be used

19、 with care共一百零五页2-28Assignment OperatorsOften we perform an operation on a variable, and then store the result back into that variableJava provides assignment operators to simplify that processFor example, the statementnum += count;is equivalent tonum = num + count;共一百零五页2-29Assignment OperatorsTher

20、e are many assignment operators in Java, including the following:Operator+=-=*=/=%=Examplex += yx -= yx *= yx /= yx %= yEquivalent Tox = x + yx = x - yx = x * yx = x / yx = x % y共一百零五页2-30Assignment OperatorsThe right hand side of an assignment operator can be a complex expressionThe entire right-ha

21、nd expression is evaluated first, then the result is combined with the original variableThereforeresult /= (total-MIN) % num;is equivalent toresult = result / (total-MIN) % num);共一百零五页JAVA 程序(chngx)共一百零五页1-32Java TranslationJava sourcecodeMachinecodeJavabytecodeBytecodeinterpreterBytecodecompilerJav

22、acompiler共一百零五页1-33ErrorsA program can have three types of errorsThe compiler will find syntax errors and other basic problems (compile-time errors)If compile-time errors exist, an executable version of the program is not createdA problem can occur during program execution, such as trying to divide

23、by zero, which causes a program to terminate abnormally (run-time errors)A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) 共一百零五页1-34Basic Program DevelopmenterrorserrorsEdit andsave programCompile programExecute program andevaluate results共一百零五页Ex

24、ercisesE1.20 Categorize each of the following situations as a compile-time error, run-time error, or logical errora. multiplying two numbers when you meant to add them (logical error)b. dividing by zero (run-time error)c. forgetting a semicolon at the end of a programming statement. (compile-time er

25、ror)d. spelling a word wrong in the output (logical error)e. producing inaccurate results (logical error)f. typing a when you should have typed ( (compile-time error)共一百零五页控制语句(yj)、循环语句(yj)共一百零五页5-37Boolean ExpressionsA condition often uses one of Javas equality operators or relational operators, wh

26、ich all return boolean results:=equal to!=not equal togreater than=greater than or equal toNote the difference between the equality operator (=) and the assignment operator (=)共一百零五页5-38Logical OperatorsBoolean expressions can also use the following logical operators:!Logical NOT&Logical AND|Logical

27、 ORThey all take boolean operands and produce boolean resultsLogical NOT is a unary operator (it operates on one operand)Logical AND and logical OR are binary operators (each operates on two operands)共一百零五页5-39Logical OperatorsA truth table shows all possible true-false combinations of the termsSinc

28、e & and | each have two operands, there are four possible combinations of conditions a and baba & ba | btruetruetruetruetruefalsefalsetruefalsetruefalsetruefalsefalsefalsefalse共一百零五页5-40Comparing CharactersIn Unicode, the digit characters (0-9) are contiguous and in orderLikewise, the uppercase lett

29、ers (A-Z) and lowercase letters (a-z) are contiguous and in orderCharactersUnicode Values0 948 through 57A Z65 through 90a z97 through 122共一百零五页控制语句(yj)&循环语句if statementif-else statementswitch statement共一百零五页5-42The if StatementThe if statement has the following syntax:if ( condition ) statement;if

30、is a Javareserved wordThe condition must be aboolean expression. It mustevaluate to either true or false.If the condition is true, the statement is executed.If it is false, the statement is skipped.共一百零五页5-43Logic of an if statementconditionevaluatedstatementtruefalse共一百零五页5-44Boolean ExpressionsA c

31、ondition often uses one of Javas equality operators or relational operators, which all return boolean results:=equal to!=not equal togreater than=greater than or equal toNote the difference between the equality operator (=) and the assignment operator (=)共一百零五页5-45The if-else StatementAn else clause

32、 can be added to an if statement to make an if-else statementif ( condition ) statement1;else statement2;If the condition is true, statement1 is executed; if the condition is false, statement2 is executedOne or the other will be executed, but not bothSee Wages.java 共一百零五页5-46Logic of an if-else stat

33、ementconditionevaluatedstatement1truefalsestatement2共一百零五页5-47The switch StatementThe general syntax of a switch statement is:switch ( expression ) case value1 : statement-list1 case value2 : statement-list2 case value3 : statement-list3 case .switchandcasearereservedwordsIf expressionmatches value2

34、,control jumpsto here共一百零五页2022/7/26The college of Computer Science & Technology48switch With No break Statementsswitch ( N ) case 1: x = 10;case 2: x = 20;case 3: x = 30;x = 10;falsetrueN = 1 ?x = 20;x = 30;N = 2 ?N = 3 ?falsefalsetruetrue共一百零五页2022/7/26The college of Computer Science & Technology4

35、9switch With break Statementsswitch ( N ) case 1: x = 10;break;case 2: x = 20;break;case 3: x = 30;break;x = 10;falsetrueN = 1 ?x = 20;x = 30;N = 2 ?N = 3 ?falsefalsetruetruebreak;break;break;共一百零五页Break:使用break 退出循环 可以使用break 语句直接强行退出循环,忽略循环体中任何其他语句和循环条件测试。在循环中遇到break语句时,循环被终止,程序控制在循环后面语句重新(chngxn)

36、开始。在一系列嵌套循环中使用break 语句时,它将仅仅终止最里面循环。Continue:停止执行当前的反复,然后退回循环起始,开始新的反复。continue 用于跳过循环体中的一部分语句,也就是不执行这部分语句Return用来明确地从一个方法返回。也就是,return 语句使程序控制返回到调用它的方法。共一百零五页public class switchtest public static void main(String args) int id; id=2; switch (id) case 1: System.out.print(id=1 ); break; case 2: System

37、.out.print(id=2 ); case 3: System.out.print(id=3 ); case 4: System.out.print(id=4 ); break; default: System.out.print(default ); 共一百零五页int i=11, j=5;switch(i/j) case 3: j+=i; case 2: j+=2; case 4: j+=4; break;case 1: j +=1; System.out.pirntln(j);11共一百零五页循环(xnhun)语句ForWhileDo 共一百零五页5-54The while Stat

38、ementA while statement has the following syntax:while ( condition ) statement;If the condition is true, the statement is executedThen the condition is evaluated again, and if it is still true, the statement is executed againThe statement is executed repeatedly until the condition becomes false共一百零五页

39、5-55Logic of a while Loopstatementtruefalseconditionevaluated共一百零五页5-56The do StatementA do statement has the following syntax:do statement;while ( condition )The statement is executed once initially, and then the condition is evaluatedThe statement is executed repeatedly until the condition becomes

40、 false共一百零五页5-57Logic of a do Looptrueconditionevaluatedstatementfalse共一百零五页5-58Comparing while and dostatementtruefalseconditionevaluatedThe while LooptrueconditionevaluatedstatementfalseThe do Loop共一百零五页5-59The for StatementA for statement has the following syntax:for ( initialization ; condition

41、; increment ) statement;The initializationis executed oncebefore the loop beginsThe statement isexecuted until thecondition becomes falseThe increment portion is executed at the end of each iteration共一百零五页5-60Logic of a for loopstatementtrueconditionevaluatedfalseincrementinitialization共一百零五页面向对象编程共

42、一百零五页类 、对象(duxing)共一百零五页构造函数构造方法要与类名相同无返回(fnhu)类型,也不需要void。在类初始化的时候调用。可重载缺省构造方法共一百零五页继承(jchng)共一百零五页关于Java中的接口和继承,下面(xi mian)说法正确的是:在Java中允许继承多个类,在extends关键字之后分别列出。 在Java中一个类只能实现一个接口。 在Java中一个类不能同时继承一个类和实现一个接口。如果接口A继承自另外一个接口B,那么用extends关键字标明,如“B extends A”。D共一百零五页下列关于Object类的说法,正确的是: Exception类不是从Ob

43、ject类派生出来的。 为了适应所有的情况,Object类中没有(mi yu)定义任何方法。 如果一个类是从Object类派生出来的,那么必须重写toString()和equals()方法。一个类如果定义为abstract的,依然继承自Object类。D共一百零五页重载(zhn zi)共一百零五页选出下列与方法(fngf)public void add(int a)为合理的重载方法(fngf)。 A.public int add(int a) B.public void add(long a) C.public void add(int a,int b) D.public void add(f

44、loat a)B共一百零五页重写(覆盖(fgi))共一百零五页多态父类的对象引用变量(binling)可以指向其所有子类的对象用接口名字定义的对象引用变量,可以指向所有实现这个接口的对象。共一百零五页修饰符可见(kjin)性(public, protected, private)static final abstract共一百零五页交通工具飞机火车汽车轮船(lnchun)共一百零五页定义(dngy)抽象类使用abstract关键字定义抽象类,例如:public abstract class A .如果(rgu)某个类是抽象类,则这个类不能有具体的对象。共一百零五页抽象(chuxing)方法如果

45、一个方法只给出方法的定义部分(b fen),而没有方法的具体实现,这个方法就是抽象方法。抽象方法的含义:某个对象具有这样的方法,但是方法如何实现不清楚。例:各种交通工具都可以把乘客从一个地方带到另外一个地方,所以交通工具应该具有一个方法移动,但是具体如何移动,不清楚,所以如果要在交通工具这个类中定义这个方法,只能是抽象的。意味着,交通工具应该有一个方法(移动),但是具体如何实现,需要看具体的子类。共一百零五页抽象方法(fngf)定义抽象方法使用关键字abstract定义public abstract void move();在类中,如果一个方法只给出声明,没有具体(jt)实现,应该使用abst

46、ract定义为抽象方法。共一百零五页抽象(chuxing)方法与抽象(chuxing)类如果一个类中出现了抽象方法,则这个类必须定义为抽象类。(有抽象方法的类一定是抽象类。)public abstract class Vehicles . public abstract void move();抽象类可以(ky)没有抽象方法。抽象类一定不能有实例。Vehicles v=new Vehicles(); 共一百零五页-static (静态(jngti)的)static 专门用来修饰内部类、属性、方法(fngf)。静态变量(类变量):这个变量独立于类的任何一个实例之外,可以由所有的类实例共享。创建类

47、时,为静态变量分配存储空间。静态方法(类方法):方法独立于类的任何一个实例之外;可以通过类名来引用。不必实例化类的对象。共一百零五页- final -final 可以修饰类、方法、变量。当它修饰类时,表示这个类不可以有子类。典型的例子就是 String。为什么不可以有子类呢?因为子类可以覆写父类的行为,一个类加上 final 就说明它的行为是定死了的,不允许改变。当 final 修饰方法时,也是同样的道理,不允许子类覆写这个方法当 final 修饰变量时,表示它们必须(bx)且仅能赋值一次。一旦将对象赋给某个 final 变量,那么这个成员或变量就不能再指向别的对象。共一百零五页综上所述,我们

48、需要注意几点:1、如果一个类已经(y jing)是 final,再给里面的方法加上 final 是没有意义的。2、抽象意味着必须要有继承,所以 abstract 和 final 任何时候都不可以同时使用。共一百零五页下面说法正确的是final 可修饰类、属性、方法(fngf)。 abstract可修饰类、属性、方法。 定义抽象方法需有方法的返回类型、名称、参数列表和方法体。 用final修饰的变量,在程序中可对这个变量的值进行更改。A共一百零五页09试题(sht)下列关于abstract关键字的说法,正确的是:A. 如果将类中的一个方法声明为abstract,那么这个类本身(bnshn)必须声

49、明为abstract。B. abstract类中只能有abstract方法,所有方法定义必须是abstract的。C. abstract类中不能包含final修饰的方法。absract方法在其子类中必须被实现。A共一百零五页6-82Static Class MembersRecall that a static method is one that can be invoked through its class nameFor example, the methods of the Math class are static:result = Math.sqrt(25)Variables c

50、an be static as wellDetermining if a method or variable should be static is an important design decision共一百零五页6-83The static ModifierWe declare static methods and variables using the static modifierIt associates the method or variable with the class rather than with an object of that classStatic met

51、hods are sometimes called class methods and static variables are sometimes called class variablesLets carefully consider the implications of each共一百零五页6-84Static VariablesNormally, each object has its own data space, but if a variable is declared as static, only one copy of the variable exists priva

52、te static float price;Memory space for a static variable is created when the class is first referencedAll objects instantiated from the class share its static variablesChanging the value of a static variable in one object changes it for all others共一百零五页6-85Static Methodsclass Helper public static in

53、t cube (int num) return num * num * num; Because it is declared as static, the methodcan be invoked asvalue = Helper.cube(5);共一百零五页6-86Static Class MembersThe order of the modifiers can be interchanged, but by convention visibility modifiers come first Recall that the main method is static it is inv

54、oked by the Java interpreter without creating an objectStatic methods cannot reference instance variables because instance variables dont exist until an object existsHowever, a static method can reference static variables or local variables共一百零五页6-87Static Class MembersStatic methods and static vari

55、ables often work togetherThe following example keeps track of how many Slogan objects have been created using a static variable, and makes that information available using a static methodSee SloganCounter.java See Slogan.java 共一百零五页StaticFinalabstract共一百零五页8-89Restricting InheritanceThe final modifi

56、er can be used to curtail inheritanceIf the final modifier is applied to a method, then that method cannot be overridden in any descendent classesIf the final modifier is applied to an entire class, then that class cannot be used to derive any children at allThus, an abstract class cannot be declare

57、d as finalThese are key design decisions, establishing that a method or class should be used as is共一百零五页StaticFinalAbstract 共一百零五页8-91Abstract ClassesAn abstract class is a placeholder in a class hierarchy that represents a generic conceptAn abstract class cannot be instantiatedWe use the modifier a

58、bstract on the class header to declare a class as abstract:public abstract class Product / contents共一百零五页8-92Abstract ClassesAn abstract class often contains abstract methods with no definitions (like an interface)Unlike an interface, the abstract modifier must be applied to each abstract methodAlso

59、, an abstract class typically contains non-abstract methods with full definitionsA class declared as abstract does not have to contain abstract methods - simply declaring it as abstract makes it so共一百零五页8-93Abstract ClassesThe child of an abstract class must override the abstract methods of the parent, or it too will be considered abstractAn abstract method cannot be defined as final or staticThe use of abstract classes is an important element of software design it allows us to establish

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论