0% found this document useful (0 votes)
84 views

Interview Questions

The document contains answers to various questions about APIs, Spring Boot, Hibernate, and Java concepts. Key points include: - Spring Boot applications can replace the embedded Tomcat server with other servers like Jetty by adding the appropriate dependency and excluding Tomcat. - The @SpringBootApplication annotation helps with configuration, component scanning, and autoconfiguration in Spring Boot. - Hibernate is an ORM tool that provides object-relational mapping and improves performance over JDBC through caching and exception handling. - Important Hibernate concepts include entities, mappings, annotations, sessions, and configuration files.

Uploaded by

sudershan dolli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Interview Questions

The document contains answers to various questions about APIs, Spring Boot, Hibernate, and Java concepts. Key points include: - Spring Boot applications can replace the embedded Tomcat server with other servers like Jetty by adding the appropriate dependency and excluding Tomcat. - The @SpringBootApplication annotation helps with configuration, component scanning, and autoconfiguration in Spring Boot. - Hibernate is an ORM tool that provides object-relational mapping and improves performance over JDBC through caching and exception handling. - Important Hibernate concepts include entities, mappings, annotations, sessions, and configuration files.

Uploaded by

sudershan dolli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

1)How you test api by unit testing?

2)How you done server side validation?


3)Can we override or replace embedded tomcat server in spring boot?
ans:Yes we can replace by just adding the dependency of another server like jetty.
Firstly we have to exclude the embedded server by using
<exclusions></exclustions> tag
in that exclusions tag we have to use <exculsion> </exclusion> tag in that
exclusion tag we have
to write group id as org.springframework.boot and artifact id as spring-boot-
starter-tomcat.
And after that we have to add dependency of jetty server like gropu id and
artifact id as
spring-boot-starter-jetty.

4)Can we disable default web server in springboot application?


ans:-Yes we can disable by using spring.main.web-appliction-type=none in
application.properties file.

5)How to disable autoconfigure class in spring boot?


ans:-By using "exclude" we can disable auto congiguration class
Example:@Enableautoconfiguration(exclude={classname.class}) we can disable n
no.of classes.

6)How does the @SpringBootApplication annotation internally works?


ans:-@SpringBootApplication annotation is equivalent to using @configuration which
helps you in
identifying a beans for a particular dependency
injection,@EnableAutoConfiguration which helps you
in autoscan if a particular bean is avaliable in your classpath then it will
be autoscanned
and it will be added to your set of dependencies,and @ComponentScan it is used
to scan components or beans
with their default attribute.

7)What is @RestController annotation in springBoot?


ans:-Basically @RestController annotation is used to create Restful Controller.It
is basically combination of two
annotation of spring that is @Controller and @ResponseBody.It converts the
response in JSON or XML.

8)Difference between @ResquestMapping and @GetMapping?


ans:-@RequestMapping is used with get,post,put etc using the method attribute on
the annotation where as @GetMapping is
responsible of getting only the get request rather than post,put etc.

9)What is the use of profiles in the spring boot?


