Explain Runnable vs Callable and thread-safe Singleton
Company: Apple
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
## Concurrency & Design Patterns (Java)
1. In Java concurrency, what is the difference between `Runnable` and `Callable`?
- When would you choose one over the other?
- How do you retrieve results and handle exceptions for each?
2. Name one or two design patterns you have used in real projects.
3. For the Singleton pattern, explain what it means for a Singleton to be **thread-safe**.
- Why can a naïve lazy Singleton be unsafe under concurrency?
- Describe at least one correct way to implement a thread-safe Singleton in Java and why it works.
Quick Answer: This question evaluates a candidate's knowledge of Java concurrency and design patterns, specifically distinctions between Runnable and Callable, mechanisms for result retrieval and exception handling, and the principles underlying thread-safe Singleton implementations.