Java Performance Optimization MCQs: Enhancing Java Application Efficiency
Master the fundamentals of Java performance optimization with these 30 MCQs. Dive into memory management, garbage collection, profiling, JVM tuning, and multi-threaded application optimization. Improve your Java application efficiency by understanding core optimization techniques.
1. Which part of the JVM is responsible for managing memory allocation and deallocation?
2. In Java, which of the following is a primary goal of garbage collection?
3. What does the term “heap memory” refer to in Java?
4. Which garbage collection algorithm is specifically designed to reduce latency in Java?
5. Which JVM option is used to specify the maximum heap size?
6. What is the purpose of the JVisualVM tool in Java?
7. Which of the following is used to perform memory profiling in Java applications?
8. Which memory space stores objects that are short-lived and eligible for garbage collection soon after creation?
9. What does the jstat tool primarily monitor?
10. Which JVM tuning flag is used to set the initial heap size in Java?
11. Which Java tool is often used to monitor live threads and memory usage?
12. Which garbage collector is considered ideal for applications that require low pause times?
13. What is the purpose of the jmap command?
14. How does the Just-In-Time (JIT) compiler help in improving performance?
15. What is “thread contention” in the context of multi-threaded applications?
16. Which JVM option allows you to enable parallel garbage collection?
17. In Java, which tool is commonly used for profiling CPU and memory usage in a production environment?
18. Which type of garbage collection is specifically designed for applications that allocate and deallocate a large number of short-lived objects?
19. What is the primary purpose of the jstack command?
20. What is the impact of excessive garbage collection in a Java application?
21. Which of the following techniques is used to reduce memory fragmentation in Java?
22. In Java NIO, which buffer type is recommended to enhance performance with large I/O operations?
23. Which garbage collection algorithm is used by default in Java 8?
24. Which of the following allows Java to efficiently manage memory for multi-threaded applications?
25. What is the purpose of the -XX:+UseConcMarkSweepGC flag?
26. How does the WeakReference class in Java help in memory management?
27. Which type of thread pool is recommended for CPU-intensive tasks to maximize efficiency?
28. In Java, how does memory leak occur?
29. What is “lock contention” in the context of optimizing multi-threaded applications?
30. Which of the following strategies can improve Java application performance in multi-threaded scenarios?
| QNo | Answer |
|---|---|
| 1 | B. Garbage Collector |
| 2 | B. Free up heap memory |
| 3 | C. Memory for dynamic allocation of objects |
| 4 | B. CMS (Concurrent Mark-Sweep) |
| 5 | B. -Xmx |
| 6 | C. To profile applications and monitor JVM |
| 7 | D. Memory Profiler |
| 8 | A. Eden Space |
| 9 | B. Heap memory usage and garbage collection statistics |
| 10 | A. -Xms |
| 11 | B. JConsole |
| 12 | D. ZGC |
| 13 | A. To display heap memory usage details |
| 14 | B. By compiling code at runtime to native code |
| 15 | B. The process where threads compete for shared resources |
| 16 | A. -XX:+UseParallelGC |
| 17 | B. JProfiler |
| 18 | D. Scavenge GC |
| 19 | B. To print stack traces of threads |
| 20 | C. Increased application latency due to frequent pauses |
| 21 | C. Compaction |
| 22 | A. ByteBuffer |
| 23 | D. Parallel GC |
| 24 | B. Thread Local Storage |
| 25 | A. To enable concurrent garbage collection |
| 26 | A. It holds references that allow garbage collection when memory is needed |
| 27 | A. Fixed Thread Pool |
| 28 | B. By not releasing memory occupied by unreachable objects |
| 29 | B. Multiple threads trying to acquire the same lock |
| 30 | B. Reducing the number of synchronized methods |