ans:We typically deal with multiple environment such as development(dev),prod
etc.The configuration properties for these environment
is different,so in application.properties file we simply have to specify
spring.profiles.active=dev or prod.
10)What is cache mechanism in hibernate?
ans:Cache is a mechanism which enhance the performance of the application.
Cache is used to reduce the database query.For e.g if I m using java
application in that if jst want to get one object from the database
then query will be fired and the database will return the object to java
appln.but after that if i want the same object one more time then
i have to send the request to database the it will return the same object one
more time in this way it will reduce the performance to overcome
this problem we will use hibernate cache which will act as a mediator in
between appliction and database if we request for object it will
first chech it in its cache memory then if it is not present then it will
request the database to send the object and then it will first
store the object in its cache memory and then it will return the object to
application.
There are two types of cache in hibernate FirstLevel cache and SeconLevel
Cache.
First level cache is associated with Session object and it is avaliable by
default in hibernate.
Second level cache is associated with Session Factory and if we want to use
that cache then we have to enable it manually.
11)What is hibernate why we use hibernate over jdbc?
ans:-Hibernate is a ORM(Object relational mapping) tool used to map java object and
database table.Basically hibernate provides you two methods
to connect with database table ie JPA annotation and xml configuration.JPA is
an interface and hibernate is a class it provides interface
to what to do and hibernate will descide how to do.
Hibernate over JDBC:
1.Hibernate supports HQL which is more object oriented.
2.It provides transaction management implicitly.
3.It throws JDBC exception or Hibernate exception which are unchecked
exception and dont need to worry about handling exception in try catch block.
4.Hibernate provides cache support for better performance.
12)Importent interfaces used in hibernate?
ans:-There are three interfaces used in hibernate that are
1.SessionFactory:It is used to create session object
2.Session:It is used to create transaction object and also used to perform
crud operation.
3.Transaction:This specifies single or atomic unit of work.
13)Important annotations in Hibernate?
ans:-1.@Entity:used to mark the class as a entity beans.
2.@Table:It is used with entity beans to specify the corresponding table name
in database.
3.@ID:Used to define the primary key in the entity beans.
4.@Access:Used to define access type either field or property.
5.@Column:Used to define the column name in database table.
6@one to one mapping:used to define one to one mapping between two primary
beans.
7.@GeneratedValue:-Used to define stratergy to generate the primary key.
14)Mappings in Hibernate?
ans:-There are the three mapping type in hibernate
1.one to one mapping:One object is associated with one object only.Example one
customer has one transaction.
2.one to many mapping:One row in a table is mapped with multiple rows in
another table.Example one user has multiple policy
3.many to one mapping:Multiple rows in a table can be mapped with multiple
rows in another table.
15)What are hibernate configuration files?
ans:-It is used to put all our database properties such as
username,password,url,driver class all the database related initialisation
is done in configuration file.
16)Steps to create the hibernate sample App ?
ans:-firstly create the pojo class then create the mapping file,create the
configuration class,class for retriving or storing the
persistence pojo and run the application to see results.
17)How to connect hibernate to springboot?
ans:we simply need to add dependency in pom.xmlfile like spring-boot-starter-data-
jpa,hibernate-core,hibernate-entitymanager and physically
connect to database mysql-connecter-java.
18)What is singleton class?
ans:-For any java class if we are allowed to create only single object such type of
class is called singleton class.
E.g:-Runtime,bussiness deliegate,service locater etc.
Advantage of singleton class:-If several people have same requrirement then
its not recommented to create aseparate object for every
requirement,we have create only one object and we can reuse same object for
every similar requirements so that performance and memory
utilization is improved.This is the central idea of singleton classes.
***Is it possible to create our own singleton class?
Ans:-Yes we can create our own singleton classes for this we have to use private
constructor and private static variable and public factory method.
Approach 1:-class Test
{
private static Test t=new Test();
private Test(){
}
public static Test getTest(){
return t;
}}
19)What is API?
ans:API stands for Application Programming Interface
An API is a set of defined rules that explain how computers or applications
communicate with one another. APIs sit between an
application and the web server, acting as an intermediary layer that processes
data transfer between systems.
** How API's work**
A client application initiates an API call to retrieve information—also known
as a request.
This request is processed from an application to the web server via the API’s
Uniform Resource Identifier (URI)
and includes a request verb, headers, and sometimes, a request body.
After receiving a valid request, the API makes a call to the external program
or web server.
The server sends a response to the API with the requested information.
The API transfers the data to the initial requesting application.
20)What is web client?
ans:In simple words, the Spring WebClient is a component that is used to make HTTP
calls to other services.
It is part of Spring's web reactive framework, helps building reactive and non-
blocking applications.
The WebClient class provides common methods for sending data to or receiving
data from any local, intranet,
or Internet resource identified by a URI. The WebClient class uses the
WebRequest class to provide access to resources.
21)@Qualifier?
ans:The @Qualifier annotation is used to resolve the autowiring conflict, when
there are multiple beans of same type.
The @Qualifier annotation can be used on any class annotated with @Component or
on methods annotated with @Bean .
This annotation can also be applied on constructor arguments or method
parameters.
22)Functional Interface?
ans:-Functional interface concept was introduced in Java 8 so before java 8 there
were no restrictions on how many no.s of abstract methods
wore there even before java 8 interfaces do not contain any of the default
method and static methods but with the enhancement of java
8 the functional interface was introduced so the functional interface is an
interface that contains only one abstract method.
There is no restriction for default methods and static methods there can be
any number of default and static methods.Having functional
interface in java is used to refer lambda expression which is the way of
implementing programming interface in java.Some internal functional
interface are runnable,callable,comparable etc.
23)What is excetion and exception handling in java?
ans:-Exception Handling is a mechanism to handle runtime errors such as
ClassNotFoundException, IOException, SQLException, RemoteException,
etc. Exception is an unwanted or unexpected event, which occurs during the
execution of a program i.e at run time, that disrupts the
normal flow of the program's instructions.
24)What is overloading in java?
ans:Overloading is concept in which the method name must be same but arguments must
be different then such method is said to be overloaded.
In overloading method resolution always take by complier so it is also called
as complie time,
E.g:public class Test{
public void m1(){
}
public void m1(int i){
}
Overriding:-Overriding is a concept in which method name must me same and arguments
must be different.As we know that whatever the Parent class
contains automatically avaliable to child class.If we are not satisfied
with the parent class method implementation then we can
overrid that method and we can write our code.
Method Hiding:-Method hinding is a concept in which we can

25)What is immutable?
ans:Once we create an object we are not allowed to change the content if any person
try to modify and if there is a change with those
changes a new object will be created and if there is no changes then that
object is reused.
26)How to create immutable class?
ans: final public class Test{
private int i;
Test(int i){
this.i=i;
}
public Test modify(int i){
if(this.i==i){
return this;
}else{
return new Test(i);
}
}
27)What is the difference between fail fast and fail safe iterator?
ans:FailFast iterator does not allow any modification during iteration process if
we try try to modify it will throw
ConcurrentmodificationException.It requires less memory and hence performance
is faster then FailSafe iterator and no clone object is created
during iteration process.Example HashMap,ArrayList,vector etc
FailSafe iterator allow modification during iteration process and it will not
throw any exception.It requires more memory and hence performance
is slightly slower than failfast.A copy or cloned object will be created during
iteration process in failsafe.Example concurrentHashMap,
copyonwriteArrayList etc.
28)What is the difference between Factory and abstract factory?
ans:The main difference between factory pattern and abstract factory pattern is
that the factory pattern provides a method of creating objects
without specifying the exact class used to create it while the abstract factory
pattern provides a method to combine a group of individual
factories without specifying their concrete classes.
29)Which repository you have used in your project?
ans:JPA repository extends CrudRepository and PagingAndSorting repository. It
inherits some finders from crud repository such as findOne,
gets and removes an entity. It also provides some extra methods related to JPA
such as delete records in batch, flushing data directly to
a database base and methods related to pagination and sorting.
30)What is mean by pagination?
ans:To divide a large number of records into multiple parts, we use pagination. It
allows users to display a part of records only.
Loading all records on a single page may take time, so it is always recommended
to created pagination.
31)@componentScan?
ans:

