点击上方“蓝色字”可订阅哦!
在美国大学中学习,计算机知识是必不可少的,在以后的就业中,计算机应用也非常广,因此在选择AP 科目时,很多中国留学生对计算机科目情有独钟。今天我们来梳理一下计算机A的考点,加油备考吧!
首先来看一下计算机学习和复习的用书建议。
辅导书类:
Barron's AP Computer Science A ★★★★★
巴郎的教材完全覆盖AP考试考点,课后题目较多,难度、题型与考试相近,但知识点讲解不够深入,适合作为复习书和刷题使用。
Princeton AP Computer Science A ★★★★
题目难度偏低,适合初学时使用。和巴郎教材二选一即可。
Course Description ★★★★
不管准备任何AP科目考试说明都是最好的学习资料,适合前期明确考试范围和后期查漏补缺时使用。
5 Steps to a 5 ★★★★
例题部分比 Barron 要少,难度相当。
Think Java How to Think Like a Computer Scientist ★★★
由于AP计算机考试中涉及的Java只是java的子集,所以本书只适合作为参考书使用。
下面是考点梳理,做好笔记哦!
1.Introductory Java Language Features
Package And Classes 类和包
public class FirstProg // file name is FirstProg.java
{
public static type1 method1 (parameter list)
{
<code for method1>
}
public static type2 method2 (parameter list)
{
<code for method 2>
}
......
public static void main (String[] args)
{
<your code>
}
}
All java methods must be contained in a class; all program statement must be placed in a method
The class that contains the main method does not contain many additional methods.
reserved words (Keywords): class, public, static, void, main.
public: the class or method is usable outside of the class
static: methods that will not access any objects of a class. The main method must always be static.
Types And Identifiers 标识符和类型
Identifiers 标识符
Identifier: name for a variable, parameter, constant, user-defined method, user-defined class
cannot begin with a digit
Lowercase: for variables and methods
Uppercase: separate into multiple words e.g getName, findSurfaceArea
a class name starts with a capitol letter
Built-in Types 内置类型
int - 整数
boolean - true or false
double - 小数
Storage of Numbers 数值储存
Integers 整数
binary
Integer.MAX_VALUE == 2^31-1
Integer.MIN_VALUE == - 2^31
Floating-Point Numbers 浮点数
NaN"not a number" - undefined number
float & double
sign * mantissa * 2^exponent
round-off error - when floating-point numbers are converted into binary, most cannot be represented exactly
e.g 0.1*26 ≠ 0.1+0.1......(26 terms)
Hexadecimal Numbers 十六进制数
conversion between hex and binary
5 hex = 0101 bin F hex = 1111 bin
5F hex = 01011111 bin
Final Variable Final变量
user-defined constant
keyword final
e.g. final double TAX_RATE = 0.08;
final variable can be declared without initializing it immediately, but can only be given just once
array bound
final int MAXSTUDENTS = 25;
int [] classList = new Int[MAXSTUDENTS];
Operators 运算符
Arithmetic Operators 算数运算符
+ addition - subtraction * multiplication /devision %mod(remainder)
Relational Operators 关系运算符
== equal to != not equal to > greater than < less than >= greater or equal to <= less than or equal to
Relational Operators can only be used in comparison of primitive types.
User defined types : equals, compareTo methods
floating-point should not be compared directly using relational operators.
Logical Operators 逻辑运算符
! NOT && AND || OR
Short-circuit evaluation
evaluated from left to right
evaluation automatically stops as soon as the value of the entire expression is known
Assignment Operators 赋值运算符
Compound assignment operators :
= += -= *= /= %=
Increment and Decrement Operator 递增递减运算符
++ --
Operator Precedence 运算符的优先级
!, ++ , -- right to left
* , / , % left to right
+ , - left to right
<, >, <=, >= left to right
== , != left to right
&&
||
=, +=, -+, *=, /=, %= right to left
Input/Output 输入输出
Escape sequences 转义字符
newline
" double quot
backslash
Control Structures 控制结构
Decision-Making Control Structures 条件结构
if...
if...else...
nested if
extended if (if...elseif...)
Iteration 循环结构
for (initialization; termination condition; update statement)
The termination condition is tested at the top of the loop
the update statement is performed at the bottom
loop variable should not have its value changed inside the loop body
the scope of the loop variable can be restricted to the loop body by combining the loop variable declaration with the initialization.
for loop
for (SomeType element : collection)
cannot be used to replace or remove elements
hides the index variable that is used with array
for-each loop
while (boolean test)
while loop
2.Classes and Objects
Public, Private, Static 公开,私有,静态
public method
accessible to all client program
private method
can be accessed only by methods of that class
information hiding
all instance variables are private
Static variable (class variable)
keep track on statics for objects of the class
accumulate a total
provide a new identity number for each new object of the class
contains a value that is shared by all instances of the class
memory allocation happens once
usage
Methods 方法
Headers
Constructors
default constructor - no arguments
creates an object of the class
name: always the same as the class
has no return type
several constructors provides different ways of initializing an object
public BankAccount ()
{
myPassword = " ";
myBalance = 0.0;
}
BankAccount b = new BankAccount ();
the constructor with parameters
public BankAccount (String password, double balance)
{
myPassword = password;
myBalance = balance;
}
BankAccount c = new BankAccount (KevinC , 800.00);
Object b and c are object variables that store the addresses of their respective BankAccount objects.
Accessors 访问器
accesses a class object without altering the object.
returns some information about the object
getSomething()
Mutator 存取器
changes the state of an object by modifying at least one of its instance variables.
setSomething()
Static Methods 静态方法
main() method
used to test other classes
all method must be static
class name . method name
object name . method name
instance methods : all methods operate on an individual objects of a class (constructors, accessors, mutators)
static methods (class methods) : methods performs an operation for the entire class
Driver Class
Method Overloading 方法重载
two or more methods in the same class having the same name but different parameter lists
signature : name & parameter types
return type is irrelevant
Scope 范围
the region where the variable or method is visible and can be accessed
within the class all instance variable and methods can be simply accessed by name (not dot operator)
local variable : defined inside a method or statement. scope: the point where it is declared to the end of the block to its declaration occurs.
when a block is excited, the memory of a local variable is automatically recycled.
this Keyword
the instance method is always called for a particular object
implicit parameter - this
References 引用
primitive data types : double, int, boolean
reference data types : all objects
Difference : the way they are stored
primitive : each has its own memory slot
reference : contains the same address
aliasing : having two reference for the same object.
The Null Reference
a uninitialized object variable is called a null reference or null pointer
statement : object == null
object = null // set to null
NullPointerException - invoke an instance method with a null reference
if you fail to initialize a local variable in a method before you use it, you will get a compile time error
if you make the same mistake with an instance variable of a class, the code may run without error
if you don't initialize a reference instance variable in a class - NullPointerException
Method Parameters
formal parameter (dummy) : placeholders for actual parameter
actual parameter (argument) : supplied by a particular method in a client program
Passing Primitive types as parameters
When a memory is called, a new memory slot is allocated for each parameter.
Any changes made to parameters will not affect the values of the arguments in the calling program.
Passing Objects as parameters
the address is copied (not the value)
not possible for a method to make an object replace another one
can change the state of the object
3.Inheritance and polymorphism
Inheritance 继承
Superclass and Subclass 超类和子类
a subclass is bigger than a superclass - it contains more methods and data
Inheritance Hierarchy 继承层次结构
a subclass can itself be a superclass of another class
subclass is-a superclass
is-a is transitive
method overriding - rewrite the method from superclass
partial overriding - part of the method is rewritten
Implementing subclasses 实现子类
keyword : extends
public class Superclass
{
// private instance variables
// other data members
// constructors
// public methods
// private methods
}
public class Subclass extends Superclass
{
// additional private instance variables
// additional data members
// constructors (not inherited!)
// additional public methods
// inherited public methods whose implementation is overridden
// additional private methods
}
Inheriting Instance Methods and Variables 继承实例方法和变量
the subclasses inherit all of the methods and variables of the superclass
instance variables are private and not directly accessible to the methods in the subclasses
classes on the same level in a hierarchy diagram do not inherit anything from each other
method overriding and the super keyword 方法重载和super关键字
include a call to the superclass method
subclass method wants to do what the superclass does, plus something extra
a method in a superclass is overridden in a subclass by defining a method with the same return typer and signature
partial overriding
constructors and super 构造函数和super
Constructors are never inherited!
the new instance variable must be explicitly initialized
if super is used in the implementation of a subclass constructor, it must be used in the first line of the constructor body.
if no constructor is provided in a subclass, the compiler provides the following default constructor
public SubClass()
{
Super(); // calls default constructor of superclass
}
Rules for Subclasses
A subclass can add new private instance variables.
A subclass can add new public, private, or static methods.
A subclass can override inherited methods.
A subclass may not redefine a public method as private.
A subclass may not override static methods of the superclass.
A subclass should define its own constructors.
A subclass cannot directly access the private members of its superclass. It must use accessor or mutator methods.
Declaring Subclass Objects 声明子类对象
Student s = new Student();
Student g = new GradStudent();
Student u = new UnderGrad();
A super class does not inherit from a subclass
Polymorphism 多态
Polymorphism is the mechanism of selecting the appropriate method of a particular object in a class hierarchy.
method calls are always determined by the type of the actual object, not the type of object reference.
the selection of the correct method occurs during the run of the program.
Dynamic Binding (Late Binding) 动态绑定(后期绑定)
overloaded - selected at compile time - static binding, early binding
overridden - selected at runtime - late binding
compiler determine if a method can be called
run-time environment determine how it will be called.
Type Compatibility 类型兼容性
Downcasting 向下转换
downcast - casting a superclass to a subclass type
Student s = new GradStudent( );
GradStudent g = new GradStudent( );
int x = s.getID( ); // compile-time error
int y = g.getID( ); // legal
s is of type Student - Student class odes not have a getID method
can be fixed by casting s to the correct type
int x = ((GradStudent) s ).getID( );
the outer parentheses are necessary
The ClassCastException
a run-time exception thrown to signal an attempt to cast an object to a class of which it is not an instance
Abstract Class 抽象类
a superclass that represents an abstract concept
may contains abstract methods - have no implementation code, just a header
appears as a place holder
If a class contains any abstract methods, it must be declared an abstract class
The abstract Keyword abstract关键字
public abstract class AbstractClass
{ ... }
public class SubClass extends AbstractClass
{ ... }
if a subclass of an abstract class does not provide implementation code for all the abstract methods, it too becomes an abstract class
public abstract class Subclass extends AbstractClass
{ ... }
An abstract class can have both instance variables and concrete methods
the header is terminated with a semicolon
It is possible for an abstract class to have no abstract methods
An abstract class may or may not have constructors
No instances can be created for an abstract class
Polymorphism works with abstract classes as it does with concrete classes
Interfaces 接口
Interface 接口
a collection of related methods whose headers are provided without implementations
all methods are public and abstract (no need to explicitly include these keywords)
provide a framework of behavior for any class
Defining an interface 定义接口
public interface FlyingObject {
void fly(); // method that simulate the flight of the object boolean isFlying(); // true if the object is in flight, false otherwise
}
The implements Keyword
public class Bird implements FlyingObject
public class mosquito extends Insect implements FlyingObject
The Comparable Interface
public interface Comparable
{
int compareTo (Object obj);
}
4.Some Standard Classes
The Object Class
The Universal Superclass
every class automatically extends Object
Methods in the Object
Object is NOT an abstract class
expectation : the methods will be overridden in any class where default implementation is not suitable
toString
public String toString()
when you attempt to print an object, the inherited default toString method is invokes
Array objects are unusual in that they do not have toString method
equals
public boolean equals(Object another)
return true if this object and other are the same object (referencing to the same memory slot)
equivalent to the == relation
The String Class
String Objects
a sequence of characters
immutable - no methods to change them after they've been constructed
constructing String Objects
can be initialized like a primitive type
String s = "abc"
String s = new String("abc");
it is possible to reassign a string reference
The Concatenation Operator
If one of the operands is a String and the other is a primitive type, then the non-String operand is converted to a String
If neither of the operands is a String object, an error occurs
Comparison of String Objects
overridden inherited from the Object class and overridden to do the correct thing:
equal
if (string1 .equals (string2)) ...
the String class implement Comparable
compares Strings in dictionary order
return true if string1 and string2 are identical strings
compareTo
java is case-sensitive
digits precede capital letters precede lowercase letters
Other String Methods
int length(
return the length of this String
String substring(int startIndex)
return a substring starts with the character at startIndex and extends to the end of the string
the first character is at index zero
StringIndexOutOfBoundsException if startIndex is negative or larger than the length of the string
String substring (int startIndex, int endIndex)
start at startIndex, end at endIndex-1
int indexOf(String str)
return the index of the first occurrence of str
return -1 if str is not the substring
if str is null - NullPointerException
Wrapper Classes
The Integer Class
The Double Class
5.Program Design and Analysis
The Water Fall Model 瀑布模型
Analysis of Specification 程序详细计划书
a written description based on costumer's requirements
Program Design 程序设计
detailed overall plan without Java code
include all objects + data structure + list of tasks
Implementation 程序实现
actual coding (具体接下来有)
Testing and Debugging 调试和测试
upgrading code as circumstances change
write a robust program to avoid bad input
compile-time error - occur during compilation e.g. syntax error
run-time error - occur during execution "throws an exception"
intent/ logic error - fails to carry out the specification of the program
typical values in each part of the domain
end point values
out-of-range values
Test Data 测试数据
Types of Errors (bugs) 错误类型
Robustness 稳健性
Program Maintenance 程序维护
Object-Oriented Program Design 面对对象程序设计
Identifying Classes 确定类
Basic Object
Collection
Controller
Display
Identifying Behaviors 确定行为
find all verbs in the program description
encapsulation 封装 bundling a group of methods and data fields into a class
Think carefully about who should do what
Determining Relationships Between Classes 确定类之间的关系
Inheritance Relationship 继承关系 (is-a)
Composition Relationship 组合关系 (has-a)
UML Diagrams UML图
实心箭头 has-a
空心箭头 is-a
interface 虚线
Implementing Classes 实现类
start with an over view of the program
collaborators: all other classes needed for one particular class
independent: a class without collaborators
Independent classes are written and tested before being incorporated into the overall project
Bottom-Up development自下而上开发
Top-Down development 自上而下开发
Implementing Methods 实现方法
Procedure Abstraction 过程抽象
avoid repeating code
use helper methods
Information Hiding 信息隐藏
instance variable and helper methods are private
Stub Method 存根方法
stub - a dummy method
Algorithm 算法
Identifying Classes 确定类
use nouns in the description
Relationship Between Classes 确定类之间的关系
Identifying Behaviors 确定行为
Decisions 制定
Program Analysis 程序分析
Program Correctness 程序的正确性
Assertion 验证
Precondition 前提条件
postcondition 后置条件
Efficiency 性能
CPU time (number of machine operations required)
Memory (number and complexity of the variables)
best case, worst case, average case
最后,提醒大家,考前记得多刷几遍题哦!
翰林课程体验,退费流程快速投诉邮箱: yuxi@linstitute.net 沪ICP备2023009024号-1