Hi Friends,
In this post I'm sharing the questions asked in Walker Digital Table Systems for Java Tech Lead position.
Also read my other interviews:
Question 1:
What is Reentrant Lock?
Answer:
ReentrantLock is a mutually exclusive lock with the same behavior as the intrinsic/implicit lock accessed via synchronization.
ReentrantLock, as the name suggests , possesses reentrant characteristics. That means , a thread that currently owns the lock can acquire it more than once without any problem.
ReentrantLock forces one thread to enter critical section and queues all other threads to wait for it to complete.
Basically, java 5 introduces the concept of a lock. Lock and ReadWriteLock are interfaces in java 5.
And their implementations are ReentrantLock and ReentrantReadWriteLock.
Question 2:
How to handle service fallback in MicroServices?
Answer:
We can use Circuit breaker pattern implementation Netflix Hystrix for handling fallback in microservices.
Actually, in Microservices based arhitecture, there are many applications running in different processes on different machines. And any of these service may be down at some point of time. So to avoid sending all requests to this misroservice, Circuit breaker pattern can be used.
Question 3:
What are REST Call End Points?
Answer:
e.g.: https://api.github.com/users/zellwk/repos?sort=pushed
In above URL, https://api.github.com is root endpoint
/users/zellwk/repos is path which determines the resource we request for.
The last part of an endpoint is query parameters. Query parameters give us the option of modifying the request with key-value pairs. They always begin with a question mark [?]. Each parameter pair is then separated with an ampersand [&] , like this:
?query1=value1&query2=value2
Question 4:
Explain Lifecycle of Spring Bean.
Answer:
Question 5:
Explain the steps of sending a request from browser and handling it at server side?
Answer:
Steps :
Question 6:
Name all the HTTP verbs?
Answer:
HTTP verbs are:
Question 7:
What is a DispatcherServlet?
Answer:
DispatcherServlet handles all HTTP requests and responses.
It is front controller in Spring MVC based applications. DisptacherServlet uses it's own WebApplicationContext which is a child of ApplicationContext created by ContextLoaderListener.
Question 8:
When we override hashcode() method, then how to retrieve the actual default hash code value for that object?
Answer:
Just use System.identityHashCode(object);
The value returned by default implementation of hashcode() is called identity hash code.
Identity hashcode is usually the integer representation of the memory address.
Hashcode of an object is a 32-bit signed int that allows an object to be managed by hash-based data structure.
Question 9:
Write a logic of two threads printing question and answer one-by-one.
Answer:
class Chat{
boolean flag = false;
public synchronized void Question(String message){
if(flag){
try{
wait();
}
catch(InterruptedException ie){
ie.printStackTrace();
}
}
System.out.println(message);
flag = true;
notify();
}
public synchronized void Answer(String message){
if(!flag){
try{
wait();
}
catch(InterruptedException ie){
ie.printStackTrace();
}
}
System.out.println(message);
flag = false;
notify();
}
}
class Question implements Runnable{
Chat chat;
String[] str = {"Hi", "How are you?", "I'm also doing fine"};
public Question(Chat c1){
this.chat = c1;
new Thread(this, "Question").start();
}
public void run(){
for(int i = 0; i< str.length; i++){
c1.question(str[i]);
}
}
}
class Answer implements Runnable{
Chat chat;
String[] str = {"Hi", "I'm good", "Great"};
public Answer(Chat c1){
this.chat = c1;
new Thread(this, "Answer").start();
}
public void run(){
for(int i=0; i<str.length; i++){
c1.answer(str[i]);
}
}
}
public class Test{
Chat chat = new Chat();
new Question(chat);
new Answer(chat);
}
That's all.
Hope this post help every reader in java interview preparation.
Thanks for reading.
Also read my other interviews:
Question 1:
What is Reentrant Lock?
Answer:
ReentrantLock is a mutually exclusive lock with the same behavior as the intrinsic/implicit lock accessed via synchronization.
ReentrantLock, as the name suggests , possesses reentrant characteristics. That means , a thread that currently owns the lock can acquire it more than once without any problem.
ReentrantLock forces one thread to enter critical section and queues all other threads to wait for it to complete.
Basically, java 5 introduces the concept of a lock. Lock and ReadWriteLock are interfaces in java 5.
And their implementations are ReentrantLock and ReentrantReadWriteLock.
Question 2:
How to handle service fallback in MicroServices?
Answer:
We can use Circuit breaker pattern implementation Netflix Hystrix for handling fallback in microservices.
Actually, in Microservices based arhitecture, there are many applications running in different processes on different machines. And any of these service may be down at some point of time. So to avoid sending all requests to this misroservice, Circuit breaker pattern can be used.
Question 3:
What are REST Call End Points?
Answer:
e.g.: https://api.github.com/users/zellwk/repos?sort=pushed
In above URL, https://api.github.com is root endpoint
/users/zellwk/repos is path which determines the resource we request for.
The last part of an endpoint is query parameters. Query parameters give us the option of modifying the request with key-value pairs. They always begin with a question mark [?]. Each parameter pair is then separated with an ampersand [&] , like this:
?query1=value1&query2=value2
Question 4:
Explain Lifecycle of Spring Bean.
Answer:
Question 5:
Explain the steps of sending a request from browser and handling it at server side?
Answer:
Steps :
- First request from browser [client side] will be received by DispatcherServlet
- DispatcherServlet will take the help of HandlerMapping and get to know the Controller class name associated with the given request.
- So now, request transfers to the Controller and then controller will process the request by executing appropriate methods and returns ModelAndView object back to the DispatcherServlet.
- Now DisptacherServlet send the view name to the ViewResolver to get the actual view page.
- Finally DispatcherServlet will pass the Model object to the view page to display the result.
Question 6:
Name all the HTTP verbs?
Answer:
HTTP verbs are:
- GET
- PUT
- POST
- DELETE
- HEAD
- PATCH
Question 7:
What is a DispatcherServlet?
Answer:
DispatcherServlet handles all HTTP requests and responses.
It is front controller in Spring MVC based applications. DisptacherServlet uses it's own WebApplicationContext which is a child of ApplicationContext created by ContextLoaderListener.
Question 8:
When we override hashcode() method, then how to retrieve the actual default hash code value for that object?
Answer:
Just use System.identityHashCode(object);
The value returned by default implementation of hashcode() is called identity hash code.
Identity hashcode is usually the integer representation of the memory address.
Hashcode of an object is a 32-bit signed int that allows an object to be managed by hash-based data structure.
Question 9:
Write a logic of two threads printing question and answer one-by-one.
Answer:
class Chat{
boolean flag = false;
public synchronized void Question(String message){
if(flag){
try{
wait();
}
catch(InterruptedException ie){
ie.printStackTrace();
}
}
System.out.println(message);
flag = true;
notify();
}
public synchronized void Answer(String message){
if(!flag){
try{
wait();
}
catch(InterruptedException ie){
ie.printStackTrace();
}
}
System.out.println(message);
flag = false;
notify();
}
}
class Question implements Runnable{
Chat chat;
String[] str = {"Hi", "How are you?", "I'm also doing fine"};
public Question(Chat c1){
this.chat = c1;
new Thread(this, "Question").start();
}
public void run(){
for(int i = 0; i< str.length; i++){
c1.question(str[i]);
}
}
}
class Answer implements Runnable{
Chat chat;
String[] str = {"Hi", "I'm good", "Great"};
public Answer(Chat c1){
this.chat = c1;
new Thread(this, "Answer").start();
}
public void run(){
for(int i=0; i<str.length; i++){
c1.answer(str[i]);
}
}
}
public class Test{
Chat chat = new Chat();
new Question(chat);
new Answer(chat);
}
That's all.
Hope this post help every reader in java interview preparation.
Thanks for reading.
java training
ReplyDelete