32)Java 8 features?
ans:The main objective of java 8 is to enable functional programming and to reduce
the line of code through which we can get easyness or
concisness we will get.
Features:
1)Lambda expression:The main objective of Lambda expression is to bring benifits of
functional programming into java.
So the lambda expression is anonymous(Nameless) function
|
without return type
without modififiers
(Such type of terminology it is called as
annonymous function)
Example: If it want to return a square of num to method then,
public int SquareIt(int a){
return a*a;
}
By using lambda expression---- n->n*n
(int a)->{return a*a;}--if we want to return anything then without curly bracket we
can write the code,automatically it will be considered as return type.
(int a)->a*a;

33)MySQL joins?
ans:-There are mainly three types of join
1.Inner join:It gives you exactly matching rows:select* from table1 JOIN table2 ON
table1.columnname=table2.columnname
2:Outerjoin left join:It will return all the records left table and matched records
from right table:-select customer cid,cmane,oamunt LEFTJOIN

3.RightJoin:It will return all the record from the right table and matched recordes
from left table.

34)ConcurrentHashMap?
ans:In concurrentHashMap underlying data structure is hashtable.concurrenthashmap
concurrent read and threadsasfe update operation
To perform read operation thread wont require any lock but to perform any update
operation it requires a lock but it is the lock of particular
part of the map i.e bucketlock.Instead of assigning hole map it is divided into
small parts that is called as concurrencylevel.Hence
concurrenthashmap allows simulteniously read operation and 16
update(write)operations coz its default size is 16.
35)What is marker interface?
ans:Marker interface is an interface in which there is no method or constants i.e
empty method.An empty interface is used to mark or identify
special operations.Example clonable interface is used to mark cloning operation and
serializable interface is used to mark serialization
and deserialization of an object.
36)Factory method in project?
ans:we have 3 type of payment in your e-commerce app (Paypal+we payment + Value
api)
every one of these classes has its own pay method and some of these if you use take
discount.

