AP CSA EXAM REVIEW

studied byStudied by 10 people
4.0(1)
Get a hint
Hint

• a constant

• holds the largest value for the int data type

• 2^31 –1

1 / 43

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

44 Terms

1

• a constant

• holds the largest value for the int data type

• 2^31 –1

Integer.MAX_VALUE

New cards
2

• a constant

• holds the smallest value for the int data type

• -2^31

Integer.MIN_VALUE

New cards
3

• 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

New cards
4

• keyword used to make a variable a constant

final

New cards
5

• 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

New cards
6

• 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?

New cards
7

answer: urk

String s = “turkey”;

what is: s.substring(1, 4);

New cards
8

• answer: 3

• 7 divides into 3 zero times, leaving 3 as a remainder

int x = 3 % 7;

New cards
9

• 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;

New cards
10

• 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?

New cards
11

• the + operator which combines strings together

String concatenation

New cards
12

A) \

B) new line

C) “

What are:

A) \\

B) \n

C) \”

New cards
13

• && (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

New cards
14

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();

}

New cards
15

• == 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?

New cards
16

• 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

New cards
17

Wrapper class that holds ints

• used to store ints in an ArrayList

• holds the MAX_VALUE and MIN_VALUE

Integer

New cards
18

• 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

New cards
19

• creates a reference to an object in memory

• calls the constructor in the object

new

New cards
20

• 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

New cards
21

• means a method does not return a value

void

New cards
22

• 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?

New cards
23

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);

}

New cards
24

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?

New cards
25

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

New cards
26

• 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

New cards
27

Public means the variable or method can be accessed outside the class, private means it cannot

public vs. private

New cards
28

• Create a one-line comment

//

New cards
29

• Makes a comment

• Can block out several lines of code

/* */

New cards
30

• answer: (x == 5 || y>0)

Simplify: !(x != 5 && y <=0)

New cards
31

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.

New cards
32

• 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

New cards
33

• Used to define a set of behavior for a group of classes

• example: List interface, Comparable interface

interface

New cards
34

• 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?

New cards
35

• 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?

New cards
36

• Used to show a class uses an interface

• example: public class Binary implements Comparable{

implements

New cards
37

• 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?

New cards
38

A

What is output if x = 7;

if( x % 2 ==1)

System.out.print(“A”);

else

System.out.print(“B”);

New cards
39

• Connects a child class to it’s parent

• The child class inherits all the features of the parent class

extends

New cards
40

• calls the constructor of the parent class

• must be the first line in the child class’ constructor

super

New cards
41

• 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

New cards
42

• template for a object

• can include variables and methods

class

New cards
43

• 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

New cards
44

• a variable of a class type

• can hold data (variables) and have methods

object

New cards

Explore top notes

note Note
studied byStudied by 34 people
... ago
4.0(1)
note Note
studied byStudied by 5 people
... ago
5.0(1)
note Note
studied byStudied by 225 people
... ago
5.0(1)
note Note
studied byStudied by 14 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 14 people
... ago
5.0(1)
note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 128 people
... ago
4.0(1)

Explore top flashcards

flashcards Flashcard (100)
studied byStudied by 20 people
... ago
5.0(2)
flashcards Flashcard (32)
studied byStudied by 39 people
... ago
5.0(1)
flashcards Flashcard (156)
studied byStudied by 10 people
... ago
5.0(1)
flashcards Flashcard (32)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (33)
studied byStudied by 4 people
... ago
5.0(2)
flashcards Flashcard (66)
studied byStudied by 19 people
... ago
5.0(2)
flashcards Flashcard (26)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (37)
studied byStudied by 13 people
... ago
5.0(2)
robot