Advanced Level
51. What is a ClassLoader?
ClassLoader is a part of the JVM that loads classes into memory at runtime. Types: Bootstrap, Extension, System ClassLoader.
52. What are transient variables?
Transient variables are not serialized. They are skipped during object serialization.
53. Explain Java Memory Model.
Defines how threads interact through memory and how changes by one thread become visible to others.
54. What is the difference between volatile and synchronized?
- volatile: Ensures visibility of changes to variables across threads.
- synchronized: Ensures mutual exclusion and visibility.
55. What is the use of the finalize() method?
It is called by the garbage collector before reclaiming an object’s memory. Deprecated in newer versions.
56. What is the difference between stack and heap memory?
Stack memory is used for method execution; heap is used for object storage.
57. What is the marker interface?
An interface with no methods. Example: Serializable.
58. What are annotations in Java?
Metadata that provide information to the compiler and JVM.
59. What is reflection?
Ability to inspect and modify behavior of classes and methods at runtime.
60. What is serialization?
Converting an object into a byte stream.
61. What is deserialization?
Reconstructing an object from a byte stream.
62. What is the difference between deep and shallow copy?
Shallow copy copies references; deep copy copies actual values.
63. What is the difference between composition and aggregation?
Composition implies ownership; aggregation implies a relationship.
64. What are default methods in interfaces?
Methods with default implementation in interfaces (Java 8+).
65. What is method reference in Java 8?
Shorthand for lambda expressions to call a method.
66. What is Optional in Java 8?
A container object which may or may not contain a value.
67. What is the use of static block?
Used to initialize static data. Executed when class is loaded.
68. What is Enum in Java?
A special Java type used to define collections of constants.
69. What is the difference between fail-fast and fail-safe?
Fail-fast throws exception during concurrent modification; fail-safe does not.
70. What are functional interfaces in Java 8?
Interfaces with a single abstract method, e.g., Runnable, Callable.
71. What is the Stream API used for?
Efficiently process sequences of elements (e.g., map, filter, collect).
72. What is a predicate?
A functional interface that represents a boolean-valued function.
73. What is CompletableFuture?
Supports asynchronous programming with non-blocking operations.
74. What are method handles?
Low-level counterparts to reflection for dynamic invocation.
75. What is the use of Java modules (Java 9)?
Provide better modularization with module-info.java
file.
76. What is var keyword in Java 10?
Allows local variable type inference.
77. What is the difference between process and thread?
A process is an independent executing program; a thread is a subset of a process.
78. What is JNI?
Java Native Interface – allows Java to interoperate with native code (C/C++).
79. What are record types in Java?
Introduced in Java 14, concise syntax for data-carrying classes.
80. What is sealed class in Java?
Restricts which classes can extend or implement it.
81. What is pattern matching in Java?
Enables conditionally extracting values from objects more concisely.
82. What is JIT compiler?
Just-In-Time compiler improves performance by compiling bytecode to native machine code at runtime.
83. What are memory leaks in Java?
Objects that are no longer needed but not garbage collected due to lingering references.
84. What is soft reference?
References that are cleared at the discretion of the garbage collector in low memory situations.
85. What are phantom references?
Used to schedule post-mortem cleanup actions.
86. What are weak references?
References that do not prevent their referents from being made finalizable, finalized, and then reclaimed.
87. What are the types of class loaders?
Bootstrap, Extension, System, and custom class loaders.
88. What is the use of assert keyword?
Used for debugging to make assertions in code.
89. What is daemon thread?
A thread that runs in the background and does not prevent JVM from exiting.
90. What is thread priority?
Helps the thread scheduler decide the order of thread execution.
91. What is the difference between notify() and notifyAll()?
notify() wakes up one waiting thread; notifyAll() wakes up all.
92. What is ThreadLocal in Java?
Provides thread-local variables to ensure thread-safety.
93. What is CountDownLatch?
A synchronization aid that allows one or more threads to wait until a set of operations are completed.
94. What is CyclicBarrier?
Allows a set of threads to wait for each other to reach a common barrier point.
95. What is the fork/join framework?
Helps parallelize divide-and-conquer algorithms using work-stealing algorithm.
96. What is a singleton class?
A class with only one instance throughout the application.
97. How to make a class immutable?
Make fields private and final, do not provide setters, and return copies of mutable objects.
98. What are design patterns?
Proven solutions to common software design problems.
99. What is MVC architecture?
Model-View-Controller – separates application logic, UI, and input control.
100. What are SOLID principles?
A set of five principles (SRP, OCP, LSP, ISP, DIP) for object-oriented design.