點(diǎn)擊上方“藍(lán)色字”可訂閱哦!
在美國(guó)大學(xué)中學(xué)習(xí),計(jì)算機(jī)知識(shí)是必不可少的,在以后的就業(yè)中,計(jì)算機(jī)應(yīng)用也非常廣,因此在選擇AP 科目時(shí),很多中國(guó)留學(xué)生對(duì)計(jì)算機(jī)科目情有獨(dú)鐘。今天我們來(lái)梳理一下計(jì)算機(jī)A的考點(diǎn),加油備考吧!
首先來(lái)看一下計(jì)算機(jī)學(xué)習(xí)和復(fù)習(xí)的用書(shū)建議。
輔導(dǎo)書(shū)類(lèi):
Barron's AP Computer Science?A
★★★★★
巴郎的教材完全覆蓋AP考試考點(diǎn),課后題目較多,難度、題型與考試相近,但知識(shí)點(diǎn)講解不夠深入,適合作為復(fù)習(xí)書(shū)和刷題使用。
Princeton AP Computer Science A
★★★★
題目難度偏低,適合初學(xué)時(shí)使用。和巴郎教材二選一即可。
Course Description
★★★★
不管準(zhǔn)備任何AP科目考試說(shuō)明都是最好的學(xué)習(xí)資料,適合前期明確考試范圍和后期查漏補(bǔ)缺時(shí)使用。
5?Steps?to?a?5
★★★★
例題部分比 Barron 要少,難度相當(dāng)。
Think Java?How to Think Like a Computer Scientist
★★★
由于AP計(jì)算機(jī)考試中涉及的Java只是java的子集,所以本書(shū)只適合作為參考書(shū)使用。
下面是考點(diǎn)梳理,做好筆記哦!
1.Introductory Java Language Features
Package And Classes 類(lèi)和包
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 標(biāo)識(shí)符和類(lèi)型
Identifiers 標(biāo)識(shí)符
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 內(nèi)置類(lèi)型
int - 整數(shù)
boolean - true or false
double - 小數(shù)
Storage of Numbers 數(shù)值儲(chǔ)存
Integers 整數(shù)
binary
Integer.MAX_VALUE == 2^31-1
Integer.MIN_VALUE == - 2^31
Floating-Point Numbers 浮點(diǎn)數(shù)
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 十六進(jìn)制數(shù)
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 運(yùn)算符
Arithmetic Operators 算數(shù)運(yùn)算符
+ addition ? - subtraction ? * multiplication ? /devision ? %mod(remainder)
Relational Operators 關(guān)系運(yùn)算符
== 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 邏輯運(yùn)算符
! 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 賦值運(yùn)算符
Compound assignment operators :
= ? ? ?+= ? ? ?-= ? ? ?*= ? ? ?/= ? ? ?%=
Increment and Decrement Operator 遞增遞減運(yùn)算符
++ ? ? ?--
Operator Precedence 運(yùn)算符的優(yōu)先級(jí)
!, ++ , -- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?right to left
* , / , % ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? left to right
+ , - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? left to right
<, >, <=, >= ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?left to right
== , !=? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??left to right
&&
||
=, +=, -+, *=, /=, %= ? ? ? ? ? ? ? ? ? ?right to left
Input/Output 輸入輸出
Escape sequences 轉(zhuǎn)義字符
newline
" ? ? ?double quot
backslash
Control?Structures 控制結(jié)構(gòu)
Decision-Making Control Structures 條件結(jié)構(gòu)
if...
if...else...
nested if
extended if (if...elseif...)
Iteration 循環(huán)結(jié)構(gòu)
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 公開(kāi),私有,靜態(tài)
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 訪問(wèn)器
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 ?靜態(tài)方法
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 ?超類(lèi)和子類(lèi)
a subclass is bigger than a superclass - it contains more methods and data
Inheritance Hierarchy ?繼承層次結(jié)構(gòu)
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 ?實(shí)現(xiàn)子類(lèi)
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 ?繼承實(shí)例方法和變量
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關(guān)鍵字
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 ? 構(gòu)造函數(shù)和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 ?聲明子類(lèi)對(duì)象
Student s = new Student();
Student g = new GradStudent();
Student u = new UnderGrad();
A super class does not inherit from a subclass
Polymorphism 多態(tài)
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) 動(dòng)態(tài)綁定(后期綁定)
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 類(lèi)型兼容性
Downcasting 向下轉(zhuǎn)換
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 ?抽象類(lèi)
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關(guān)鍵字
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 程序詳細(xì)計(jì)劃書(shū)
a written?description?based on costumer's requirements
Program Design 程序設(shè)計(jì)
detailed overall plan without Java code
include all objects + data structure + list of tasks
Implementation 程序?qū)崿F(xiàn)
actual coding (具體接下來(lái)有)
Testing and Debugging 調(diào)試和測(cè)試
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 測(cè)試數(shù)據(jù)
Types of Errors (bugs) 錯(cuò)誤類(lèi)型
Robustness 穩(wěn)健性
Program Maintenance 程序維護(hù)
Object-Oriented Program Design 面對(duì)對(duì)象程序設(shè)計(jì)
Identifying Classes 確定類(lèi)
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 確定類(lèi)之間的關(guān)系
Inheritance Relationship 繼承關(guān)系 (is-a)
Composition Relationship 組合關(guān)系 (has-a)
UML Diagrams ?UML圖
實(shí)心箭頭 has-a
空心箭頭 is-a
interface 虛線
Implementing Classes 實(shí)現(xiàn)類(lèi)
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自下而上開(kāi)發(fā)
Top-Down development 自上而下開(kāi)發(fā)
Implementing Methods 實(shí)現(xiàn)方法
Procedure Abstraction 過(guò)程抽象
avoid repeating code
use helper methods
Information Hiding 信息隱藏
instance variable and helper methods are private
Stub Method 存根方法
stub - a dummy method
Algorithm 算法
Identifying Classes 確定類(lèi)
use nouns in the description
Relationship Between Classes 確定類(lèi)之間的關(guān)系
Identifying Behaviors 確定行為
Decisions 制定
Program Analysis 程序分析
Program Correctness 程序的正確性
Assertion 驗(yàn)證
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號(hào)-1