APCSA Flashcards

(113 cards)

1
Q

What is the default value of an int variable in Java?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the result of 7 / 2 in Java?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the result of 7.0 / 2 in Java?

A

3.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the % (modulo) operator return?

A

The remainder after division

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you declare a double variable called price?

A

double price;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the result of casting (int) 4.9?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which Java class is used to generate random numbers?

A

java.util.Random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of Math.random()?

A

Generates a double between 0.0 (inclusive) and 1.0 (exclusive)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you import the Scanner class?

A

import java.util.Scanner;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you read an int from the console using Scanner?

A

Scanner sc = new Scanner(System.in); int x = sc.nextInt();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What method checks string equality?

A

.equals()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What method returns string length?

A

.length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What method returns a character at index i of a String?

A

.charAt(i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you concatenate two Strings?

A

Using the + operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the output of ‘abc’.substring(1,3)?

A

bc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a class in Java?

A

A blueprint for creating objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is an object in Java?

A

An instance of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What keyword is used to create a new object?

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the constructor do?

A

Initializes a new object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an instance variable?

A

A variable defined inside a class but outside methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the visibility of public?

A

Accessible from any class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the visibility of private?

A

Accessible only inside the same class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a method?

A

A function defined inside a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the purpose of a return type?

A

Specifies the data type the method returns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What keyword is used to exit a method and send back a result?
return
26
What is method overloading?
Multiple methods with the same name but different parameters
27
What is method overriding?
Redefining a method in a subclass
28
What is a static method?
A method that belongs to the class, not instances
29
How do you call a static method?
ClassName.methodName()
30
What are parameters?
Inputs passed to a method
31
What is a local variable?
A variable defined inside a method
32
What is a Boolean expression?
An expression that evaluates to true or false
33
What operators are used in Boolean logic?
&&, ||, !
34
What is short-circuit evaluation?
Stopping evaluation when the result is already determined
35
What is the result of true || false && false?
true
36
What does an if statement do?
Executes a block of code based on a condition
37
What does else do?
Executes when the if condition is false
38
What loop is best when number of iterations is known?
for loop
39
What loop is best when condition must be checked before starting?
while loop
40
What is an accumulator variable?
A variable used to store a running total
41
What keyword breaks out of a loop?
break
42
What keyword skips to the next loop iteration?
continue
43
How do you declare an array of 10 integers?
int[] arr = new int[10];
44
How do you get the length of an array?
arr.length
45
What is the index of the first element of an array?
0
46
What exception occurs if you access an invalid array index?
ArrayIndexOutOfBoundsException
47
What is an enhanced for loop?
A for-each loop to iterate over arrays or collections
48
How do you declare an ArrayList of Strings?
ArrayList list = new ArrayList<>();
49
How do you add an element to an ArrayList?
list.add('item');
50
How do you access an element at index i of an ArrayList?
list.get(i)
51
How do you change the value at index i in an ArrayList?
list.set(i, 'newValue')
52
How do you remove an element from an ArrayList?
list.remove(i)
53
How do you get the size of an ArrayList?
list.size()
54
What happens when you remove elements during a for-each loop?
ConcurrentModificationException
55
How do you traverse a 2D array?
Nested for loops
56
How do you declare a 2D array of ints?
int[][] matrix = new int[3][4];
57
How do you get the number of rows in a 2D array?
matrix.length
58
How do you get the number of columns in a 2D array row?
matrix[0].length
59
What is inheritance?
A way for one class to inherit from another
60
What is the keyword for a subclass?
extends
61
What is polymorphism?
The ability for objects to take many forms
62
What is dynamic binding?
Method calls are resolved at runtime
63
What is the Object class?
The root of all Java classes
64
What is the equals() method used for?
To compare two objects' content
65
What is the difference between == and .equals()?
== compares references, .equals() compares content
66
What is an abstract class?
A class that cannot be instantiated and may have abstract methods
67
What is an interface?
A collection of abstract methods
68
What is recursion?
A method that calls itself
69
What must every recursive method have?
A base case
70
What is stack overflow?
Error from infinite recursion
71
What is factorial(n) recursively?
n * factorial(n-1)
72
What is linear search?
Checking each element in order
73
What is binary search?
Repeatedly dividing a sorted array to find a value
74
What sorting algorithm uses nested loops to compare each pair?
Bubble sort
75
What sorting algorithm selects the smallest element each pass?
Selection sort
76
What sorting algorithm builds a sorted array one element at a time?
Insertion sort
77
What is Big-O notation?
Describes algorithm time complexity
78
What is the Big-O of binary search?
O(log n)
79
What is the Big-O of bubble sort?
O(n^2)
80
What is the Big-O of linear search?
O(n)
81
What is encapsulation?
Hiding internal state with private variables and public methods
82
What is cohesion?
How closely related the responsibilities of a class are
83
What is coupling?
The degree to which one class relies on another
84
What is the main() method signature?
public static void main(String[] args)
85
How do you create a new object of class Car?
Car myCar = new Car();
86
How do you use inheritance to make class Dog from Animal?
class Dog extends Animal
87
What does super() do?
Calls the superclass constructor
88
How do you override a method from a superclass?
Use @Override annotation and redefine the method
89
What is an interface used for?
To define a contract of methods that a class must implement
90
What is the difference between Array and ArrayList?
Array is fixed size, ArrayList is dynamic
91
What is null?
A reference that points to no object
92
What error is thrown when you call a method on null?
NullPointerException
93
How do you declare a constant?
final int MAX = 100;
94
What package includes ArrayList and Scanner?
java.util
95
How do you implement Comparable interface?
public class MyClass implements Comparable
96
How do you compare objects using compareTo?
Return negative if less, 0 if equal, positive if greater
97
What is autoboxing?
Automatic conversion from primitive to wrapper class
98
What is unboxing?
Automatic conversion from wrapper class to primitive
99
What wrapper class corresponds to int?
Integer
100
What does instanceof check?
Whether an object is an instance of a class
101
What is the purpose of this keyword?
Refers to the current object
102
How do you create a generic method?
Use before return type
103
How do you prevent a class from being inherited?
Use the final keyword
104
What is overloading?
Multiple methods with same name but different parameter lists
105
What are the 4 FRQ types on the AP CSA exam?
Methods and Control Structures, Classes, Arrays/ArrayLists, 2D Arrays
106
How long is the AP CSA exam?
3 hours
107
What percent of the exam is FRQ?
0.5
108
How many FRQs are on the exam?
4
109
How many MCQs are on the exam?
40
110
How many points is each FRQ worth?
9 points
111
What is the max score on the AP CSA exam?
5
112
How many points do you need to score a 5?
About 70–80% total
113
What is the best strategy for FRQs?
Write readable, correct code; use helper methods if needed