The document is a comprehensive guide for Java interviews, specifically targeting candidates with over six years of experience. It includes over 100 questions across various sections such as Core Java, Spring Boot, Java 8 Stream API, and Java Multithreading & Concurrency, along with practical coding exercises and advanced concepts. Additionally, it addresses real-world debugging, problem-solving techniques, and interview trick questions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views4 pages
Java Spring Interview Guide
The document is a comprehensive guide for Java interviews, specifically targeting candidates with over six years of experience. It includes over 100 questions across various sections such as Core Java, Spring Boot, Java 8 Stream API, and Java Multithreading & Concurrency, along with practical coding exercises and advanced concepts. Additionally, it addresses real-world debugging, problem-solving techniques, and interview trick questions.
🔹 Thread Lifecycle & Basics 1. What is a thread in Java? 2. Explain the thread lifecycle. 3. How do you create a thread in Java? 4. Difference between Runnable and Thread class? 5. Can we start a thread twice? Why not? 6. What happens if we call run() instead of start()? 7. What is the role of the Thread.sleep() method? 8. How to handle interruption in threads? 9. How to make a thread wait for another thread to finish? 10. What is a daemon thread? 🔹 Synchronization and Locks 11. What is thread safety? 12. Explain synchronization in Java. 13. Difference between synchronized method and synchronized block? 14. Can a static method be synchronized? 15. What is a deadlock? How to detect and prevent it? 16. What is a livelock? 17. What is starvation in multithreading? 18. How to avoid deadlock in Java? 19. Example of nested locks causing deadlock? 20. Difference between wait() and sleep()? 🔹 Concurrency Utilities (Executors, Future, Locks, etc.) 21. What is the Executor framework? 22. Difference between ExecutorService and ThreadPoolExecutor? 23. What is Callable and Future? 24. How to cancel a task in a thread pool? 25. What is CountDownLatch? Provide use-case. 26. What is CyclicBarrier? 27. What is Semaphore? 28. What is ReentrantLock and how is it used? 29. Difference between ReentrantLock and synchronized? 30. What is ReadWriteLock? 🔹 Thread Pools and Scheduled Execution 31. How to create a fixed thread pool? 32. How to schedule a task with delay? 33. What happens if thread pool is exhausted? 34. What is ThreadPoolExecutor rejection policy? 35. Difference between newFixedThreadPool() and newCachedThreadPool()? 36. What is a work-stealing pool? 37. What is the ForkJoinPool in Java? 38. Use of invokeAll() and invokeAny() methods? 39. How to shut down an ExecutorService? 40. What is graceful vs. immediate shutdown? 🔹 Inter-thread Communication 41. What is producer-consumer problem? 42. How do threads communicate in Java? 43. Use of wait(), notify() and notifyAll()? 44. Example of using wait/notify for producer-consumer? 45. What is spurious wakeup? 46. What is volatile keyword? 47. When to use AtomicInteger? 48. Difference between volatile and synchronized? 49. What is memory consistency error? 50. What are happens-before relationships? 🔹 Practical Coding Exercises 51. Write a program that prints even and odd numbers using two threads. 52. Implement a custom blocking queue using wait/notify. 53. Simulate a producer-consumer using BlockingQueue. 54. Write a multi-threaded file downloader. 55. Create a ThreadPoolExecutor with custom settings. 56. Implement deadlock and solve it. 57. Write a task scheduler with fixed delay. 58. Use Semaphore to control access to a resource. 59. Demonstrate inter-thread communication using CountDownLatch. 60. Create a bank transaction system with thread safety. 🔹 Real-world Debugging & Problem Solving 61. How do you debug a deadlock in production? 62. What tools are used to analyze thread dumps? 63. How do you fix CPU spike issues caused by threading? 64. How to profile a Java application’s threads? 65. What are thread dump and heap dump? 66. When should you use parallel streams? 67. How to reduce contention in multi-threaded apps? 68. How to increase throughput in concurrent programs? 69. Use-case of bounded thread pools in microservices? 70. How to ensure atomicity without locks? 🔹 Advanced Concepts 71. What is ThreadLocal? 72. Use-case for ThreadLocal? 73. Difference between ThreadLocal and global variables? 74. What is a ThreadGroup? 75. What is ThreadFactory? 76. What is false sharing in concurrency? 77. What is Compare-And-Swap (CAS)? 78. What is lock-free programming? 79. What is contention and how to avoid it? 80. Explain Phaser in Java. 🔹 Microservices & Real-World Integration 81. How does multithreading affect REST APIs? 82. Should we use thread pools in controller layer? 83. When to use async controllers in Spring Boot? 84. Impact of thread pools in reactive programming? 85. What is Netty and how does it differ from traditional thread model? 86. What is the impact of I/O-bound vs CPU-bound tasks? 87. What is backpressure? 88. How to manage memory leak in thread-heavy applications? 89. How to debug thread starvation in a web application? 90. What profiling tools do you use for concurrency? 🔹 Interview Trick Questions 91. Can two threads execute static and non-static synchronized methods of the same object? 92. Can thread priorities be used to enforce execution order? 93. What happens if a thread is waiting on an object and no one notifies? 94. Why are volatile variables not enough for atomicity? 95. Can synchronized block throw exception? 96. Can you lock on a String object? 97. How is synchronized handled internally in JVM? 98. Can a thread block another thread from being scheduled? 99. Difference between thread contention and deadlock? 100. Can Java guarantee fairness in multithreaded execution? 101. What happens when you forget to release a lock? ✅ All questions include explanations or code examples.
🔜 Next: I’ll compile 100+ real-world scenario-based Java + Spring
debugging and optimization questions (with detailed step-by-step answers).