Java Programs-
1-Real-World JSON Parsing in Java (Complete Guide)
Java RealĀ Question-
- Why does a Spring Boot app consume more memory over time?
- How do you detect bean initialization issues in large applications?
- What happens if @PostConstruct throws an exception?
- Why does @Value sometimes fail to inject properties?
- How does Spring Boot decide the order of auto-configurations?
- What are the risks of enabling too many Actuator endpoints?
- Why does your app behave differently after scaling pods?
- How does Spring Boot handle classpath scanning internally?
- What causes duplicate bean registration in multi-module projects?
- Why does your API return correct data but response time fluctuates?
- How do you control thread usage in Spring Boot applications?
- What happens when application.yml and application.properties both exist?
- Why do custom exception handlers sometimes not trigger?
- How do you handle large payloads without killing performance?
- Why does Hibernate generate unexpected queries?
- How do you debug a deadlock in a Spring Boot service?
- What happens if a BeanFactoryPostProcessor fails?
- How do you avoid startup failure due to missing configs?
- Why does Spring Boot retry DB connections on startup?
- How do you manage feature toggles safely?
- Why does @Cacheable sometimes not cache?
- How does Spring Boot isolate environment-specific configs?
- What causes classloader issues in fat JARs?
- How do you safely reload configs without restarting?
- Why does logging behave differently in prod vs local?
- How do you handle partial failures in dependent services?
- Your Spring Boot app works locally but fails after deployment. What are the first 3 things you check?
- A REST API is slow only in production, not locally. How do you debug it?
- You changed application.properties but changes are not reflecting. Why?
- Your Spring Boot service crashes under high traffic. What could be the reasons?
- Multiple beans of the same type exist and Spring throws an error. How do you fix it?
- You need different configs for dev, test, and prod. How will you design this?
- Your API works fine but returns 401 randomly. What could cause this?
- A database connection pool is getting exhausted. How do you identify and solve it?
- How do you handle API failures when calling another microservice?
- Your application memory usage keeps increasing over time. What do you suspect?
- How do you implement retry logic for failed REST calls?
- You deployed a new version but users still hit the old behavior. Why?
- How do you secure sensitive values like DB passwords in Spring Boot?
- What happens if @Transactional fails midway? How do you verify rollback?
- Your logs are missing in production. Where do you look?
- How do you handle versioning of REST APIs without breaking clients?
- One microservice is down and others are failing. How do you prevent this?
- How do you reduce startup time of a Spring Boot application?
- You need to execute code only once after application startup. How?
- How do you handle long-running background jobs in Spring Boot?
- What are SOLID principles?
- What is OOPs in Java?
- Which Redis version are you currently using?
- What is socket programming in Java?
- What is multithreading?
- When should we override equals() and hashCode()?
- What is immutability in Java?
- What is synchronization in Java?
- What is the Singleton design pattern?
- What are the types of Singleton?
- Where do we use Eager, Lazy, Thread-safe, Double-checked locking, and Enum Singleton?
- If we have multiple catch blocks (one for Exception and one for a custom exception), what will happen?
- Difference between Hashtable and ConcurrentHashMap?
- What is a Consumer functional interface in Java 8?
- What is a Predicate functional interface?
- Purpose of default methods in functional interfaces?
- What is backward compatibility in Java?
- Difference between collect() and reduce() in Stream API?
- If a Kafka producer publishes to a topic, how does a consumer consume data?
- What is CompletableFuture?
- How do you group and sum data using Stream API?
- Can you explain Stream API code line by line?
- How do you make parallel service calls using CompletableFuture?
- How do you handle a shared counter using multiple threads?
- Difference between sleep(), wait(), and notify()?
- What is Thread.yield()?
- Metaspace vs. PermGen: Since Java 8, PermGen is gone. Explain how Metaspace works and how it handles class metadata memory allocation differently from the Heap.
- Weak vs. Soft References: In the context of building a caching library, when would you strictly use SoftReference over WeakReference?
- The volatile Keyword: Does volatile guarantee atomicity? Explain “happens-before” relationship in the context of the Java Memory Model (JMM).
- ThreadLocal Usage: How does ThreadLocal work internally? Why is it a common source of memory leaks in web containers (like Tomcat)?
- CompletableFuture: Scenario: You need to fetch data from 3 different microservices (User, Orders, Payments) asynchronously and combine the result. Write a snippet using CompletableFuture.allOf().
- Deadlock Prevention: Given a banking system where Account A transfers to Account B, write a thread-safe transfer method that prevents deadlock if two threads try to transfer (A->B and B->A) simultaneously.
- N+1 Problem: What is the N+1 select problem in Hibernate/JPA? How do @EntityGraph or JOIN FETCH solve it?
- Optimistic vs. Pessimistic Locking: You are designing a ticket booking system. Which locking strategy would you use for seat selection and why?
- Connection Pooling: What are the critical configuration parameters in HikariCP (e.g., maximumPoolSize, connectionTimeout)?
- Records: How do Java Records differ from standard POJOs regarding immutability and equals()/hashCode() generation?
- Virtual Threads (Project Loom): How do Virtual Threads differ from Platform Threads? Why are they better for I/O-heavy workloads?
- Pattern Matching for switch cases: Explain how pattern matching enhances switch in newer Java versions.
- HashMap collision: Explain the transition from LinkedList to Red-Black Tree in a HashMap bucket (Java 8+). What is the threshold?
- ConcurrentHashMap: How does ConcurrentHashMap achieve thread safety without locking the entire map? Explain the concept of “Segment Locking” (pre-Java 8) vs. CAS + synchronized (Java 8+).
- PriorityQueue: Implement a “Top K Elements” logic using a PriorityQueue. What is the time complexity of insertion and removal?
- Bean Lifecycle: Explain the order of execution: Constructor, Setter, @PostConstruct, BeanPostProcessor.
- Circular Dependencies: How does Spring Boot handle circular dependencies (A depends on B, B depends on A)? What is the difference between constructor injection and setter injection in this context?
- Transactional Propagation: Explain the difference between PROPAGATION_REQUIRED and PROPAGATION_REQUIRES_NEW.