36)Constructor chaining?
ans:Constructor chaining means calling the one contructor from another constructor.
we can call the constructor by two ways
1.Within the same class by using this().
2.Between a child class to parent class by using super method().
E.g: Class A{ Class B extends A{
A(){ B(){
} this(123); }
A(int x){} B(int x){Super(111);}
} }

37)Throw and throws keyword?


ans:Throw keyword is used to handover the exception to the JVM manually.It is used
inside the method and it is used to through only one
Exception.
Throws is a keyword which is used for only checked exception it is used for
declaration and bypass to the caller.It is used inside the method
It can be used to declare multiple exceptions.We can use throws keyword for only
constructor and methods not for classes.

38)Difference between t.start() and t.run()?


ans:In the case of t.start() a new Thread will be created which is responsible for
the execution of run() method.
But in the case of t.run() no new Thread will be created and run() method will be
executed just like a normal method by the main Thread.
39)What is Agile methodology?
ans:-The Agile methodology is a way to manage a project by breaking it up into
several phases.In agile model both development and testing activities
are concurrent.
Different types of Agile methodology:-
1.Scrum:Scrum is a framework of rules, roles, events, and artifacts used to
implement Agile projects. It is an iterative approach, consisting of
sprints that typically only last one to four weeks. This approach ensures that your
team delivers a version of the product regularly.
40)Example FaceBook?
ans:If we want to build our own facebook then in this case there are so many
requirements we just have to priopritize them for example newsfeed,
chat window is important,showing images n all.Now we have to start working on these
requirement if we are following scrum then it normally go
with sprint it has time limit in which work has to be done normally sprint is of
1,2 or 4weeks.
41)What is ORM framework?
ans:-It is an object relational mapping which is used to map object to the
database.
42)What is JPA?
ans:-What is JPA framework?
The Java Persistence API (JPA) is a specification of Java. It is used to persist
data between Java object and relational database. JPA acts as a
bridge between object-oriented domain models and relational database systems. As
JPA is just a specification, it doesn't perform any operation
by itself.
43)Hibernate advantages over JDBC?
ans:-It provides Automatic table creation.
2)Fast Performance.
3) Database Independent Query.
4)It provides cache support.
disadvantages:-
Hibernate generates lot of SQL statements in runtime based on our mapping , so it
is bit slower than JDBC.
If we use JDBC, then we directly write our queries, so no extra effort is required.
44)Hibernate objects?
ans:

You might also like