AP® Computer Science A Unit 1 flashcardsUsing Objects and Methods
40 cards · about 10 minutes for the whole deck
Flashcard drill
Space flips the card, arrow keys move, and keys 1 to 4 rate how well you knew it.
- Position
- 1 / 40
- Due
- 40
- Mastered
- 0 / 40
This card: New
Flip the card before you rate it.
Algorithm
A step-by-step process for solving a problem. The order of the steps (sequencing) matters, since the same steps in a different order can give a different result.
Topic 1.1: Introduction to Algorithms, Programming, and Compilers
Compiler
The tool that checks your Java for syntax errors and translates it so it can run. Code with a syntax error won't run at all.
Topic 1.1: Introduction to Algorithms, Programming, and Compilers
Syntax error
A mistake in the rules of the language, like a missing semicolon or brace. The compiler catches it before the program can run.
Topic 1.1: Introduction to Algorithms, Programming, and Compilers
Logic error
A mistake that lets the program run but gives the wrong result, like averaging with the wrong formula. Testing with known answers finds it.
Topic 1.1: Introduction to Algorithms, Programming, and Compilers
Run-time error
An error that happens while the program is running and makes it stop early. An exception, like dividing an int by 0, is one kind.
Topic 1.1: Introduction to Algorithms, Programming, and Compilers
Primitive type
A basic type that holds a simple value directly. This course uses three:
int(whole numbers),double(decimals) andboolean(true/false).Topic 1.2: Variables and Data Types
Reference type
Any class type, like
String. A reference variable holds a reference (like an address) to an object, not the object itself.Topic 1.2: Variables and Data Types
Integer division
Dividing two
ints gives anintand drops the decimal part:7 / 2is 3. Make one value adoubleto keep the decimal:7 / 2.0is 3.5.Topic 1.3: Expressions and Output
Remainder operator
%Gives the remainder after integer division:
17 % 5is 2.n % 2 == 0checks for even numbers, andn % 10gets the last digit.Topic 1.3: Expressions and Output
Escape sequence
A backslash code inside a string literal:
\"is a double quote,\\is a backslash and\nis a new line.Topic 1.3: Expressions and Output
printvs.printlnSystem.out.printprints and stays on the same line.System.out.printlnprints and then moves to the next line.Topic 1.3: Expressions and Output
ArithmeticExceptionThe exception thrown when you divide an
intby theint0 (with/or%). It happens while the program runs, not at compile time.Topic 1.3: Expressions and Output
Assignment operator
=Works out the value on the right first, then stores it in the variable on the left. So
x = x + 1uses the oldxto make the new one.Topic 1.4: Assignment Statements and Input
nullThe value of a reference variable that doesn't point to any object. Calling a method on
nullthrows aNullPointerException.Topic 1.4: Assignment Statements and Input
Casting
Converting a value to another type:
(int) 3.9is 3 and(double) 7is 7.0. A cast applies only to the value right after it.Topic 1.5: Casting and Range of Variables
Rounding with a cast
(int) (x + 0.5)rounds a non-negativedoublex to the nearestint. Casting alone always cuts off the decimal part.Topic 1.5: Casting and Range of Variables
Integer overflow
Going past
Integer.MAX_VALUEorInteger.MIN_VALUE. Java doesn't stop; the value wraps around to the other end of the range.Topic 1.5: Casting and Range of Variables
Round-off error
A tiny error because most decimals can't be stored exactly in a
double.0.1 + 0.2 == 0.3isfalsefor this reason.Topic 1.5: Casting and Range of Variables
Compound assignment operator
A shortcut like
+=,-=,*=,/=or%=that does the math with the variable's current value and stores the result back:x += 3isx = x + 3.Topic 1.6: Compound Assignment Operators
++and--count++adds 1 andcount--subtracts 1. On the exam they're only used as statements on their own, after the variable.Topic 1.6: Compound Assignment Operators
API documentation
The description of a library's classes: their constructors and methods, what they need and what they do. You can use a class without seeing its code.
Topic 1.7: Application Program Interface (API) and Libraries
Attribute vs. behavior
An attribute is data an object stores (like a title). A behavior is something it can do (like play), written as a method.
Topic 1.7: Application Program Interface (API) and Libraries
Precondition
A condition that must be true before a method is called. The method doesn't check it; the caller is responsible.
Topic 1.8: Documentation with Comments
Postcondition
A condition that will be true after a method finishes, such as what it returns, as long as its preconditions were met.
Topic 1.8: Documentation with Comments
Method signature
A method's name plus its parameter types in order, like
area(int, int). The return type and parameter names aren't part of it.Topic 1.9: Method Signatures
Overloading
Several methods (or constructors) with the same name but different parameter lists. Java picks the one whose parameters match the arguments.
Topic 1.9: Method Signatures
Call by value
Java passes a copy of each argument's value. Changing a primitive parameter inside a method never changes the caller's variable.
Topic 1.9: Method Signatures
Class method
A method marked
staticthat belongs to the class, not an object. Call it with the class name:Math.sqrt(16.0).Topic 1.10: Calling Class Methods
Math.random()Returns a
doublefrom 0.0 up to but not including 1.0.(int) (Math.random() * n) + agives a randomintfrom a to a + n - 1.Topic 1.11: Math Class
Math.powandMath.sqrtMath.pow(a, b)gives aᵇ andMath.sqrt(x)gives √x. Both return adouble, soMath.pow(2, 3)is 8.0.Topic 1.11: Math Class
Object
One specific instance of a class, with its own copy of the class's data. A class is the blueprint; objects are what you build from it.
Topic 1.12: Objects: Instances of Classes
Superclass and subclass
A subclass inherits from its superclass. Every class in Java is a subclass of
Object.Topic 1.12: Objects: Instances of Classes
Constructor
Code that sets up a new object. It has the same name as the class and runs when you use
new, likenew Book("Emma", 300).Topic 1.13: Object Creation and Storage (Instantiation)
Aliasing
Two reference variables that refer to the same object, as after
b = a;. A change made through one shows up through the other.Topic 1.13: Object Creation and Storage (Instantiation)
NullPointerExceptionThrown when you call a method on a reference that holds
null, because there's no object to call it on.Topic 1.14: Calling Instance Methods
Immutable String
A
Stringcan't be changed. Methods likesubstringreturn a new string, so you must store the result to keep it.Topic 1.15: String Manipulation
substring(a, b)Returns the characters from index a up to but not including index b, so its length is b - a.
substring(a)goes to the end.Topic 1.15: String Manipulation
indexOf(str)Returns the index where
strfirst appears, or -1 if it isn't there.Topic 1.15: String Manipulation
equalsvs.==for stringsa.equals(b)checks whether two strings have the same characters.==only checks whether they're the same object, so useequals.Topic 1.15: String Manipulation
compareToa.compareTo(b)is negative if a comes first alphabetically, 0 if they're equal and positive if a comes after b.Topic 1.15: String Manipulation