All Interview Question
All Interview Question
4. Lots of API to learn: A lot of effort is required to learn Hibernate. So, not
very easy to learn hibernate easily
What will be the exception will occur if we add object of Dog in List<Animal>?
Synchronized HashMap:
1. Each method is synchronized using an object level lock. So the get and put methods on
synchMap acquire a lock.
2. Locking the entire collection is a performance overhead. While one thread holds on to the
lock, no other thread can use the collection.
ConcurrentHashMap was introduced in JDK 5.
1. There is no locking at the object level, The locking is at a much finer granularity. For
a ConcurrentHashMap, the locks may be at a hashmap bucket level.
2. The effect of lower level locking is that you can have concurrent readers and writers which is
not possible for synchronized collections. This leads to much more scalability.
3. ConcurrentHashMap does not throw a ConcurrentModificationException if one
thread tries to modify it while another is iterating over it.
If we have configured Second level cache and data is changed from Database ? what output
will be returned on calling get or load method?
5) global session: global session scope is equal as session scope on portlet-based web
applications.
What is wildcard?
What is the use of Ribbon and Zuul Proxy ? How Hystrix comes in picture?
You can throw any type of Throwable object using the keyword throw . It interrupts the
method. Anything after the throw statement would not be executed, unless the thrown
exception is handled. The exception object is not returnedfrom the method, it is thrown
from the method.
War : Web archive file : It represents a web application and in a single war file it contains all the
html, css , js ,xml, jsp, servlet etc all the web component required for a web application. If we
maintain a war file project delivery, deployment and transportation will become easy.
EAR: Enterprise archive file : It represents enterprise application. In web application we can use
only web related technology like Servlet and Jsp but in enterprise application anything related
to java j2ee ,we can use like ejb Jms etc
Logback mechanism
Adding Dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
spring-boot-starter-web comes with Embedded Tomcat. We need to exclude this
dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
What are Rest API? What are different methods of Restful Api?
What is Connection pooling? Which API do you use for connection pooling in your application
and How?
What is the way to call default and static method call in Java 8?
What is difference between @ Component and @ Service?
Why we have this static interface ? it could be also possible in any class?
If we are implementing default method in our class. Which method will be called our
implemented method or default method implementation in Interface?
Interface A{
Default test(){}
} Class B implents A{
Test(){
Interface A {
Default test(){ }
Interface B{
Default test(){ }
Class C implements A, B{
We are calling c.test(); /// What it will give CTE/Exception?
Q-> There is a table called Employee. I have employee object I want to ensure that at any given
point of time at a time one request for one employee should be updated. So suppose for the
same employee I have three threads. I want to ensure for single request should be updated on
sequential manner and for multiple request employee should be updated on parallel manner.
How you will design the system?
To update a single employee object it should work sequential and for multiple employee that
should go parallel. what level locking should we used? and how you will manage?
How long this thread will wait on calling wait () method? Is there any time limit?
Which thread will get chance to continue its execution on after calling t1.notify() if t2, t3, and
t4 are in waiting state?
LinkedList vs ArrayList?
What is Map?
If I have multithreaded system which map should we use for taking care of Performance and
Security both?
How Hashmap internally works?
If I want to use my custom class object as key ? what are the guidelines we have to follow?
I have a collection of employee/We want to sort it. How it will be sorted. If I don’t define
anything basis will it give nay error?
I have an array of size 10. I have two stack object s1 and s2. I am performing pop, push
operation on both object but the element should be stored in one array only?
I want to build an approval management system. Where Request comes to Manager if manager
rejects it. it revert back to requester. If Manager approves request goes to Senior Manger. If
senior manager approves then it goes to higher level. I Want to design a system. How will you
design it.ie what will be the classes and how the all will be related?
In the above case if you are creating the same methods in all level of class. Then why are you
creating these methods at different level.
What is subquery?
For extracting data which one is better approch .using subquery or using Joining?
In two phase locking we use synchronized at class level locking or object level locking?
How we make the class so that no one can clone my singleton object?
Types of Autowiring?
Beanfactory vs ApplicationContext?
Union vs UnionAll?
Query 1 1 2 3
Query 2 -> 1 2 3 4
Triggers?
What is synchronization?
Can you brief ur current project you are working for and the challenges you have?
How your downstream application sends the request picked by you? Like SELA picks that
request one by one or any multithreading involved to process?
How you connect your upstream application either its sequential or parallel processing?
Is result coming from one upstream application dependent on others?
What happens if you are sending the request to upstream or sending the response to down
stream and it is taking a longer time .then how do you handle it? Do you just truncate or is
there any timeout? Or you wait to return response from all the services, means how do you
handle it?
If you a controller ABC and you are calling different services s1, s2, s3, s4.This service call is any
API driven or Rest call? --- its a rest API call
If 4 different request has been sent to s1, s2 s3 and s4 so s1, s2 s3 has returned the response
and suppose s4 service is slow or hang so your request is stuck. i.e no any negative response
nor any exception? What is your approach to handle this? // Hystrix
If any exception occurs then Hystrix but if it is taking too long time due to stickness of any
reason ?
If you're only interested in the keys, you can iterate through the keySet() of the map:
Map<String, Object> map = ...;
Finally, if you want both the key and value, use entrySet():
Problem statement :
Questions:
1. You have a Java web server in production that got stuck: stopped writing logs and
doesn’t answer to http requests. How would you investigate?
2. Logs say OutOfMemoryError - how would you investigate?
3. Customer clicks on a button and gets NullPointerException, but same case works
correctly in development environment. There are no log statements in code that help
analyse the problem. How would you investigate and what step would you take to ease
debugging such problems in future?
4. You are investigating an issue and written a JUnit test - it fails as expected. So you start
debugger and step over several times, but the issue is not reproduced. Why can this
happen?
5. Your production Java web server typically handles http request in <50ms, but now you
see times raised to about 1 second. How would you investigate?
6. You have multithreaded app which looks properly synchronized, but sometimes it seems
that when particular field is read it returns old value. You suspect some synchronization
issue, how would you investigate?