Core Java (General Questions)
- Explain how you would handle a scenario where a method needs to be thread-safe but also efficient.
- How would you implement a custom sorting algorithm without using Java’s built-in sort methods?
- How would you design an immutable class in Java? What scenarios would require immutability?
- Given two unsorted arrays, how would you find the common elements between them?
- If you encounter a
NullPointerException
in production, how would you resolve it?
- How would you use
Optional
to avoid NullPointerException
and handle absent values?
- Describe how you would optimize memory usage in a Java application.
- How would you avoid deadlocks in a multi-threaded application?
- Describe a situation where you used
volatile
and synchronized
in your project.
- How would you improve the performance of an application with slow database queries?
- How would you use Java Streams to manipulate and filter large datasets efficiently?
- How would you handle a
ClassNotFoundException
or NoClassDefFoundError
in Java?
- What steps would you take to identify and resolve a memory leak in a Java application?
- How would you manually trigger garbage collection in Java, and when would it be appropriate to do so?
- Describe how you would handle a race condition in a multi-threaded application.
- How would you write a program to efficiently read and write a large file in chunks, rather than loading the entire file into memory?
- How would you handle an OutOfMemoryError in Java, and how can you prevent such issues from happening?
- How would you handle backward compatibility in a serialized Java object when the class structure changes over time?