How can you shorten x = x + 1 and x = x + y?
x++;
x += y;
How do you import a scanner?
java.util.Scanner;
What should you use after using nextInt() or nextDouble()?
input.nextLine();
How do you state a new Scanner?
Scanner input = new Scanner(System.in)
What is the stack?
What is the heap?
What happens when you have String str1 = “abc” and String str2 = “abc”?
They both refer to the same object, saving memory from not creating a new object.
What happens when you have String str1 = “abc” and String str3 = new String(“abc”)?
A new object is forced to be created. Str1 and str3 do not point to the same area.
What is immutability?
Strings cannot be changed unless they are re-assigned.
What are some escape sequences to help you use special characters in Strings?
Compare these values in ASCII.
“A”.compareTo(“B”)
“test”.compareTo(“testing”)
“testing”.compareTo(“test”)
<0
<0
>0
How do you make an array?
type[] name = new type[# of elements]
What exception would you get for accessing a value outside an array?
ArrayIndexOutOfBoundsException
How do you structure an enhanced for loop?
for (type loopName: dataName)
{ code here }
What coordinate would you look at for gradeBook[2][1]?
(3, 2)
In gradeBook[x][y], what is the row and what is the column?
x = row; y = column
How do you declare a 2D array?
type[][] array = new type[x][y]
What does array.length do for a 2D array?
Shows the number of rows.
What does array[r].length do?
Shows the number of items of that row.
public static int multiply(int a, int b) {
return a * b;
}
int product = multiply(x, y);
What are the arguments?
What are the parameters?
X and y
A and b