Home
Explore
Exams
Search for anything
Login
Get started
Home
AP CSA EXAM REVIEW
AP CSA EXAM REVIEW
4.0
(1)
Rate it
Studied by 10 people
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Card Sorting
1/43
There's no tags or description
Looks like no tags are added yet.
Study Analytics
All
Learn
Practice Test
Matching
Spaced Repetition
Name
Mastery
Learn
Test
Matching
Spaced
No study sessions yet.
44 Terms
View all (44)
Star these 44
1
New cards
• a constant
• holds the largest value for the int data type
• 2^31 –1
Integer.MAX_VALUE
2
New cards
• a constant
• holds the smallest value for the int data type
• -2^31
Integer.MIN_VALUE
3
New cards
• variable is connected to the whole class, not individual objects
• all variables of the class share this one variable
• with the keyword final it is used to create a constant
• also called: class variables
static variable
4
New cards
• keyword used to make a variable a constant
final
5
New cards
• resizable array
• uses the List interface
• only holds objects
• built in methods for inserting, deleting, etc
• Can use the for-each loop or regular for-loop
ArrayList
6
New cards
• answer: 3
• Remember that with integer division the decimal is cut off, no rounding happens
int x = 7;
x = x /2;
what does x equal?
7
New cards
answer: urk
String s = “turkey”;
what is: s.substring(1, 4);
8
New cards
• answer: 3
• 7 divides into 3 zero times, leaving 3 as a remainder
int x = 3 % 7;
9
New cards
• answer: B
• Since 4.5 is a double you must use a numeric cast to change it to an int.
Which is correct?
A. int x = (double) 4.5;
B. int x = (int) 4.5;
C. int x = 4.5;
10
New cards
• answer: ans 45
• Since the first thing after the = is a String, java uses concatenation
• so it changes 4 to a String, puts it on the end of ans , then changes 5 to a String and puts it at the end
String w = “ans: “+ 4 + 5; What is w?
11
New cards
• the `+` operator which combines strings together
String concatenation
12
New cards
A) \\
B) new line
C) “
What are:
A) \\\\
B) \\n
C) \\”
13
New cards
• && (and): if the first part is false, the whole thing will be false, so it never tests the second part
• || (or): if the first part is true, the whole thing will be true, so it never tests the second part
Short circuit evaluation
14
New cards
1 2 3 4
2 4
3
4
What is output?
for (int a = 1; a < 5; a++){
for (int b = a; b < 5; b += a)
System.out.print(b);
System.out.println();
}
15
New cards
• == only does a primitive test for equality
• in objects this means it is testing the memory address, not the values stored in the object
Why is it best to use .equals instead of == with objects?
16
New cards
• In the same class, many methods with the same name
• Java tells them apart using the signature
• Signature: the number a type of parameters
• CANNOT use the methods return type to tell them apart
overloading
17
New cards
Wrapper class that holds ints
• used to store ints in an ArrayList
• holds the MAX_VALUE and MIN_VALUE
Integer
18
New cards
• array can hold primitive types or class types
• all elements are of the same type
• not resizable
• Use the regular for-loop
• Use .length to find the size
simple arrays
19
New cards
• creates a reference to an object in memory
• calls the constructor in the object
new
20
New cards
• builds an object in memory
• sets up all the variables in the objects
• has the same name as the class
• NEVER has a return type or void
• can overload the constructor—Java tells them apart by the number and type of the parameters
constructor
21
New cards
• means a method does not return a value
void
22
New cards
• An array of integers
• If this is a free response question the first thing you should do is: int \[\] list = new int \[10\];
public int \[\] doStuff()
What type does this method return?
23
New cards
15
What is returned by the call mystery(5)?
public static int mystery(int num){
if (num ==0) return 0;
return num + mystery(num - 1);
}
24
New cards
answer:
0 1 2 3
10 14 4 8
int list \[\] = { 5, 7, 2, 4};
for (int i = 0; i < list.length; i++) l
ist \[i\] = list\[i\] \* 2;
What is stored in list after this loop?
25
New cards
`null` is a special value that can be assigned to any object reference variable to indicate that the variable does not refer to any object.
null
26
New cards
• 2-D arrays are row-major—> the rows come first.
• rows = 3, columns = 5
\
for(int r = 0; r < stuff.length; r++)
for (int c = 0; c < stuff\[r\].length; c++)
stuff\[r\]\[c\] = r + c;
int stuff \[\] \[\] = new int \[3\]\[5\];
How many columns? How many rows?
Write the for loops to initialize this to: 01234 12345 23456
27
New cards
Public means the variable or method can be accessed outside the class, private means it cannot
public vs. private
28
New cards
• Create a one-line comment
//
29
New cards
• Makes a comment
• Can block out several lines of code
/\* \*/
30
New cards
• answer: (x == 5 || y>0)
Simplify: !(x != 5 && y
31
New cards
int maxIndex = 0;
for (int i = 1; i < x.length; i++){
if (x\[maxIndex\] < x\[i\])
maxIndex = i;
}
int x\[\];
Assume this array has been initialized. Write a loop to find the index of the largest element.
32
New cards
• method connected to the class, not an object
• ex: Math.random
• You do not declare a variable of Math type to get to the random method
static methods
33
New cards
• Used to define a set of behavior for a group of classes
• example: List interface, Comparable interface
interface
34
New cards
• Interfaces cannot have variables or code in methods. They can only have constants and a list of abstract methods
• Abstract classes can have some code along with the abstract methods
How are abstract classes different than interfaces?
35
New cards
• second must include code for all of the abstract methods in first.
• If second does not have code for all the abstract methods in first, second is also abstract
• The abstract methods are like a todo list, once a child class has code for all the abstract methods, the abstraction is lifted
You have an abstract class called first. A child class called second extends first. What must be true for second to NOT be abstract?
36
New cards
• Used to show a class uses an interface
• example: public class Binary implements Comparable{
implements
37
New cards
• Since b1 is null, it does not point to a location in memory. We cannot use any methods on a null object.
• throws a NullPointerException,
Bug b1 = null;
b1.act();
What’s wrong?
38
New cards
A
What is output if x = 7;
if( x % 2 ==1)
System.out.print(“A”);
else
System.out.print(“B”);
39
New cards
• Connects a child class to it’s parent
• The child class inherits all the features of the parent class
extends
40
New cards
• calls the constructor of the parent class
• must be the first line in the child class’ constructor
super
41
New cards
• A class set up to be a parent to a subclass
• can have abstract methods, these are methods with no code
• an abstract class cannot be instantiated (cannot create an object from it)
• If the child class does not implement all the abstract methods it is also abstract
abstract class
42
New cards
• template for a object
• can include variables and methods
class
43
New cards
• All classes are children of this class
• has a toString and equals method
• toString returns the variable’s memory address
• equals tests if two variables memory addresses are the same
• the equals and toString methods are usually rewritten in child classe
Object
44
New cards
• a variable of a class type
• can hold data (variables) and have methods
object