java microservice telephonic interview of 10 years experienced
Summary
TLDRIn this interview, the candidate discusses their experience with microservices architecture and communication methods, including REST and Kafka. They address handling high-throughput scenarios and Java-related topics such as version differences, exceptions, and multi-threading. The candidate also explains key concepts in Java 7 and Java 8, including Comparable vs. Comparator and stream API. They touch on service discovery, service registry, and Spring Boot beans. The interview concludes with a coding challenge to check for anagrams, showcasing the candidate's logical approach to problem-solving.
Takeaways
- 👋 Introduction and current roles and experiences discussed.
- 💻 Discussion about microservices architecture versus monolithic services.
- 🔄 Explanation of service communication using REST template for updates.
- 🔧 Query about the setup and handling of Kafka producer-consumer throughput.
- 📜 Differences between Java 7 Comparable and Comparator explained.
- 🤝 Contract between equals and hash code methods in Java discussed.
- 🔀 Explanation of starvation and deadlock in multi-threading environments.
- ❗️ Difference between compile-time and runtime exceptions in Java.
- 🚫 Explanation of exception handling using throw and throws keywords.
- 🗂 Differences between HashMap, HashTable, and ConcurrentHashMap and their use cases.
- 🌊 Discussion about the use of streams in Java 8 and their advantages over iterators.
- 🔍 Use of service discovery and service registry in applications explained.
- 🔠 Task to check if two strings are anagrams by comparing character counts.
- 🫘 Explanation of the concept of a bean in Spring Boot.
Q & A
What are your current roles and how much experience do you have?
-The interviewee is involved in doing both reviews and credit card fixing at a call center. They have experience with these tasks and are proficient in both.
Are you using a microservice architecture or monolithic services?
-The interviewee is using microservice architecture.
Can you explain how service communication happens in your current project?
-The service communication depends on the type of call. For synchronous calls, they use REST with a REST template for updates and parameters. For asynchronous communication, they use Kafka for event-based messaging.
How would you handle a scenario where your Kafka producer is producing 100 records per second but the consumer is consuming only 20 records per second?
-In this scenario, the interviewee would handle the situation by increasing the throughput, likely by adding more consumers or optimizing the existing consumer logic.
What is the difference between Comparable and Comparator in Java?
-Comparable has a single method, compareTo, used to define the natural ordering of objects. Comparator, on the other hand, allows multiple comparison methods to define different orderings, often implemented as a functional interface in Java 8 and above.
What is the contract between the equals and hashCode methods in Java?
-The contract between equals and hashCode is that if two objects are equal according to the equals method, they must have the same hashCode. However, it is not required for two objects with the same hashCode to be equal according to the equals method.
What is the difference between starvation and deadlock in a multithreading environment?
-Starvation occurs when a thread is perpetually denied access to resources, while deadlock is a situation where two or more threads are blocked forever, each waiting on the other to release a resource.
What are some ways to prevent deadlock in a multithreading environment?
-To prevent deadlock, one can use techniques like ordering resource acquisition, using a timeout for resource requests, and employing deadlock detection algorithms.
What is the difference between a compile-time exception and a runtime exception in Java?
-Compile-time exceptions, also known as checked exceptions, must be handled with try-catch blocks or declared with the throws keyword. Runtime exceptions, or unchecked exceptions, occur during program execution and do not need to be explicitly handled.
What is the difference between the throw and throws keywords in Java?
-The throw keyword is used to explicitly throw an exception within a method. The throws keyword is used in a method's signature to declare that the method can throw exceptions of the specified types.
What will happen if a method in a parent class throws a NullPointerException and a method in a child class throws an Exception?
-The code will not compile because the child class method cannot throw a broader exception than the parent class method. The exceptions thrown by the child method must be the same or a subclass of the exceptions thrown by the parent method.
What are the differences between HashMap, Hashtable, and ConcurrentHashMap in Java?
-HashMap is not synchronized and is suitable for single-threaded environments. Hashtable is synchronized and thread-safe but generally slower. ConcurrentHashMap is designed for concurrent access, providing better performance in multithreaded environments.
Why is the Stream API faster than an iterator in Java?
-The Stream API can be faster because it supports parallel processing and allows more optimized operations on data collections.
What is the purpose of service discovery or a service registry in microservices architecture?
-Service discovery or service registry is used to register and manage all the services in an application. It helps in locating and distributing client requests to different services, checking the status of services, and managing service instances.
What is a Spring Bean and how is it used?
-A Spring Bean is an object managed by the Spring IoC container. It is defined in the configuration file or by using annotations, and the container instantiates, configures, and manages the bean's lifecycle.
Outlines
😀 Introduction and Experience
The speaker introduces themselves, describing their current roles and technologies they work with. They mention their experience in reviews, credit card fixing, and call center work. They discuss using microservice architecture and the communication methods between different services, including synchronous calls and REST templates.
🤔 Comparable vs Comparator
The speaker explains the difference between Comparable and Comparator in Java. Comparable has a compareTo method and is used for natural ordering, while Comparator can have multiple methods for customized sorting. They also discuss the contract between equals and hashCode methods, emphasizing consistency in their implementations to avoid errors.
🧵 Multi-threading: Starvation and Deadlock
The speaker delves into multi-threading, explaining starvation and deadlock. They describe how threads can wait for each other indefinitely, leading to deadlock, and how synchronization blocks can be used to avoid such issues. They also touch upon compile-time vs runtime exceptions and the proper use of throw and throws keywords.
📝 Java Exceptions and HashMap Variants
The conversation covers the difference between compile-time and runtime exceptions in Java. The speaker also discusses the distinctions between HashMap, Hashtable, and ConcurrentHashMap, including their use cases and performance differences. The benefits of stream processing over iterators in Java 8 are highlighted.
🔄 Service Discovery and Anagram Logic
The speaker explains service discovery and registry in the context of microservices, using examples of service registry and client requests. They then tackle a coding problem to check if two strings are anagrams, discussing the logic of character count and sorting. The paragraph ends with a brief mention of Spring Boot beans.
Mindmap
Keywords
💡Microservice architecture
💡Synchronous communication
💡Kafka
💡Java 7
💡Comparable and Comparator
💡Equals and hashCode contract
💡Multithreading
💡Deadlock
💡Compile-time vs. runtime exception
💡HashMap, Hashtable, ConcurrentHashMap
Highlights
Introduction of the interviewee's current roles and technologies.
Discussion about service communication methods in the current project.
Explanation of using synchronous and asynchronous calls with REST template.
Description of Kafka setup and event handling in the project.
Scenario-based question on handling Kafka producer-consumer throughput.
Start of Java questions focusing on versions used.
Difference between Comparable and Comparator in Java 7.
Explanation of the contract between equals and hashCode methods in Java.
Discussion on working in a multithreaded environment and avoiding deadlocks.
Explanation of compile-time versus runtime exceptions in Java.
Difference between throw and throws in exception handling.
Scenario question involving method overriding and exceptions in parent and child classes.
Difference between HashMap, Hashtable, and ConcurrentHashMap.
Features used from Java 8 in the current project, including streams.
Comparison of streams and iterators in Java for parallel processing.
Explanation of service discovery and service registry usage.
Anagram logic and coding task involving string manipulation.
Question on Spring Boot beans and annotations.
Transcripts
ah let's start with the basic
introduction and uh what is your current
roles and how much is experience you
have and a little bit about your current
Technologies
[Music]
sometimes doing both reviews and credit
card fixing added me call center
foreign
are you using my microservice
architecture or monolithic
Services okay can you a little bit uh
explain about how the service
communication happens
into your current project
the different Services
depends on what kind of call we want
like synchronous
so let's say like if it is called
basically we are doing uh like by using
the rest template so we are using the
rest for updates
as part of the parameters and then uh
like that particular services
and if it is
well here we are using like for the
communication we are using that
let's call it
okay so have you set up that Kafka or it
all set up by the another person
the more our team used to work the
functionality we are working basically
it is a synchronous call we are saying
so I am more profitable in that but yes
we are using that
event
if new event they are adding so they are
adding into the XML files
correct in details because
okay okay
fine so like I have one scenario for the
Kafka uh my producer is producing 100
records per second
but my consumer is consuming 20 record
per second
so how you will handle this scenario
like in some case it will be
a full queue and you will not able to
push the records into your queue so what
you will do in this scenario
how will you how you will increase the
throughput
s
okay okay fine
so let's start with the Java questions
currently which Java version you are
using
okay Jared let's start with the Jazz
some job seven questions first and then
we will move to the javasa it so in a
Java 7 we have comparable and
comparative what is the difference
between those
is having highest incomparable
comparabilities compared to method is
there and Main comparator we are we are
having a second by expression which of
the methods are there in a comparable
method only is available English to
interfaces and actually even we can send
Java it we can say it time with the
functional interface also but in
compatibility is the method is available
okay okay
yeah yeah okay what so like uh an
incomparable comparator we are using
equals methods and uh hash codes also so
what is the contract between equals and
hash code method
in Java
is
if we can select if the first method we
are doing the uh let's say the
temperature right by using first method
and if the output is like whatever
output it is given from the equals
method the hasbode method also is going
to give us the same but the contract
like the Y Square size Mark correct like
it can be different so we can say equals
method we can return value and password
return value will be same if it is like
but if if the has per value is returning
something
method
okay okay fine
so in a uh
uh have you work in a multi-theory
environment
project
s
okay so what is the difference between
starvation and date lock
okay
we have to create some more threads and
they are waiting for each other to get
the object Club let's say I have foreign
[Music]
[Music]
and
and we can cover it like if you want to
Google it um like to reserve it
basically we can use this uh using the
synchronized block or synchronization
paper basically we can play positive
blog so that only one third will execute
once the execution
get released then another thread we can
give it like we can add another checking
status execution
foreign
yeah yeah fine no problem so while
you're giving answers you told that like
a star which uh deadlock can be avoided
so what are the like what are the ways
we implement or we
uh follow so that we will not able to
get into deadlock situation
so can you give some examples like in
your projects which you guys follow or
followed
we can keep
we can call those methods like in in the
living we can select application between
threads we can keep it in some way
things States and we can call that
notify notify all method at all or we
can basically if we are going to do
because before having a synchronization
we can say this is a straight set so
that only one thread will be like able
to access that particular lock of that
object there
okay so what is the okay thanks
so what is the difference between a
compile time
exception Android time exception
second exception
this basically there's two exceptions
yeah it's it's the part of exception
class so that definition we can say it
is uh it will be used to get it in the
compiled time and we we will be able to
test it or we can we can handle this
exception so that like well writing
before we can give the cash flow or
close keyword and then we can use it and
we can handle that exercise but runtime
exceptions basically we will get that
for runtime only so that like we can say
something like we have to open whenever
we are writing that code let's say uh
array index out of boundary and that
kind of exception only used questions
so in that case we have whenever we are
writing that code we have to take care
of the uh like exercise
so you can
handle it in the foreign
yeah
okay
we are writing our like custom
exceptions we can say so those exception
candles we can uh keep it as part of the
objectives
okay so while implementing or writing
the exception code you we use throw and
Truth what is the difference between
throw and those
of course basically we are using a
startup first method uh
signature itself
whenever we want to throw that
exceptions we can
okay so suppose I have class A which is
my parent and I have class B which is my
child class
so in parent class I have a method
display over the display method I am
throwing the exception
uh
null pointer exception okay
close null pointer exception so
and Below there is one method in a child
class same method which is X throwing
the exception throwing
exception okay
so will this class compile or will
or it will throw the runtime exception
so that is
showing that except something like the
main line yeah
it is like super self yes
so
I think now it will not allow us because
we can we can give in the Surplus only
like the uh let's start back at the
final Foundation if we are showing the
exceptions in class a method and we are
using some other exceptions in the class
three methods then I think it will allow
okay yeah right
type of exceptional it will not be it
will not Allah
okay great
uh we have a hash map has
cable and concurrent hashmah so what is
the difference between these three when
we use and when
which is the faster from these three and
what is the use cases of these three
okay as you have Snapchat has not
basically we are using uh
it
is like
I can make we can make it as simple
by using the synchronized math method
confident has not possibilities like uh
it is getting used for the single thread
environment
yeah yeah got it okay so like uh how
much you're not expense like your legs
move to the
so from java it like uh which are the
features you have used in your current
project
foreign
okay so have you uh like I used a stream
okay so why stream is faster than
iterator
like it will do uh what to select it is
like we are we used to get the output
also as a stream type basically so we
can say based on the parallel processing
it is
of so how much iron for experience you
have in a
um
okay so what is the use of service
Discovery or Services history
basically we are using this service
registry we can sell it to register all
of our services like whatever Services
we are using as part of application we
can register there so we can unless they
like we are using something like example
the service resistance you requests
of client is
located
and distribute certificates to the
different Services which is available in
the service resolution so we can even
take in the service registry the how
many uh services are available already
is in the uh which state like the status
of the services like it is active or not
we used to get it and uh
as a service registry we can use like we
have producer Factory we can like we are
going into the apartment can help and we
can give in the service track like
enable uh
um
okay thanks okay so like uh do you have
any coding editor open Let's uh
okay can you share so I will be giving
one small example uh
I have one program like uh let's take I
am write a string like a RM programmer
then there is one more string
programmer I am
so you have to tell
uh is it an anagram or not okay
so
you know what is mean by another
all right yes I think it is it should be
like having the same characters
okay and same count of the character
many characters and same count yes
uh you can tell me logic and then start
or because we have a listen
think on that
um
I can do here one thing like if first
I'll check the length
so what I can do I can keep it this
thing to some character array
in this one also I can keep it into some
character array when I can sort that
value after using something like let's
say uh for that particular character
arrive here it is now it's a character
that I am having all those characters
sort with screen character then I can
use one more foreign
okay
so
uh I have like uh some questions from
the spring boot like in Spring boot we
have a
string and spring mode okay we have a
bean okay so what is mean by b
I like The annotation chip we are using
or
like we have to do the foreign
oh great
Weitere ähnliche Videos ansehen
TCS Java | Spring Boot | Microservices | 4 Years | Selected | Mock Interview
Java Spring Boot 3 Years Experience Interview
Crack Your Java Interview With Most-Asked Questions | Java Fundamentals
Call Center Actual Application | Mock Call | Final Interview | Kuya Reneboy in Metacom Part 3
Frontend Interview Experience (Unacademy) - Javascript and React JS Interview Questions
#1 What is Spring Framework?
5.0 / 5 (0 votes)