Java interview questions:
Core Java Questions⇒
What are the features of Java 8?
What is the Optional class?
What is a Functional Interface?
What is a Lambda expression and its syntax?
Create a Functional Interface and implement it
What is Serialization? What is serialVersionUID?
Internal working of HashMap
What is Multithreading? Different thread states?
What is Deadlock and how to prevent it?
Stream APl⇒
Find alist of names starting with the letter 'A.
Find the highest salaried e employee from al list.
t
Return a Map with ID as key and salary as value from list
of employees
Microservices⇒
What are the components of Microservices?
What is an API Gateway?
What is Service Discovery?
What is the use of a Circuit Breaker?
Best way to store credentials needed by multiple services?
How to log a response body along with HTTP status code
after every API call?
Spring boot:
1. What are the advantages of using Spring Boot?ll
2. What are the Spring Boot key components?
3. Why Spring Boot over Spring?
4. What is the starter dependency of the Spring Boot
module?
5. How does Spring Boot work?
6. What does the @SpringBootApplication annotation do
internally?
7. What is the purpose of using @ComponentScan in the
class files
8. How does a Spring Boot application get started?
9. What are the most common Spring Boot CLI
commands?
10.V What is Spring Boot CLI & what. are itS benefits?
11.W
it
What is Spring Initializer?
12. What are starter dependencies?
13. What is the difference between @RestController and
@Controller in Spring Boot?
14. What is an loC container?
15. Describe the flow of HT TPS requests through the
Spring Boot application.
16. What is the difference between @RequestMapping
and @GetMapping?
17. What is the use of Profiles in Spring Boot?
18. What is Spring Actuator? What are its advantages?
19. How to enable Actuator in a Spring Boot application?
20. What are the actuator-provided endpoints used for
onitoring the Spring Boot application?
21. How to get the list of all the beans in your Spring Boot
application?
22. How to check the environment properties in your
Spring Boot application?
23. How to enable debugging logs in the Spring Boot
application?
24. Where do we define properties in the Spring application?
25. What is Dependency Injection?
26. Explain the @RestController annotation in Spring Boot.
27. How to disable a specific auto-configuration class?
28. Can we disable the default web server in a Spring Boot
application?
29. Can we override or replace the embedded Tomcat
server in Spring Boot?
30. What is the default port of Tomcat in Spring Boot?
31. Is it possible to change the port of the embedded
Tomcat server in Spring Boot?
32. Can We create a non-web application in Spring Boot?
33. What is Spring Boot dependency management?
34. What are the basic annotations that Spring Boot
offers?
Java concurrency:
Thread Joining 8
Using [Link]@" allows one thread to wait for the
completion of another, which is helpful for sequencing
tasks or ensuring dependencies are respected.
How Threads Signal Completion
Threads don't "notify" completion explicitly, but their
completion can be tracked using:
`join0
- "[Link](" (when using 'ExecutorService) I
-Shared variables (careful with visibility P
synchronization!)
wait0 vs sleep0
- `sleep(` pauses the current thread for a fixed time but
holds the lock (ifany)
wait(` pauses the thread until notified and releases the
lock - essential for inter-thread communication
.Y Synchronized Method Vs Synchronized Block
- Synchronized method: Locks the entire method (less
flexible)
D
Synchronized block: Locks only the specific part of code
that needs protection (more efficient)
ExecutorService
A cleaner way to manage thread pools and task execution.
It abstracts thread creation and offers better control and
scalability.
Callable VS Runnable
⁃ "Runnable`: No return value, can't throw checked
exceptions
- `Callable<V>`: Returns a result and can throw checked
exceptions-ideal for tasks with results
Java :
What is a marker interface?
Why use a marker interface?
When to use interface and abstract class?
What is the use of constructor in Java?
What is static method?
Can we use static method in constructor?
What is the contract between hashcode and equals
methods?
What is failfast iteration and how will e resolve?
Difference between map vs flatmap in Java?
What are sealed classes?
What are Spring Boot advantages?
What is application context?
What are the scope in spring?
Difference between prototype and request scope?
What are components of Kafka?
How to handle if Kafka keeps on?
How to handle dependency injection in Spring Boot?
What is Authentication & Authorization?
What are the error codes used?
What is 404, 402, 502, 503, 401 error codes?
How to handle "Not Found" error?
What is the issue behind "Bad Request" error?
What is @Mockito?
When and when not to use @Mock?
What is Error and Exception?
How to handle OutOfMemoryException?
How to handle "Service Not Found" error even when the
beans are properly registered?
How to debug in local and remote repository?
How to create pipeline and deploy in Jenkins?
What happens when there is a collision in HashMap?
What is hashcode( and equals( method and its uses?
Whatis multithreading? How multithreading is
implemented in my project?
What is NullPointerException? and How it is handled?
Is server port and debug port same?
DB @Bean and @Autowired?
What is Functionallnterface?
How to handle Gateway Timeout and Service Unavailable
error in project?
Interviewer: How do you create a Singleton class?
Your Answer:
To create a Singleton:
1 Imake the constructor private so that no one can
create an object from outside.
2 Icreate a private static variable to hold the single
object.
3 I create a public static method that returns the object.
Inside this method, I check if the object is nul,then create
t.
Example Code (explain briefly):
public class MySingleton f
private static MySingleton instance,;
private MySingleton()// Step 1
public static MySingleton getlnstance0 f// Step 3
if (fnstance == null) (
instance = new MySingleton(; / Step 2
return instance;
Interviewer: ls it thread-safe?
Your Answer:
= No, this basic version is not thread-safe. lf two threads
access it at the same time, they can create two objects.
⁃ To make it thread-safe, I can use the synchronized
keyword in the getInstance( method.
Thread-safe version:
public static synchronized MySingleton getinstance( f
if (instance
puIl)
instance = new MySingleton();
}
Return instance
Useful links:
Singleton;
[Link]
y-7350501891086155777-3khE?utm_source=social_share_send&utm_medium=android_app&r
cm=ACoAADFv5boBZi5nP_Z17f4Lcl3acvhOzuKImRw&utm_campaign=copy_link
[Link]
46019504918847488-nq1c?utm_source=share&utm_medium=member_android&rcm=ACoAAD
Fv5boBZi5nP_Z17f4Lcl3acvhOzuKImRw
[Link]
s-real-activity-7346960511852240897-Jr82?utm_source=social_share_send&utm_medium=and
roid_app&rcm=ACoAADFv5boBZi5nP_Z17f4Lcl3acvhOzuKImRw&utm_campaign=copy_link
[Link]
348782211510296577-K9rI?utm_source=social_share_send&utm_medium=android_app&rcm=
ACoAADFv5boBZi5nP_Z17f4Lcl3acvhOzuKImRw&utm_campaign=copy_link