JMM Flashcards

1
Q

How is virtual heap space divided in Java?

A

young gen :
—– eden - object created using new keyword
—– survivor - objects which have survived after java garbage collection from Eden space
old (Tenured) gen - objects which survived after garbage collection from Young Generation
perm gen - metadata of classes (static methods, method names, JVM objects
after java 8 - no more eperm gen => Metaspace (not heap)

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

Metaspace VS Perm gen

A

Metaspace has unlimited default maximum size
Strings used to be kept on the PermGen

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

What difference between float and BigDecimal. How they store the data?

A

BigDecimal - more precision
BigInteger - before point and int after point

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

Java object references

A

Strong - object will not be garbaged
Weak - object will be garbaged if only weak ref available
Soft - object will be garbaged only in case of memory need
Phantom - object will be garbaged only but also put in queue on finalize mehtod (you will be notified when object is garbage collected)

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

deep copy vs shallow copy

A

deep copy - all the objects in the tree are deeply copied, so the copy isn’t dependant on any earlier existing object that might ever change
shallow copy - only copy field values and therefore the copy might be dependant on the original object

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

Disadvantages of setting heap size too high

A

extended caching warmup times,
problems with fragmentation
problems with garbage collection

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

How to force GC be executed?

A

no way to force
calling System.gc() may lead to GC

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

What are memory leaks?

A

objects present in the heap
that are no longer used,
but the garbage collector is unable
to remove them from memory

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

What is variable shadowing

A

a variable in a certain scope
(eg., inside a loop)
has the same name
as a variable declared in outer scope.

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

Types of garbage collectors

A

Serial Garbage Collector - freezing all the application threads while doing garbage collection. uses just a single thread for garbage collection
Parallel Garbage Collector - the default garbage collector of the JVM. uses multiple threads for garbage collection.also freezes all the application threads while performing garbage collection.
CMS Garbage Collector - Concurrent Mark Sweep
freezes only if:
1 - marking in the tenured generation space.
2 - change in heap memory while garbage collection.
uses more CPU, but less stops
G1 Garbage Collector separates the heap memory into regions and does collection within them in parallel.better support heaps larger than 4GB.

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

Default garbage collectors

A

Java 7 - Parallel GC
Java 8 - Parallel GC
Java 9 - G1 GC
Java 10- G1 GC
Java 11- Z GC

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

Strong, Weak, Soft and Phantom References

A

Strong - default. Object not eligible for GC
Weak - object is eligible for GC
Soft - hold object until memory is available
Phantom - object is directly eligible for GC (used to know when an object is removed from memory)

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