1.
Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called:
Correct Answer
D. D.both methods and classes.
Explanation
Programs designed for maintainability are constructed from small simple pieces or modules. In Java, these modules are called classes. Classes are used to define the structure and behavior of objects in a program. Additionally, methods are also essential components of a program as they contain the code that performs specific tasks or operations. Therefore, both methods and classes play a crucial role in creating maintainable programs in Java.
2.
Which one of these primitive types are unsigned?
Correct Answer
A. Char
Explanation
The correct answer is char because it is the only primitive type that can represent unsigned values. The other options, long, double, and float, are all signed types.
3.
GC is a high priority thread. True/False?
Correct Answer
B. False
Explanation
GC (Garbage Collection) is not a high priority thread. It is a background process that is responsible for reclaiming memory occupied by objects that are no longer in use by the program. The priority of the GC thread is typically lower than that of the application threads, as the main focus is on executing the application logic efficiently. Therefore, the correct answer is False, indicating that GC is not a high priority thread.
4.
Java supports both multi dimension and nested arrays.True/False?
Correct Answer
A. False
Explanation
Java supports multi-dimensional arrays, which are arrays of arrays. This means that an array in Java can have multiple dimensions, such as a 2-dimensional array or a 3-dimensional array. However, Java does not support nested arrays, which are arrays that are elements of another array. In other words, Java does not allow arrays to be nested inside each other. Therefore, the correct answer is False.
5.
If an object becomes eligible for Garbage Collection and its finalize() method has been called and inside this method the object becomes accessible by a live thread of execution and is not garbage collected. Later at some point the same object becomes eligible for Garbage collection, will the finalize() method be called again?
Correct Answer
B. False
Explanation
If an object becomes eligible for Garbage Collection and its finalize() method has been called and inside this method the object becomes accessible by a live thread of execution and is not garbage collected, the finalize() method will not be called again when the object becomes eligible for garbage collection again. Once the finalize() method has been called and the object has been determined to be not garbage collected, it will not be called again in future garbage collection cycles.
6.
public class GCTest3 { GCTest3 g; public static void main(String [] str){ GCTest3 gc1 = new GCTest3(); GCTest3 gc2 = new GCTest3(); gc1.g = gc2; //gc1 refers to gc2 gc2.g = gc1; //gc2 refers to gc1 gc1 = null; gc2 = null; } } Which Object is eligible for garbage collection?
Correct Answer
C. Gc1 and gc2
Explanation
The objects gc1 and gc2 are eligible for garbage collection because they are no longer referenced by any variables in the program.
7.
Why is Java Architectural Neutral?
Correct Answer
C. Because it is Platform Independent
Explanation
Java is considered architectural neutral because it is platform independent. This means that Java programs can run on any operating system or hardware platform without the need for any modifications. Java achieves this through the use of the Java Virtual Machine (JVM), which acts as an intermediary between the Java code and the underlying system. The JVM interprets the Java bytecode and converts it into machine code that can be executed by the specific operating system and hardware. This allows Java programs to be written once and run anywhere, making it highly portable and adaptable to different environments.
8.
What is "Stop the World"?
Correct Answer
A. When GC occurs ,the thread where the collection occures should be interrupted.
Explanation
"Stop the World" refers to a pause in the execution of an application when garbage collection (GC) occurs. During GC, the thread responsible for garbage collection interrupts the execution of the application in order to reclaim memory occupied by objects that are no longer needed. This interruption is necessary to ensure the consistency of the memory state during garbage collection. Therefore, the correct answer is "When GC occurs, the thread where the collection occurs should be interrupted."
9.
-XX:NewRatio=3: ,what does this mean?
Correct Answer
B. Set the size of the Young Generation as a ratio of the size of the Old Generation
Explanation
This option suggests that the XX:NewRatio parameter is used to set the size of the Young Generation in relation to the size of the Old Generation. It implies that by adjusting this ratio, one can control the memory allocation for the different generations in Java garbage collection.
10.
How Can you tell the system to perform a garbage collection?
Correct Answer
D. System.gc() and RunTime.gc()
Explanation
The correct answer is system.gc() and RunTime.gc(). These two methods can be used to suggest the system to perform a garbage collection. The system.gc() method is a static method of the System class that suggests the JVM to perform garbage collection. The RunTime.gc() method is a method of the Runtime class that suggests the JVM to run the garbage collector. Both methods can be used to suggest the JVM to perform garbage collection, although it is not guaranteed that the garbage collection will actually occur immediately.