AP Computer Science Java Vocabulary Review
Java Quick Reference
Accessible Methods from the Java Library:
class java.lang.Object:
boolean equals (Object other)String toString()class java.lang.Integer:
Integer (int value)int intValue()Integer.MIN_VALUEInteger.MAX_VALUEclass java.lang.Double:
Double (double value)double doubleValue()class java.lang.String:
int length()String substring(int from, int to)returns substring from 'from' to 'to-1'
String substring(int from)returns substring from 'from' to end
int indexOf(String str)returns the index of first occurrence of str, -1 if not found
int compareTo(String other)returns < 0 if less than other, = 0 if equal, > 0 if greater
class java.lang.Math:
static int abs(int x)static double abs(double x)static double pow(double base, double exponent)static double sqrt(double x)static double random()interface java.util.List:
int size()boolean add(E obj)append obj to end of list
void add(int index, E obj)insert obj at position index, shifting elements
E get(int index)E set(int index, E obj)replace element at position index
E remove(int index)remove element at position index
AP Computer Science Java Subset
Purpose of the Java Subset
Outline features of Java that may appear on the AP Computer Science A Exam.
Supplementary details on input/output methods are not tested.
Key Features in the AP Java Subset:
Enables meaningful question formulation.
Assists students in test preparation.
Allows instructor flexibility in teaching methods.
Language Features on AP CS A Exam
Tested Language Features:
Comments:
/* */,//,/** ... */Primitive Types:
int,char,boolean, etc.Operators: Arithmetic (
+,-), Increment/Decrement (++,--), Assignment (=), Etc.Control Statements:
if,else,while,for,returnVariables: Include parameter and local variables
Not Tested Features:
User input methods (Scanner, System.in, etc.)
3D arrays and other complex arrays
switchstatements,try/catch/finally
Working with Arrays
Array Characteristics:
All items in an array must be of the same data type.
Length can be found using
nameOfArray.length.
1D Arrays:
Declaration:
int[] example = new int[10];Initialization:
int[] example2 = {1, 2, 5, 6};Printing:
Arrays.toString(example2);
2D Arrays:
Declaration:
int[][] example3 = new int[3][4];Row-major order indexing.
Searching Arrays:
Sequential Search: Check each element until key is found.
Binary Search: Requires sorted array.
Exception Handling
Exceptions to Watch:
NullPointerExceptionIndexOutOfBoundsExceptionArithmeticExceptionIllegalArgumentException
Handling Exceptions:
try/catchblocks used for observing code that could throw exceptions.
Javadoc Comments
Purpose: Generates HTML documentation from code comments.
Common Tags:
@param,@return,@exception,@authorUsage Example: ```java /**
Method description
@param arg1 description
@return description
*/
public void method(int arg1){}
```
Test-Taking Tips for AP Computer Science Exam
Multiple Choice Tips:
Read questions carefully; focus on keywords.
Use scratch paper for calculations.
Guess only if you can eliminate at least 2 options.
Free Response Tips:
Read the whole question, then focus on parts incrementally.
Reuse code and methods wherever possible to avoid redundancy.
Time management is crucial; aim for 20 minutes per question.
Recursion
Definition: Method calling itself with a base case.
Example: Factorial implementation.
Polymorphism and Inheritance
Polymorphism: An object can take many forms, typically through class references.
Inheritance: Allows a child class to inherit properties and behavior from a parent class.
Example:
class Child extends Parent {}