Java Interview Questions – Microservices Architecture

Q1: [Amazon] How do you optimize Java code for performance?

Answer:

  • Use StringBuilder instead of String + String.
  • Avoid creating unnecessary objects.
  • Use efficient data structures (HashMap vs TreeMap).

Q2: [Google] How do you profile a Java application?

Answer: Use VisualVM, JProfiler, YourKit.


Q3: [Microsoft] What is JVM tuning?

Answer: Adjusting heap size, GC algorithms, thread pools for better performance.


Q4: [Netflix] What is the impact of using final keyword?

Answer: Improves performance and security by preventing modification.


Q5: [Facebook] How do you reduce memory leaks in Java?

Answer:

  • Avoid unnecessary object references.
  • Use WeakReference for large objects.
  • Close resources (try-with-resources).

Q6: [Oracle] What is a thread dump in Java?

Answer: A thread dump captures all active threads for debugging performance issues.


Q7: [Uber] What is a heap dump in Java?

Answer: A heap dump captures JVM memory usage for debugging memory leaks.


Q8: [Deloitte] What are common performance bottlenecks in Java?

Answer:

  • Excessive GC pauses
  • Unoptimized database queries
  • Blocking I/O operations

Q9: [JP Morgan] What is the impact of using too many threads in Java?

Answer: Can cause CPU contention, high memory usage, and poor performance.


Q10: [Goldman Sachs] What are the benefits of using a CDN with Java applications?

Answer: Reduces latency and load times for static assets (CSS, JS, images).