點擊上方“藍色字”可訂閱哦!
在美國大學中學習,計算機知識是必不可少的,在以后的就業中,計算機應用也非常廣,因此在選擇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
最后,提醒大家,考前記得多刷幾遍題哦!

? 2025. All Rights Reserved. 滬ICP備2023009024號-1