This set of Java Multiple Choice Questions & Answers (MCQs) on “Memory Management”.
1. Which of the following is not a segment of memory in java? Answer: d 2. Does code Segment loads the java code? Answer: a 3. What is JVM? Answer: b 4. Which one of the following is a class loader? Answer: a 5. Which class loader loads jar files from JDK directory? Answer: b 6. Which of the following is not a memory classification in java? Answer: d 7. What is the Java 8 update of PermGen? Answer: c 8. Classes and Methods are stored in which space? Answer: d 9. Where is String Pool stored? Answer: b 10. The same import package/class be called twice in java? Answer: a
a) Stack Segment
b) Heap Segment
c) Code Segment
d) Register Segment
Clarification: There are only 3 types of memory segment. Stack Segment, Heap Segment and Code Segment.
a) True
b) False
Clarification: Code Segment loads compiled java bytecode. Bytecode is platform independent.
a) Bootstrap
b) Interpreter
c) Extension
d) Compiler
Clarification: JVM is Interpreter. It reads .class files which is the byte code generated by compiler line by line and converts it into native OS code.
a) Bootstrap
b) Compiler
c) Heap
d) Interpreter
Clarification: Bootstrap is a class loader. It loads the classes into memory.
a) Bootstrap
b) Extension
c) System
d) Heap
Clarification: Extension loads jar files from lib/ext directory of the JRE. This gives the basic functionality available.
a) Young
b) Old
c) Permanent
d) Temporary
Clarification: Young generation is further classified into Eden space and Survivor space. Old generation is also the tenured space. The permanent generation is the non heap space.
a) Code Cache
b) Tenured Space
c) Metaspace
d) Eden space
Clarification: Metaspace is the replacement of PermGen in Java 8. It is very similar to PermGen except that it resizes itself dynamically. Thus, it is unbounded.
a) Eden space
b) Survivor space
c) Tenured space
d) Permanent space
Clarification: The permanent generation holds objects which JVM finds convenient to have the garbage collector. Objects describing classes and methods, as well as the classes and methods themselves, are a part of Permanent generation.
a) Java Stack
b) Java Heap
c) Permanent Generation
d) Metaspace
Clarification: When a string is created; if the string already exists in the pool, the reference of the existing string will be returned, else a new object is created and its reference is returned.
a) True
b) False
Clarification: We can import the same package or same class multiple times. Neither compiler nor JVM complains will complain about it. JVM will internally load the class only once no matter how many times we import the same class or package.