Java Programming
June 7, 2025 at 07:09 AM
💻 *Advanced Java Interview Questions:*
*1. What is the difference between a process and a thread?*
- _Process:_ An independent execution unit with its own memory.
- _Thread:_ A smaller execution unit within a process that shares memory resources.
*2. What is the 'volatile' keyword in Java?*
- It ensures that a variable’s value is always read from main memory, preventing thread caching issues.
*3. Explain 'synchronized' in Java.*
- It prevents multiple threads from executing a block of code at the same time, avoiding race conditions.
*4. What is the difference between shallow copy and deep copy?*
- _Shallow copy:_ Copies references, not actual objects.
- _Deep copy:_ Creates new instances of objects instead of copying references.
*5. What is Garbage Collection in Java?*
- The JVM automatically removes unused objects to free memory.
*6. How does Java handle memory management?*
- Java uses automatic garbage collection and a heap-based memory allocation system.
*7. What are the types of garbage collectors in Java?*
- _Serial GC_
- _Parallel GC_
- _CMS (Concurrent Mark-Sweep) GC_
- _G1 (Garbage First) GC_
*8. What is the difference between a HashSet and TreeSet?*
- _HashSet:_ Unordered, uses hashing for fast access.
- _TreeSet:_ Ordered, implements a balanced tree structure.
*9. What are Java design patterns?*
- Common solutions to recurring software design problems (e.g., Singleton, Factory, Observer).
*10. Explain the difference between Callable and Runnable.*
- _Runnable:_ Does not return a value, used with threads.
- _Callable:_ Returns a value and can throw exceptions.
👉 *React ❤️ for more!*
❤️
👍
❤
🇮🇳
💋
😮
👯♀️
🙏
🫶
66