telephonic interview on java, microservives
Core Java
1.)
Can you tell me briefly about oops principle
with a real time example?
Inheritance:- It is a way in which child
object inherits common properties and behavior
From parent object.
Use of this is to promote code
reuseability.
Polymorphism:-
2 types of polymorphism are there compile
time(overloading ) and runtime (overriding).
Overloading:- to change the behavior of
method based on change in arguments.
Overriding:- To change the behavior of
method defined in parent class in child class.
Encapsulation:- It is used to bind data and
behavior in together.It is promoted by making
Instance varaibles private and access via
getter and setter.
Abstraction:- To hide implementation
details from the client and exposing via interface or abstract class is know as
abstraction.
Example :- HashMap
Map map = new HashMap();
m.put(“key”,”value”);
As we can see, we can create and use the
operations but underlying implementation is hidden so implementation is
abstracted from client.
Internally, HashMap uses Entry array, then
declare private and public access methods that the encapsulation.
A realization of your desired
abstraction.
Encapsulation = Abstraction + Data Hiding
2.)
What is the use of POJO(getter and setter) in
java?
It is encapsulation principle.
The fields of a class can be made read-only
or write-only.
A class can have total control over what is
stored in its fields.
The users of a class do not know how the
class stores its data. A class can change the data type of a field and users of
the class do not need to change any of their code.
3.)
Difference between ArrayList and LinkedList?
Storage
ArrayList:- dynamic array
LinkedList:- doubly LinkedList
Use case
ArrayList:- ArrayList is better for storing
and accessing data.
LinkedList:- LinkedList is better for
manipulating data.
4.)
Below Code snippet and tell the output.
Void a() throws exception()
{
B();
Return “a”;
}
Void b(){
Try{
Return “b”;
}catch (Exception e) {
Return “e”;
}finally {
Return “f”;
}
}
a.)
Incase no exception is thrown
b.)
Incase exception is thrown
Always return a and in case exception is re- thrown then
nothing will be printed .
Spring
5.)
What is spring boot, spring eureka , spring config?
Spring boot:- simplify the
bootstrapping and development of a new Spring application.
Spring eureka:- used to
register services to repository.
Spring config:- to find out
the end point of eureka server and other configurations
6.)
How to achieve Loading
balancing and fault tolerance ?
Using Ribbon and Hystrix.
7.)
Difference between .properties
and .yml file and which one is good.
Difference between
properties and yml is duplication of prefixes for same category.
YML Is more human readable.
Can configure different
profiles in single file using yml.
8.)
Can we configure
different properties file like yml for different profiles?
Yes.
9.)
Difference between POST
and PUT http methods?
PUT is idempotent, so if you PUT an object
twice, it has no effect. This is a nice property, so I
would use PUT when possible.
POST is non-idempotent, when you need the
server to be in control of URL generation of your resources. Use PUT otherwise.
Prefer PUT over POST.
Example:- POSTing twice with the same data
means create two identical users with different ids. PUTing twice with the same
data creates the user the first and updates him to the same state the second
time (no changes). Since you end up with the same state after a PUT no matter
how many times you perform it, it is said to be "equally potent"
every time - idempotent. This is useful for automatically retrying requests. No
more 'are you sure you want to resend' when you push the back button on the
browser.
Comments
Post a Comment