Unit 1
Unit 2
Unit 3
Unit 4
Wild Card
100

int result = (int) (Math.random() * 10) + 1

What does this generate?

Generates an integer between 1 and 10, inclusive, and assigns it to the variable result.

100

boolean a = true; 

boolean b = false; 

boolean result = (a != b); 

What will the value of result be?

true

100

What is required to create objects of a class?

Instance Variables

Constructors

Constructor Call from the Main Method

100

String[] animals = new String[5];

What is the code required to replace the animal at the last index of this array with "flamingo"?

animals[4] = "flamingo";

100

What rule MUST we follow when declaring the instance variables of a Java class?

They must be declared as PRIVATE.
200

int num = (int)(Math.random() * 6); 

What value can num NEVER be?

6

200

(3 + 4 == 5) != (3 + 4 >= 5) 

What value, if any, does the expression evaluate to? 

true

200

What are the 4 different types of methods we can find in a Java class?

Void

Non Void

Accessor/Getter

Mutator/Setter

200

int[][] table = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}; System.out.println(table[2][1]); 

What value is printed as a result of executing the code segment?

2

200

Will you earn a penalty on the AP exam if you forget to type in the following symbols?

{ } ; 

No, so long as the reader can easily understand the order/sequence of your code.

300

public Person(int idNumber, int age, boolean isActive) { /* implementation not shown */ } 

 Person p3 = new Person(3544, false, 18); 

Why will this object instantiation NOT work?

The list of arguments given is not in the correct order by type. The second argument should be an int and the third argument should be a boolean.

300

boolean a = true; boolean b = true;

System.out.print((b || (!a || b)) + " ");

System.out.print(((!b || !a) && a) + " ");

System.out.println(!(a && b) && b);

What output is produced when this code segment is executed?  

true false false

300

Explain, what is the purpose of a toString() method?

It returns a string that describes the attributes of an object you are referencing.

300

There is an ArrayList of Integer elements that represents the ages of all the students in the school. What code is required to determine how many elements are in this ArrayList? 

.size() to identify the total number of elements

300

Convert this traditional for loop into an enhanced for loop. Assume names is an array of Strings.

for(int i = 0; i<names.length; i ++{

System.out.println(i);

}


for(String i : names){

System.out.println(i);

}

400

String str = "CompSci";

System.out.print(str.substring(1,4));

What will be printed?

omp

400

int count = 5; 

while (count < 100) { 

count = count * 2; } 

count = count + 1;

What is the value of  count  after executing the code segment?

161

400

Explain, what is the purpose of the this keyword?

Programmers can give the parameter variables the same names as the instance variables and  this  can distinguish them and avoid a naming conflict.

400

Explain, what is recursion? What must happen in order for this process to STOP?

Recursion is when a method calls itself. It is a form of repetition.

In order to stop a recursive call, the base case must be met. The base case is the smallest possible problem (or problems) that the method knows how to solve, the ones it can answer directly without any more recursion.

400

Convert this for loop into a while loop:

for (int c = 1; c < 4; c++){

System.out.println(c);

}

int c = 1; 

while(c < 4){

System.out.println(c);

c++;

}

500

String str = "Summer Break";

System.out.print(str.substring(7,8)+str.substring(1,6));

What will be printed?

Bummer

500

int n = 35;
int result = 1;
while (n > 0){    

int d = n % 10;    

result *= d;    

n /= 10; }
System.out.println(result);

What is the output after the code has been executed?

15

500

A Java class can have many different constructors. Explain, what would be the purpose of having more than one constructor? What do we call this process  in Java?

Sometimes you will want to write more than one constructor so that there are different ways of making an instance of your class. One reason to do that is to make it convenient to create instances from different kinds of arguments. This is called overloading.

500

What is required to traverse the elements in a 2D array? Explain why this is required.

A nested for loop is required.

The outer loop accesses the elements in the rows, the inner loop accesses the elements in each column.

500

Where did Ms. Morales go to school for undergrad and what did she major in?

Pepperdine University, Biology B.A

M
e
n
u