review Flashcards

(49 cards)

1
Q

What is the default value of a boolean?

A

false

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

What is the default value of an int?

A

0

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

What does Math.random() return?

A

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
4
Q

How do you generate an int from 1 to 10 using Math.random()?

A

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

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

What does == do for primitives?

A

Compares values

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

What does == do for objects?

A

Compares references (not content)

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

How do you compare strings?

A

Using .equals()

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

What does .equalsIgnoreCase() do?

A

Compares strings ignoring upper/lower case

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

How do you convert String to int?

A

Integer.parseInt(str)

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

How do you convert String to double?

A

Double.parseDouble(str)

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

How do you convert int to String?

A

Integer.toString(num)

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

What does charAt(i) return?

A

The character at index i in a string

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

What is string concatenation?

A

Joining strings with +

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

What is substring(a

A

b)?

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

What is substring(a)?

A

Extracts characters from index a to the end

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

What does indexOf(char) do?

A

Returns the first index of a character

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

What is a wrapper class?

A

An object version of a primitive (e.g.

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

Can ArrayLists hold primitive types?

A

No

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

What is the difference between Array and ArrayList?

A

Array has fixed size

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

What method returns ArrayList size?

21
Q

What method adds an item to an ArrayList?

A

list.add(item)

22
Q

How do you loop through an ArrayList?

A

Use for loop or enhanced for loop

23
Q

What does list.remove(index) do?

A

Removes the item at the given index

24
Q

What does list.contains(item) do?

A

Returns true if item is found

25
What happens if you access index out of bounds?
IndexOutOfBoundsException
26
What is a constructor?
A special method to initialize objects
27
What is the default constructor?
A no-argument constructor provided by Java if none is written
28
What does this refer to?
The current object
29
What is scope?
The part of the code where a variable is accessible
30
What is a static method?
A method that belongs to the class
31
What is a static variable?
A variable shared by all instances
32
Can static methods use instance variables?
No
33
What is a class?
A blueprint for creating objects
34
What is encapsulation?
Keeping data private and exposing behavior via methods
35
What is a mutator method?
A method that modifies an object’s fields (setter)
36
What is an accessor method?
A method that returns a field’s value (getter)
37
What is casting?
Changing one data type to another
38
What is upcasting?
Assigning a subclass object to a superclass reference
39
What is downcasting?
Casting a superclass reference to a subclass
40
What is polymorphism?
Same method behaves differently depending on object type
41
What is recursion?
A method calling itself to solve a smaller problem
42
How do you stop recursion?
With a base case
43
What causes stack overflow?
Too many recursive calls without reaching base case
44
What does the keyword extends mean?
It’s used to inherit from a superclass
45
What is method overriding?
A subclass providing a new version of a method
46
What is the purpose of @Override?
To show you're overriding a superclass method
47
How do you compare objects logically?
Use .equals()
48
What is DeMorgan’s Law?
!(A && B) is !A || !B, and vice versa
49
What does System.out.println() do?
Prints text to the console followed by a newline