Finals Notes II Flashcards

(20 cards)

1
Q

How can you shorten x = x + 1 and x = x + y?

A

x++;
x += y;

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

How do you import a scanner?

A

java.util.Scanner;

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

What should you use after using nextInt() or nextDouble()?

A

input.nextLine();

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

How do you state a new Scanner?

A

Scanner input = new Scanner(System.in)

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

What is the stack?

A
  • Stores local variables
  • Stores references to objects in the heap
  • Stores method calls
  • Memory is allocated and freed automatically as methods are called and returned
  • Follows LIFO (Last In, First Out) order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the heap?

A
  • Stores all objects (keywords, arrays, Strings, etc.)
  • Stores instance variables inside objects
  • Stores string literals in a String Pool
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when you have String str1 = “abc” and String str2 = “abc”?

A

They both refer to the same object, saving memory from not creating a new object.

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

What happens when you have String str1 = “abc” and String str3 = new String(“abc”)?

A

A new object is forced to be created. Str1 and str3 do not point to the same area.

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

What is immutability?

A

Strings cannot be changed unless they are re-assigned.

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

What are some escape sequences to help you use special characters in Strings?

A
  • \” for quotations
  • \ for backslashes
  • \n for a line break
  • \t for a tab space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Compare these values in ASCII.
“A”.compareTo(“B”)
“test”.compareTo(“testing”)
“testing”.compareTo(“test”)

A

<0
<0
>0

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

How do you make an array?

A

type[] name = new type[# of elements]

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

What exception would you get for accessing a value outside an array?

A

ArrayIndexOutOfBoundsException

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

How do you structure an enhanced for loop?

A

for (type loopName: dataName)
{ code here }

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

What coordinate would you look at for gradeBook[2][1]?

A

(3, 2)

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

In gradeBook[x][y], what is the row and what is the column?

A

x = row; y = column

17
Q

How do you declare a 2D array?

A

type[][] array = new type[x][y]

18
Q

What does array.length do for a 2D array?

A

Shows the number of rows.

19
Q

What does array[r].length do?

A

Shows the number of items of that row.

20
Q

public static int multiply(int a, int b) {
return a * b;
}
int product = multiply(x, y);

What are the arguments?
What are the parameters?

A

X and y
A and b