Java Programming Multiple Choice Questions - Garbage Collection
This section focuses on the "Garbage Collection" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1.What allows the programmer to destroy an object x?
Explanation: When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.
2. Which statement is true?
Explanation:C See the note above on Islands of Isolation (An object is eligible for garbage collection when no live thread can access it - even though there might be references to it).
B is wrong. "Never again be used" does not mean that there are no more references to the object.
A is wrong. Even though Java applications can run out of memory there another answer supplied that is more right.
3. Which of the below is not a memory leak solution?
Explanation:Process restart is not a permanent fix to memory leak problem. The problem will resurge again..
4. Which of the below is not a Java Profiler?
Explanation:Memory leak is like holding a strong reference to an object although it would never be needed anymore. Objects that are reachable but not live are considered memory leaks. Various tools help us to identify memory leaks.
5. Which statement is true?
Explanation: All objects are placed in the garbage collectible heap.
6. How to get prints of shared object memory maps or heap memory maps for a given process?
Explanation: We can use jmap as jmap -J-d64 -heap pid.
7. What is -Xms and -Xmx while starting jvm?
Explanation:JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. java -Xmx2048m -Xms256m.
8. Which of the following has the highest memory requirement?
Explanation:JVM is the super set which contains heap, stack, objects, pointers, etc.
9. Where is a new object allocated memory?
Explanation:A new object is always created in young space. Once young space is full, a special young collection is run where objects which have lived long enough are moved to old space and memory is freed up in young space for new objects..
10.Which of the following is a garbage collection technique?
Explanation:A mark and sweep garbage collection consists of two phases, the mark phase and the sweep phase. I mark phase all the objects reachable by java threads, native handles and other root sources are marked alive and others are garbage. In sweep phase, the heap is traversed to find gaps between live objects and the gaps are marked free list used for allocating memory to new objects.
Also check :