ch3 Flashcards

1
Q

Can a numeric literal contain a comma?

A

no

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

Which object does a variable with the value null refer to?

A

To no object at all. There is no null singleton or sth like that in Java.

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

What is the scope of static variables?

A

Created: when the class is loaded. Stay: as long as the class stays in the JVM.

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

What are the possible scopes of a variable?

A

static, instance / member, local / method / stack (temporary, automatic??), block (Remember: no life outside a class)

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

What about the variables of the method which has invoked the current method?

A

They are alive, but out of scope. (They are on the stack, but not in the top étage.)

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

When do instance variables get a value?

A

When the object gets created. If no explicit value is defined, they get initialized with a default value.

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

Is an array an object?

A

Yes.

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

int [] numbers = new int[10]; What does this array contain?

A

10 int elements with the value 0.

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

Do local variables have a default value?

A

No.

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

What happens, if you use a local variable which has not been initialized?

A

compiler error: might not have been initialized

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

Reference variables referring to such objects behave a bit different.

A

String

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

What does variable shadowing mean?

A

Reusing a variable name which has already been declared somewhere else.

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

Which part of the memory is involved in the garbage collection process?

A

heap

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

What does the garbage collection do?

A
  1. search for objects eligible for garbage collection: No live thread can reach it. 2. evtl delete them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Who starts the garbage collection?

A

The JVM. The program code can request a run, but there is no guarantee, it will run indeed.

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

Is the following statement true: If there is a reference to an object, it is not eligible for garbage collection ?

A

No. If the object belongs to an ‘island of isolation’, it is eligible for garbage collection.

17
Q

How can you request a garbage collection?

A

System.gc() Runtime.getRuntime().gc()

18
Q

What is Runtime?

A

a class. It has a single instance (a singleton) for each main program. It provides a mechanism to communicate directly with the JVM.

19
Q

How can you communicate directly with the JVM in your code?

A

via the singleton instance of the Runtime class: Runtime.getRuntime()

20
Q

Can you get an OutOfMemoryException, if the garbage collector has never run?

A

No.

21
Q

What are the drawbacks of the finalize method?

A

It is not deterministic when the garbage collection runs, thus it is not deterministic when finalize runs. If the code in finalize saves the object from deletion, but it gets eligible for garbage collection again later, the finalize method will not run before the actual deletion.