Introduction
This summary covers core topics commonly asked in Java backend interviews, illustrated through a detailed Q&A format. It addresses thread management, exception handling, Spring Boot, and microservices, concluding with a practical Java 8 programming example. For a broader overview of Java fundamentals, see Java Programming: A Comprehensive Guide to Understanding Java and Its Concepts.
Java Threading Concepts
Ways to Create Threads
- Extend
Threadclass and overriderun() - Implement
Runnableinterface - Use the Executor framework (recommended for multiple threads)
Deadlocks and Prevention
- Deadlock occurs when threads wait indefinitely on each other's resources.
- Prevent by consistent lock ordering, using
tryLock(), and minimizing synchronized blocks.
Thread States
- New (created but not started)
- Runnable (ready to run or running)
- Blocked/Waiting (waiting to acquire a lock or waiting for signal)
- Timed Waiting (waiting for a specified time)
- Terminated (completed execution)
- Note: Threads cannot be restarted once terminated; new thread instances are needed.
Exception Handling in Java
throwis used to explicitly throw an exception.throwsdeclares exceptions a method might throw.- Exceptions: Checked (compile-time checked) and unchecked (runtime exceptions like
NullPointerException).
Try-With-Resources
- Allows automatic resource management.
- Resources (e.g.,
BufferedReader) implementingAutoCloseableare closed automatically at block end.
Object Comparison
==compares object references.equals()compares object content.- Example with strings:
String str1 = "ABC"; String str2 = new String("ABC"); str1 == str2 // false str1.equals(str2) // true
Abstract Class vs Interface
- Abstract class: can have abstract and concrete methods; allows variables.
- Interface: primarily abstract methods; since Java 8, may include default and static methods.
- A class can extend only one abstract class but implement multiple interfaces.
Spring Boot Fundamentals
Dependency Injection (DI)
- DI injects dependencies into a class instead of creating them internally.
- Supported via annotations like
@Autowiredand@Bean. - For detailed common Spring Boot interview topics, refer to Top 50 Spring Boot Interview Questions and Answers Explained.
Circular Dependencies
- Handled using proxies or
@Lazyannotation to defer bean initialization.
Repository Interfaces
CrudRepository: basic CRUD operations.JpaRepository: extendsCrudRepository, adds pagination and more features.- Preference depends on use case; e.g.,
JpaRepositoryfor pagination support.
Performance Tuning Strategies
- Use caching to reduce database calls.
- Apply indexing on frequently queried columns.
- Monitor with Spring Actuator.
- Implement asynchronous processing with
@Async.
Microservices Architecture
Monolith to Microservices Migration Steps
- Identify domain boundaries and functional modules.
- Develop independent services for each module.
- Define service communication:
- Synchronous (REST APIs)
- Asynchronous (message brokers like Kafka)
- Use API Gateway as a unified entry point.
- Implement service discovery (e.g., Eureka).
- Setup CI/CD pipelines for automated deployment.
- Write unit and integration tests; automate regression testing.
Communication Patterns
- Synchronous: client waits for response before continuing.
- Asynchronous: client sends requests without waiting; consumers process messages independently.
Java 8 Coding Example: Unique Sorted Words
- Input: A sentence string.
- Process:
- Split sentence into words.
- Convert to lowercase.
- Extract distinct words.
- Sort alphabetically.
- Collect into a list.
List<String> uniqueWords = Arrays.stream(sentence.split(" "))
.map(String::toLowerCase)
.distinct()
.sorted()
.collect(Collectors.toList());
uniqueWords.forEach(System.out::println);
- Output: List of unique words sorted alphabetically, e.g., [and, fun, is, java, powerful].
For foundational coding exercises related to Java basics, consider Java Basics: Outputs, Variables, and User Input Explained.
Conclusion
This overview equips Java developers with concise explanations of core backend concepts, practical coding techniques, and strategic insights for interviews and real-world projects. To deepen interview preparation, explore Top 10 Spring Boot Interview Questions with Answers & Examples.
uh hello good evening how are you hi good evening I'm good thank you how are you I'm also doing well thank
you so this this call is regarding your Java interview and this is going to be your uh Java backend interview so do you
like to introduce yourself about technology stack and what kind of uh domains you have worked
on uh yes so I am currently uh having around 4.5 years of experience working as a Java developer so I know
Java writing Rest API is using spring boot uh basics of micros bed architecture and uh from database side I
know SQL and Oracle as a database and apart from this I have a little idea about UI Technologies as
well like angular HTML CSS but that is my secondary skill my primary skill is Ja so that's it from my side
okay great all right and uh which version of java are you currently working
on uh yes we are currently using jdk8 but trying to upgrade it to jdk 17 all right nice okay so if I ask you
to rate yourself in C Java out of five how much would you rate yourself okay so out of five I'll will
try to answer at least uh four questions so if you ask me to WR I can WR myself around
four okay great all right so let's get started what are the different ways to create threads do you have any idea
around this uh yes so we can create the thread in two or three ways uh first way is
like we can extend the thread class and then override the run method so that will give me a thread object then I can
use runable interface so my class should Implement that reenable interface and then I'll be able to implement or create
a thread and there is a executor framework okay so that can also use to create the thread so these are the three
ways which can be used to create threads in Java okay all right and what is the recommended way of creating
threats so you can uh if there is a need to create multiple threads then you can go with executor framework otherwise if
you want to create a single thread and your class is not extending any other class then you can go with thread class
otherwise uh it is simply go and Implement theal inter renable interface all right great okay uh so let's uh just
go one step further uh do you know what is deadlock and how can uh we avoid it uh yes so uh Deadlock occurs when two
or more threads are waiting on each other's resources okay so let us consider I have uh one thre thread one
is holding a resource one and uh thread two is waiting for resource to but that is hold by another thread so this
situation is called as deadlock now we can avoid this by different ways like uh we can use locks in a consistent order
or uh we can use uh trylock mechanisms like lock. TR function which is available in
java.util concurrent package or even we can minimize the synchronized code blocks so that will help me to reduce
the deadlock conditions great great uh what are the common thread States or what are the
different states in which the thread can be present uh yes so there are different
stats uh through which a thread can go uh so when we create a thread but that thread is not at started so we call it
as uh in the thread is in New State now when the thread starts running or it is ready to run then we call that state as
runable state then a blocked state or we can call it as a wetting state so thread is actually uh in this set the thread is
actually waiting to acquire the lock then we have another like waiting or time waiting uh state so where the
thread is waiting for a specific time and when we uh uh finish or the thread finish its task so basically it
completes uh the task execution then that thread goes into terminated State okay can I uh can I uh once thread is
terminated can I restart the thread uh once a thread is terminated uh I think you should be able to restart
that thread but that will be a new thread okay all right all right okay now uh let's let's try to go towards
exception uh what is the difference between and throws do you know about it uh yes so throw and throws keyword
are related to exception handling in Java so basically throw is used to explicitly throw an exception in the
code for example I want to throw an exception when I don't see the information which is uh let us consider
I'm trying to find an employee and that employee is not available so I can throw employee not found exception so I can
use throw keyword to throw this exception and throws is used with your method signature this indicates that the
method uh May throw an exception so this is the use of uh throw ski word okay okay all right and uh what
are the different types of exceptions in Java we have a different types of exceptions like checked exception and
unchecked exceptions so checked exceptions are the exceptions which are checked by your compiler at compile time
and unchecked exceptions are basically runtime exceptions which occurs when your code is running or this is uh not
checked by your compiler for example null pointer exception or array index out of bound exception so these are the
runtime exceptions which occurs at a run time okay great um there is something called as TR with resource what what do
you mean by TR with resource uh try with a resource means we are writing a resource along with your tribe
block for example uh uh let us consider there is a file okay and I want to create an object of buffer reader so
instead of creating separate object of buffer reader inside triblock or outside Tri block what I can do I can use the
buffer dater object along with a TR statement so what will happen I don't need to close that resource explicitly
so when you use try with resource the resource will be automatically closed once uh the uh execution or uh use of
that resource is completed so you don't need to uh explicitly close that resource so that is a try with resource
and the one more thing related to it is like the uh as I said I need a buffer rer res so that Bufford reader
should be implementing that autoc closable interface that is the requirement to use or try with
resource excellent in Java excellent excellent nice so uh let's try to um what is the difference between uh equal
to equal to operator and equals method these are the two ways to compare the objects so what what is the difference
between them uh so equal equal operator is used to compare the references for the
objects okay and equals method is used to check the content of the object for example uh now let me uh create two
strings uh string St str1 equal to uh ABC and string St str2 is equal to new string of ABC in this case if I use St
R1 equal equal to St str2 in this case I'll get uh the response as false because this St str1 and S str2 are
referencing to two different uh instances and if I use St str1 do equals St str2 then I'll get the response as
true because Str str1 is holding the string content as ABC and Str str2 is also hold in string as AB so both ABC
and ABC are same so I'll get uh true as a uh return value or the response okay okay and uh what about
what is the difference between abstract class and interface and when to go for which one do do you have any idea on
this uh so basically abstract class uh can have methods as well as variables but in interface we have only abstract
methods so in abstract class you can have abstract as well as non-abstract methods but in interface till Java we
have only abstract methods in Java we have static and default methods as well where we can provide the implementation
of uh the methods and the other thing is like uh a class can extend only one abstract class but it can Implement
multiple interfaces so interface can extend the interface but it cannot implement the
interface okay all right nice so these are the two differences okay right uh now let's try
to move towards uh spring boot questions okay how much would you rate yourself in Spring boot out of
five uh so even in Spring boot I will try to answer at least four questions out of five so I can rate around four
great great uh there's a basic fundamental what is the dependency injection and how does
spring wot support it okay so dependency injection is basically a design pattern where
dependencies are injected into a class instead of being created inside it okay so what I'm going to do is I'm going to
create uh the dependency instead of creating the dependencies it will be injected by this dependency injection
pattern now uh this spring boot uh supports this dependency injection using annotations like add direct aut or addir
bin where uh the bins will be injected by using these annotations for example let us consider I need a bean of type
employee so I can use object of employee along with atwi I'll get the instance or being of uh type
employee okay all right all right and uh uh do you know circular dependen dependencies and how does uh spring
handle it spring boot handle it uh yeah so circular dependencies can be handled using proxy
objects or you can use the annotations like add direct a lazy annotation to load the dependencies lazily so
developers actually uh can avoid these circular dependencies by refactoring the code or we can use constru injection
with a direct lazy annotation that will load the beans lazily so you can avoid the circular
dependency great great okay so now uh in Spring boot there are different types of repositories oh for example cred
repository and jpa repository what is the difference between cred repository and GP
repository uh so C repository as it is name suggest uh it is useful for performing CED operations like create
read update and a delete operations whereas JPI repository is built on top of BL repository where it provides the
operations which are available in C repository with additional attributes or uh functions like pation so you can have
uh I can say that there are uh more features which are available in jpa repository okay and in your project uh
what kind of repository are you using uh we are using JP repository because we need to the results as well
as we need pation as well and that is supported by JP repository so we use the JP
repository okay okay nice nice so um what are some of the best practices for tuning the performance of your
springboard application I have an application in I want to tune the performance of that application how
would you go about this okay uh so to tune the performance or to improve the application
performance I can use uh caching that is one way so what will happen uh caching means basically we are trying to avoid
the database calls frequently let us consider I need uh some data the database and that data is not changing
frequently so what I will do I'll cure that data at servers memory and then whenever there is a need it will uh go
to the server get the data from the cach and to the client every time I don't need to go to the database so that will
reduce the uh time uh of round trip from client to server apart from that on database side uh I can use indexing on
which are frequently used for search operations so I can uh optimize queries using uh this proper indexing then
uh I can even configure the actuator end points to get the insights of application or to monitor the
application health and performance that will help me to monitor the performance and then I can use those met to improve
the performance or I can use use the asynchronous processing uh using addir async
annotation okay all right so these are some of the nice ways to uh tune in the performance nice nice all right and um
how do you uh now we'll move to microservices consider you have one monolithic application and I want to
divide that application into microservices how would you go about dividing your monolithic to M
Services okay so dividing a monolithic application into microservice based applications first thing is I'll try to
identify the dos and what I can say as boundaries based on the functionalities so what I will do I'll try to analyze
the existing code and identify the modules which I can create or I can use to create the services then uh the next
thing is I'll try to create this separate services to handle a specific business functionality then we need to
decide how these services will interact with each other or communicate with each other so if there is a need to
consistently pass data from one service to another service then I can use synchronous
communication uh using uh messaging tools like uh capka or ACU mq or rabit mq and if there is a need to have a
synchronous communication like sending a request to a service and getting dat that service so I can use um rest apis
for this communication then I'll introduce API Gateway which will act as a front door for uh the client request
so whenever there is a request from client side it will go through the API and then uh the API get will collect
data from the different services and send back to the client and then I will use Discovery service so that service
will help me toover the instances of these services so whenever there is a need uh to communicate uh or to manage
the communication between Services I can use Discovery service to discover services for communication purpose even
I can use some load balancing to uh manage the load of these Services then I need to decide the technical
stack which will be required to implement these Services as these Services can be developed independently
and deployed independently then uh I uh need to decide the things related deployment of
these services for example I need to set up a cicd which will help me for continuous integration and
continuous deployment of this services so whenever developer commits the code the checkin should happen and it should
build the code and deploy the code to a VM or server by using Docker images or you can use kubernetes for managing
these containers then uh testing point of view I'll try to write the J units which will cover the coding
and uh from Qs point of view we uh have testing as well as Automation in place to uh for regression testing so these
are the few things which I will consider while migrating monolith application into uh microservice based application
yeah that that was a comp comprehensive answer all right thanks all right now uh let's try to uh do you know some of the
differences between synchronous and asynchronous communication in case of microservices uh yes so synchronous
communication is basically uh like send the request and wait for the response before proceeding with the next one so
basically client sends a request and for response from the uh server s uh before proceeding with the next request and I
uh we are using rest apis for uh this communication okay and uh asynchronous communication is like client continually
sends the request and uh it doesn't wait for the server to get the response for example message cues like app or rabbit
where the publisher will publish the messages continuously to that capka broker or q and the consumer will
consume it as and when are required is synchronous and asynchronous communication okay nice uh all right now
uh I am going to give you one program you can try to answer that program using Java 8 so do you want to share your
screen yes uh let me know once it is visible I can I can see your
screen okay now now uh the program statement is like this uh you want to write you need to
write a program to find the list of unique words from a sentence okay okay and sorted alphabetically in
alphabetical order using Java we need to find the unique words and sort it alphabetically using Java
it okay so what I will do uh here you can see I have written a class client and inside I write a man
that will be the starting point for my program execution now I'll take the input as a string
so Str Str equal to uh so what I will do I'll take uh input as something like Java is
fun and Java is powerful so this will be my input okay
okay now the next thing is uh I have to find the list of inals from this sentence and then I need to sort it
right so what I will do first I will try to find the and store it into list so I'll declare a variable of type list
which will hold all these unique words so I'll mention it as unique words okay now find the unique
words I can use split function which is available in string so what I can do uh and then I need to uh use stream
apis and then display the result so first thing is I'll need to uh split this so St str.
split will be used to split the uh sentence by spaces then I need to use a stream what I will do I'll simply create
a stream using array
dot stream and here I'll pass the uh Words which are splitted by using space function then what I will do I'll
convert this into lower case so I'll use map and then I'll use string colon colon to lower case so basically this lower
case is a function which is available in string and and I'm referring it using method reference object then what I will
do I'll try to find the distinct words using uh distinct function and then I'll sort all this using sorted function okay
now I got uh what I did here so I tried to split this sentence using equals and then I converted all these uh words into
low workus and then I tried to find the distinct or unique words using distinct function and then I sorted it and
finally I'll collect it into a list so I'll use collect method which takes collector and this
collectors dot to list will give me all the words into a list okay now I will get all the unique words and now I'll
simply print these words okay so I'll use system. out. print to print these words
now let me run this and see what is the output so here you can see and one is Java powerful so Java was occurred twice
but we have to find unique words so basically we need to avoid the duplicates so Java has been printed only
once then is is also printed only once and if you see all these are sorted in ascending order or alphabetical
order yes so that is uh from this Cod yeah nice all right wonderful so I think uh I'm done from my side do you
have any specific questions for me uh no I don't have any question all right so it was wonderful talking to you
and thanks a lot for your time and have a very uh good day ahead thank you yeah thank you Bye by
In Java backend development, you can create threads by extending the Thread class and overriding its run() method, implementing the Runnable interface, or preferably using the Executor framework which efficiently manages multiple threads and thread pools. The Executor framework is recommended because it provides better thread management and scalability for backend applications.
Deadlocks occur when threads wait indefinitely for each other's resources. To prevent them, maintain consistent lock ordering to avoid cyclic dependencies, use tryLock() to attempt acquiring locks without blocking indefinitely, and minimize synchronized blocks to reduce contention. These strategies help ensure threads do not get stuck waiting on each other, improving application stability.
In Java, 'throw' is used within a method to explicitly throw a specific exception instance, like throw new IOException(). In contrast, 'throws' is used in a method signature to declare that this method might throw certain types of exceptions, informing callers to handle or propagate them. For example: public void read() throws IOException indicates the method may throw IOException.
Spring Boot uses annotations like @Autowired and @Bean to inject dependencies into classes rather than having classes instantiate them directly. This approach promotes loose coupling and easier testing by allowing components to be supplied with their dependencies externally. Dependency Injection simplifies wiring components and improves modularity in backend applications.
To migrate from monolith to microservices, first identify domain boundaries and separate functional modules. Develop independent services for each module, define communication patterns using synchronous REST APIs or asynchronous messaging systems like Kafka, set up an API Gateway for unified access, implement service discovery tools such as Eureka, establish CI/CD pipelines for automated deployments, and ensure comprehensive unit, integration, and regression testing. This phased approach enables effective and maintainable microservice architectures.
In Java 8, you can process a sentence string by splitting it into words with split(" "), converting each to lowercase using map(String::toLowerCase), removing duplicates with distinct(), sorting alphabetically via sorted(), and collecting to a list using collect(Collectors.toList()). This chain of stream operations efficiently produces a sorted list of unique words. For example:
List<String> uniqueWords = Arrays.stream(sentence.split(" ")) .map(String::toLowerCase) .distinct() .sorted() .collect(Collectors.toList());
Abstract classes can contain both abstract and concrete methods and allow instance variables, while interfaces primarily declare abstract methods but can include default and static methods since Java 8. A class can extend only one abstract class but implement multiple interfaces. Use abstract classes when creating a base class with shared code and state; use interfaces to specify contracts for disparate classes to implement, promoting flexibility and multiple inheritance of type.
Heads up!
This summary and transcript were automatically generated using AI with the Free YouTube Transcript Summary Tool by LunaNotes.
Generate a summary for freeRelated Summaries
Java Programming: A Comprehensive Guide to Understanding Java and Its Concepts
Explore Java programming concepts including OOP, exception handling, and collections. Learn how to build robust applications!
Top 50 Spring Boot Interview Questions and Answers Explained
This comprehensive guide covers the top 50 Spring Boot interview questions, including key concepts, features, advantages, and practical examples. Learn about Spring Boot architecture, configuration, starters, deployment, and best practices to excel in your Java developer interviews.
Top 10 Spring Boot Interview Questions with Answers & Examples
Discover the top 10 Spring Boot interview questions with detailed answers and practical examples. This guide covers key concepts like auto-configuration, starters, REST APIs, actuator, exception handling, and profiles to help you ace your Spring Boot interviews.
Java Course Introduction: Mastering Coding Fundamentals and Data Structures
Kickstart your Java programming journey with our guided course covering basics to algorithms for aspiring developers.
Java Basics: Outputs, Variables, and User Input Explained
Learn Java's fundamentals: how to give output, use variables, data types, and take user input effectively.
Most Viewed Summaries
Kolonyalismo at Imperyalismo: Ang Kasaysayan ng Pagsakop sa Pilipinas
Tuklasin ang kasaysayan ng kolonyalismo at imperyalismo sa Pilipinas sa pamamagitan ni Ferdinand Magellan.
A Comprehensive Guide to Using Stable Diffusion Forge UI
Explore the Stable Diffusion Forge UI, customizable settings, models, and more to enhance your image generation experience.
Mastering Inpainting with Stable Diffusion: Fix Mistakes and Enhance Your Images
Learn to fix mistakes and enhance images with Stable Diffusion's inpainting features effectively.
Pamamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakaran ng mga Espanyol sa Pilipinas, at ang epekto nito sa mga Pilipino.
Pamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakarang kolonyal ng mga Espanyol sa Pilipinas at ang mga epekto nito sa mga Pilipino.

