Skip to main content

JAVA A to Z Interview Questions Answers2

Servlet interview questions

There is a list of 30 servlet interview questions for beginners and professionals. If you know any servlet interview question that has not been included here, kindly post your question in the Ask Question section.

1) How many objects of a servlet is created?

Only one object at the time of first request by servlet or web container.

2) What is the life-cycle of a servlet?

1.    Servlet is loaded
2.    servlet is instantiated
3.    servlet is initialized
4.    service the request
5.    servlet is destroyed

3) What are the life-cycle methods for a servlet?

Method
Description
public void init(ServletConfig config)
It is invoked only once when first request comes for the servlet. It is used to initialize the servlet.
public void service(ServletRequest request,ServletResponse)throws ServletException,IOException
It is invoked at each request.The service() method is used to service the request.
public void destroy()
It is invoked only once when servlet is unloaded.

4) Who is responsible to create the object of servlet?

The web container or servlet container.

5) When servlet object is created?

At the time of first request.

6) What is difference between Get and Post method?

Get
Post
1) Limited amount of data can be sent because data is sent in header.
Large amount of data can be sent because data is sent in body.
2) Not Secured because data is exposed in URL bar.
Secured because data is not exposed in URL bar.
3) Can be bookmarked
Cannot be bookmarked
4) Idempotent
Non-Idempotent
5) It is more efficient and used than Post
It is less efficient and used

7) What is difference between PrintWriter and ServletOutputStream?

PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class. The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.

8) What is difference between GenericServlet and HttpServlet?

The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol specific. HttpServlet provides additional functionalities such as state management etc.

9) What is servlet collaboration?

When one servlet communicates to another servlet, it is known as servlet collaboration. There are many ways of servlet collaboration:
  • RequestDispacher interface
  • sendRedirect() method etc.

10) What is the purpose of RequestDispatcher Interface?

The RequestDispacher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interceptor can also be used to include the content of antoher resource.

11) Can you call a jsp from the servlet?

Yes, one of the way is RequestDispatcher interface for example:
1.    RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");  
2.    rd.forward(request,response);  

12) Difference between forward() method and sendRedirect() method ?

forward() method
sendRedirect() method
1) forward() sends the same request to another resource.
1) sendRedirect() method sends new request always because it uses the URL bar of the browser.
2) forward() method works at server side.
2) sendRedirect() method works at client side.
3) forward() method works within the server only.
3) sendRedirect() method works within and outside the server.

13) What is difference between ServletConfig and ServletContext?

The container creates object of ServletConfig for each servlet whereas object of ServletContext is created for each web application.

14) What is Session Tracking?

Session simply means a particular interval of time.
Session Tracking is a way to maintain state of an user.Http protocol is a stateless protocol.Each time user requests to the server, server treats the request as the new request.So we need to maintain the state of an user to recognize to particular user.

15) What are Cookies?

A cookie is a small piece of information that is persisted between the multiple client requests. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.

16) What is difference between Cookies and HttpSession?

Cookie works at client side whereas HttpSession works at server side.

17) What is filter?

A filter is an object that is invoked either at the preprocessing or postprocessing of a request. It is pluggable.

18) How can we perform any action at the time of deploying the project?

By the help of ServletContextListener interface.

19) What is the disadvantage of cookies?

It will not work if cookie is disabled from the browser.

20) How can we upload the file to the server using servlet?

One of the way is by MultipartRequest class provided by third party.

21) What is load-on-startup in servlet?

The load-on-startup element of servlet in web.xml is used to load the servlet at the time of deploying the project or server start. So it saves time for the response of first request.

22) What if we pass negative value in load-on-startup?

It will not affect the container, now servlet will be loaded at first request.

23) What is war file?

A war (web archive) file specifies the web elements. A servlet or jsp project can be converted into a war file. Moving one servlet project from one place to another will be fast as it is combined into a single file.

24) How to create war file?

The war file can be created using jar tool found in jdk/bin directory. If you are using Eclipse or Netbeans IDE, you can export your project as a war file.
To create war file from console, you can write following code.
1.    jar -cvf abc.war *  
Now all the files of current directory will be converted into abc.war file.

25) What are the annotations used in Servlet 3?

There are mainly 3 annotations used for the servlet.
1.    @WebServlet : for servlet class.
2.    @WebListener : for listener class.
3.    @WebFilter : for filter class.

26) Which event is fired at the time of project deployment and undeployment?

ServletContextEvent.

27) Which event is fired at the time of session creation and destroy?

HttpSessionEvent.

28) Which event is fired at the time of setting, getting or removing attribute from application scope?

ServletContextAttributeEvent.

29) What is the use of welcome-file-list?

It is used to specify the welcome file for the project.

30) What is the use of attribute in servlets?

Attribute is a map object that can be used to set, get or remove in request, session or application scope. It is mainly used to share information between one servlet to another.

Jsp Interview questions

There is a list of 25 jsp interview questions for freshers and professionals. If you know any jsp interview question that has not been included here, post your question in the Ask Question section.

1)What is JSP?

Java Server Pages technology (JSP) is used to create dynamic web page. It is an extension to the servlet technology. A JSP page is internally converted into servlet.

2) What are the life-cycle methods for a jsp?

Method
Description
public void jspInit()
It is invoked only once, same as init method of servlet.
public void _jspService(ServletRequest request,ServletResponse)throws ServletException,IOException
It is invoked at each request, same as service() method of servlet.
public void jspDestroy()
It is invoked only once, same as destroy() method of servlet.

3)What is difference between hide comment and output comment?

The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown.

4)What are the JSP implicit objects ?

JSP provides 9 implicit objects by default. They are as follows:
Object
Type
1) out
JspWriter
2) request
HttpServletRequest
3) response
HttpServletResponse
4) config
ServletConfig
5) session
HttpSession
6) application
ServletContext
7) pageContext
PageContext
8) page
Object
9) exception
Throwable

5)What is difference between include directive and include action?

include directive
include action
1) The include directive includes the content at page translation time.
1) The include action includes the content at request time.
2) The include directive includes the original content of the page so page size increases at runtime.
2) The include action doesn't include the original content rather invokes the include() method of Vendor provided class.
3) It's better for static pages.
3) It's better for dynamic pages.

6) Is JSP technology extensible?

Yes. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

7) How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" %> within your JSP page.

8) How can I prevent the output of my JSP or Servlet pages from being cached by the browser?

(OR) How to disable caching on back button of the browser?

1.    <%  
2.    response.setHeader("Cache-Control","no-store");   
3.    response.setHeader("Pragma","no-cache");   
4.    response.setHeader ("Expires", "0"); //prevents caching at the proxy server  
5.    %>   

9) How can we handle the exceptions in JSP ?

There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.

10) What are the two ways to include the result of another page. ?

There are two ways to include the result of another page:

11) How can we forward the request from jsp page to the servlet ?

Yes ofcourse! With the help of forward action tag, but we need to give the url-pattern of the servlet.

12) Can we use the exception implicit object in any jsp page ?

No. The exception implicit object can only be used in the error page which defines it with the isErrorPage attribute of page directive.

13) How is JSP used in the MVC model?

JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.

14) What are context initialization parameters?

Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.

15) What are the different scope values for the <jsp:useBean> tag?

There are 4 values:
1.    page
2.    request
3.    session
4.    application

16)What is the difference between ServletContext and PageContext?-

ServletContext gives the information about the container whereas PageContext gives the information about the Request.

17)What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

request.getRequestDispatcher(path) is used in order to create it we need to give the relative path of the resource whereas context.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

18) What is EL in JSP?

The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It provides many objects that can be used directly like param, requestScope, sessionScope, applicationScope, request, session etc.

19)What is basic differences between the JSP custom tags and java beans?

  • Custom tags can manipulate JSP content whereas beans cannot.
  • Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
  • Custom tags require quite a bit more work to set up than do beans.
  • Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

20) Can an interface be implemented in the jsp file ?

No.

21) What is JSTL?

JSP Standard Tag Library is library of predefined tags that ease the development of JSP.

22) How many tags are provided in JSTL?

There are 5 type of JSTL tags.
1.    core tags
2.    sql tags
3.    xml tags
4.    internationalization tags
5.    functions tags

23) Which directive is used in jsp custom tag?

The jsp taglib directive.

24) What are the 3 tags used in JSP bean development?

1.    jsp:useBean
2.    jsp:setProperty
3.    jsp:getProperty

25) How to disable session in JSP?

1.    <%@ page session="false" %>   

EJB Interview Questions

There is given EJB interview questions and answers that has been asked in many companies. Let's see the list of top EJB interview questions.

1) What is EJB?

EJB stands for Enterprise Java Bean. It is a server-side component to develop scalable, robust and secured enterprise applications in java. More details...

2) What are the types of Enterprise Bean?

There are 3 types of enterprise bean in java.
1.    Session Bean
2.    Message Driven Bean
3.    Entity Bean

3) What is session bean?

Session Bean encapsulates business logic. It can be invoked by local, remote or web service client.
There are 3 types of session bean.
1.    Stateless Session Bean
2.    Stateful Session Bean
3.    Singleton Session Bean

4) What is stateless session bean?

Stateless session bean is a business object that doesn't maintain conversational state with the client. More details...

5) What is stateful session bean?

Stateful session bean is a business object that maintains conversational state with the client. More details...

6) What is singleton session bean?

Singleton session bean is instantiated only once for the application. It exists for the life cycle of the application.

7) What is JMS?

Java Message Service is a messaging service to create, send and receive messages asynchronously. More details...

8) What are the advantages of JMS?

  • Asynchronous
  • Reliable

9) What is PTP model?

In Point to Point model, one message is delivered to one receiver only. Here, Queue is used as a message oriented middleware. More details...

10) What is Pub/Sub model?

In Publisher/Subscriber model, one message is delivered to all subscribers. Here, Topic is used as a message oriented middleware. More details...

11) What is MDB?

Message Driven Bean (MDB) encapsulates business logic. It is invoked by passing message. It is like JMS receiver. More details...

12) What is Entity Bean?

Entity Bean is a server side component that represents the persistent data. Since EJB 3.x, it is replaced by JPA. More details...

13) What is Session Facade?

Session Facade is a design pattern to access enterprise bean through local interface. It abstracts the business object interactions and provides a service layer. It makes the performance fast over network.

Struts Interview Questions

There is given frequently asked struts interview questions and answers that has been asked in many companies. Let's see the list of top Struts2 interview questions.

1) What is Struts?

Struts is a framework for developing MVC-based framework. Struts2 is the combination of Webwork and struts1 frameworks. More details...

2) What is the difference between struts1 and struts2?
No.
Struts1
Struts2
1)
Action class is not POJO. You need to inherit abstract class.
Action class is POJO. You don't need to inherit any class or implement any interface.
2)
Front controller is ActionServlet.
Front Controller is StrutsPrepareAndExecuteFilter.
3)
It uses the concept of RequestProcessor class while processing request.
It uses the concept of Interceptors while processing the request.
4)
It has only JSP for the view component.
It has JSP, Freemarker, Valocity etc. for the view component.
5)
Configuration file name can be [anyname].xml and placed inside WEB-INF directory.
Configuration file must be struts.xml and placed inside classes directory.
6)
Action and Model are separate.
Action and Model are combined within action class.

3) What are the features of Struts?

  • Configuration MVC components
  • POJO based action
  • AJAX Support
  • Various Tag Support
  • Various Result Types
  • Integration Support

4) What is MVC?

MVC is a design pattern. MVC stands for Model, View and Controller. Model represents data, view represents presentation and controller acts as an interface between model and view.
Description: mvc architecture

5) What is interceptor?

Interceptor is an object i.e. invoked at preprocessing and postprocessing of a request. It is pluggable. More details...

6) What are the life cycle methods of interceptor?

  • public void init()
  • public void intercept(ActionInvocation ai)
  • public void destroy()

7) What is ValueStack?

ValueStack is a stack that contains application specific object such as action and other model. More details...

8) What is ActionContext?

ActionContext is a container in which action is executed. It is unique per thread. More details...

9) What is ActionInvocation?

ActionInvocation is responsible to invoke action. It holds action and interceptor objects. More details...

10) What is OGNL?

OGNL is an expression language of struts2. It stands for Object Graph Navigation Language. More details...

11) What are the 5 constants of Action interface?

1.    SUCCESS
2.    ERROR
3.    INPUT
4.    LOGIN
5.    NONE

12) What does params interceptor?

The params (also known as parameters) interceptor sets all parameters on the ValueStack. More details...

13) What does execAndWait interceptor?

The execAndWait (also known as ExecuteAndWait) interceptor is used to display intermediate or wait result. More details...

14) What does modelDriven interceptor?

The modelDriven interceptor makes other model as the default object of ValueStack. By default, action is the default object of ValueStack. More details...

15) What does validation interceptor?

The validation interceptor performs validation checks and adds field-level and action-level error messages. More details...

16) What are the bundled validators?

  • requiredstring
  • stringlength
  • email
  • date
  • int
  • double
  • url
  • regex

17) What is the difference between plain-validator and field-validator?

In plain-validator one validator can be applied to many fields. In field-validator many validators can be applied to single field. More details...

18) What is the use of jsonValidation?

The jsonValidation interceptor is used to perform asynchronous validation. It works with validation and workflow interceptors. More details...

19) What are the aware interfaces in struts2?

Aware interfaces are used to store information in request, session, application and response objects. The 4 aware interfaces are given below:
  • ServletRequestAware
  • ServletResponseAware
  • SessionAware
  • ServletContextAware

20) What does i18n interceptor?

The i18n interceptor is used to provide multi lingual support for struts application. More details...

Hibernate Interview Questions

Hibernate interview questions are asked to the students because it is a widely used ORM tool. The important list of top 20 hibernate interview questions and answers for freshers and professionals are given below.

1) What is hibernate?

Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate and retrieve data from the database.

2) What is ORM?

ORM is an acronym for Object/Relational mapping. It is a programming strategy to map object with the data stored in the database. It simplifies data creation, data manipulation and data access.

3) Explain hibernate architecture?

Hibernate architecture comprises of many interfaces such as Configuration, SessionFactory, Session, Transaction etc.

4) What are the core interfaces of Hibernate?

The core interfaces of Hibernate framework are:
  • Configuration
  • SessionFactory
  • Session
  • Query
  • Criteria
  • Transaction

5) What is SessionFactory?

SessionFactory provides the instance of Session. It is a factory of Session. It holds the data of second level cache that is not enabled by default.

6) Is SessionFactory a thread-safe object?

Yes, SessionFactory is a thread-safe object, many threads cannot access it simultaneously.

7) What is Session?

It maintains a connection between hibernate application and database.
It provides methods to store, update, delete or fetch data from the database such as persist(), update(), delete(), load(), get() etc.
It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return these instances.

8) Is Session a thread-safe object?

No, Session is not a thread-safe object, many threads can access it simultaneously. In other words, you can share it between threads.

9) What is the difference between session.save() and session.persist() method?

No.
save()
persist()
1)
returns the identifier (Serializable) of the instance.
return nothing because its return type is void.
2)
Syn: public Serializable save(Object o)
Syn: public void persist(Object o)

10) What is the difference between get and load method?

The differences between get() and load() methods are given below.
No.
get()
load()
1)
Returns null if object is not found.
Throws ObjectNotFoundException if object is not found.
2)
get() method always hit the database.
load() method doesn't hit the database.
3)
It returns real object not proxy.
It returns proxy object.
4)
It should be used if you are not sure about the existence of instance.
It should be used if you are sure that instance exists.

11) What is the difference between update and merge method?

The differences between update() and merge() methods are given below.
No.
update() method
merge() method
1)
Update means to edit something.
Merge means to combine something.
2)
update() should be used if session doesn't contain an already persistent state with same id. It means update should be used inside the session only. After closing the session it will throw error.
merge() should be used if you don't know the state of the session, means you want to make modification at any time.
Let's try to understand the difference by the example given below:
1.    ...  
2.    SessionFactory factory = cfg.buildSessionFactory();  
3.    Session session1 = factory.openSession();  
4.       
5.    Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//passing id of employee  
6.    session1.close();  
7.       
8.    e1.setSalary(70000);  
9.       
10.  Session session2 = factory.openSession();  
11.  Employee e2 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//passing same id  
12.    
13.  Transaction tx=session2.beginTransaction();  
14.  session2.merge(e1);  
15.    
16.  tx.commit();  
17.  session2.close();  
After closing session1, e1 is in detached state. It will not be in session1 cache. So if you call update() method, it will throw an error.
Then, we opened another session and loaded the same Employee instance. If we call merge in session2, changes of e1 will be merged in e2.

12) What are the states of object in hibernate?

There are 3 states of object (instance) in hibernate.
1.    Transient: The object is in transient state if it is just created but has no primary key (identifier) and not associated with session.
2.    Persistent: The object is in persistent state if session is open, and you just saved the instance in the database or retrieved the instance from the database.
3.    Detached: The object is in detached state if session is closed. After detached state, object comes to persistent state if you call lock() or update() method.

13) What are the inheritance mapping strategies?

There are 3 ways of inheritance mapping in hibernate.
1.    Table per hierarchy
2.    Table per concrete class
3.    Table per subclass

14) How to make a immutable class in hibernate?

If you mark a class as mutable="false", class will be treated as an immutable class. By default, it is mutable="true".

15) What is automatic dirty checking in hibernate?

The automatic dirty checking feature of hibernate, calls update statement automatically on the objects that are modified in a transaction.
Let's understand it by the example given below:
1.    ...  
2.    SessionFactory factory = cfg.buildSessionFactory();  
3.    Session session1 = factory.openSession();  
4.    Transaction tx=session2.beginTransaction();  
5.       
6.    Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));  
7.       
8.    e1.setSalary(70000);  
9.       
10.  tx.commit();  
11.  session1.close();  
Here, after getting employee instance e1 and we are changing the state of e1.
After changing the state, we are committing the transaction. In such case, state will be updated automatically. This is known as dirty checking in hibernate.

16) How many types of association mapping are possible in hibernate?

There can be 4 types of association mapping in hibernate.
1.    One to One
2.    One to Many
3.    Many to One
4.    Many to Many

17) Is it possible to perform collection mapping with One-to-One and Many-to-One?

No, collection mapping can only be performed with One-to-Many and Many-to-Many

18) What is lazy loading in hibernate?

Lazy loading in hibernate improves the performance. It loads the child objects on demand.
Since Hibernate 3, lazy loading is enabled by default, you don't need to do lazy="true". It means not to load the child objects when parent is loaded.

19) What is HQL (Hibernate Query Language)?

Hibernate Query Language is known as an object oriented query language. It is like structured query language (SQL).
The main advantage of HQL over SQL is:
1.    You don't need to learn SQL
2.    Database independent
3.    Simple to write query

20) What is the difference between first level cache and second level cache?

No.
First Level Cache
Second Level Cache
1)
First Level Cache is associated with Session.
Second Level Cache is associated with SessionFactory.
2)
It is enabled by default.
It is not enabled by default.

Spring Interview Questions

Spring interview questions and answers are frequently asked because it is now widely used framework to develop enterprise application in java. There are given a list of top 40 frequently asked spring interview questions.

1) What is Spring?

It is a lightweight, loosely coupled and integrated framework for developing enterprise applications in java.

2) What are the advantages of spring framework?

1.    Predefined Templates
2.    Loose Coupling
3.    Easy to test
4.    Lightweight
5.    Fast Development
6.    Powerful Abstraction
7.    Declarative support

3) What are the modules of spring framework?

1.    Test
2.    Spring Core Container
3.    AOP, Aspects and Instrumentation
4.    Data Access/Integration
5.    Web

4) What is IOC and DI?

IOC (Inversion of Control) and DI (Dependency Injection) is a design pattern to provide loose coupling. It removes the dependency from the program.
Let's write a code without following IOC and DI.
1.    public class Employee{  
2.    Address address;  
3.    Employee(){  
4.    address=new Address();//creating instance  
5.    }  
6.    }  
Now, there is dependency between Employee and Address because Employee is forced to use the same address instance.
Let's write the IOC or DI code.
1.    public class Employee{  
2.    Address address;  
3.    Employee(Address address){  
4.    this.address=address;//not creating instance  
5.    }  
6.    }  
Now, there is no dependency between Employee and Address because Employee is not forced to use the same address instance. It can use any address instance.

5) What is the role of IOC container in spring?

IOC container is responsible to:
  • create the instance
  • configure the instance, and
  • assemble the dependencies

6) What are the types of IOC container in spring?

There are two types of IOC containers in spring framework.
1.    BeanFactory
2.    ApplicationContext

7) What is the difference between BeanFactory and ApplicationContext?

BeanFactory is the basic container whereas ApplicationContext is the advanced container. ApplicationContext extends the BeanFactory interface. ApplicationContext provides more facilities than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.

8) What is the difference between constructor injection and setter injection?

No.
Constructor Injection
Setter Injection
1)
No Partial Injection
Partial Injection
2)
Desn't override the setter property
Overrides the constructor property if both are defined.
3)
Creates new instance if any modification occurs
Doesn't create new instance if you change the property value
4)
Better for too many properties
Better for few properties.

9) What is autowiring in spring? What are the autowiring modes?

Autowiring enables the programmer to inject the bean automatically. We don't need to write explicit injection logic.
Let's see the code to inject bean using dependency injection.
1.    <bean id="emp" class="com.javatpoint.Employee" autowire="byName" />  
The autowiring modes are given below:
No.
Mode
Description
1)
no
this is the default mode, it means autowiring is not enabled.
2)
byName
injects the bean based on the property name. It uses setter method.
3)
byType
injects the bean based on the property type. It uses setter method.
4)
constructor
It injects the bean using constructor
The "autodetect" mode is deprecated since spring 3.

10) What are the different bean scopes in spring?

There are 5 bean scopes in spring framework.
No.
Scope
Description
1)
singleton
The bean instance will be only once and same instance will be returned by the IOC container. It is the default scope.
2)
prototype
The bean instance will be created each time when requested.
3)
request
The bean instance will be created per HTTP request.
4)
session
The bean instance will be created per HTTP session.
5)
globalsession
The bean instance will be created per HTTP global session. It can be used in portlet context only.

11) In which scenario, you will use singleton and prototype scope?

Singleton scope should be used with EJB stateless session bean and prototype scope with EJB stateful session bean.

12) What are the transaction management supports provided by spring?

Spring framework provides two type of transaction management supports:
1.    Programmatic Transaction Management: should be used for few transaction operations.
2.    Declarative Transaction Management: should be used for many transaction operations.

» Spring JDBC Interview Questions


13) What are the advantages of JdbcTemplate in spring?

Less code: By using the JdbcTemplate class, you don't need to create connection,statement,start transaction,commit transaction and close connection to execute different queries. You can execute the query directly.

14) What are classes for spring JDBC API?

1.    JdbcTemplate
2.    SimpleJdbcTemplate
3.    NamedParameterJdbcTemplate
4.    SimpleJdbcInsert
5.    SimpleJdbcCall

15) How can you fetch records by spring JdbcTemplate?

You can fetch records from the database by the query method of JdbcTemplate. There are two interfaces to do this:
2.    RowMapper

16) What is the advantage of NamedParameterJdbcTemplate?

NamedParameterJdbcTemplate class is used to pass value to the named parameter. A named parameter is better than ? (question mark of PreparedStatement).
It is better to remember.

17) What is the advantage of SimpleJdbcTemplate?

The SimpleJdbcTemplate supports the feature of var-args and autoboxing.

» Spring AOP Interview Questions


18) What is AOP?

AOP is an acronym for Aspect Oriented Programming. It is a methodology that divides the program logic into pieces or parts or concerns.
It increases the modularity and the key unit is Aspect.

19) What are the advantages of spring AOP?

AOP enables you to dynamically add or remove concern before or after the business logic. It is pluggable and easy to maintain.

20) What are the AOP terminology?

AOP terminologies or concepts are as follows:
  • JoinPoint
  • Advice
  • Pointcut
  • Aspect
  • Introduction
  • Target Object
  • Interceptor
  • AOP Proxy
  • Weaving

21) What is JoinPoint?

JoinPoint is any point in your program such as field access, method execution, exception handling etc.

22) Does spring framework support all JoinPoints?

No, spring framework supports method execution joinpoint only.

23) What is Advice?

Advice represents action taken by aspect.

24) What are the types of advice in AOP?

There are 5 types of advices in spring AOP.
1.    Before Advice
2.    After Advice
3.    After Returning Advice
4.    Throws Advice
5.    Around Advice

25) What is Pointcut?

Pointcut is expression language of Spring AOP.

26) What is Aspect?

Aspect is a class in spring AOP that contains advices and joinpoints.

27) What is Introduction?

Introduction represents introduction of new fields and methods for a type.

28) What is target object?

Target Object is a proxy object that is advised by one or more aspects.

29) What is interceptor?

Interceptor is a class like aspect that contains one advice only.

30) What is weaving?

Weaving is a process of linking aspect with other application.

31) Does spring perform weaving at compile time?

No, spring framework performs weaving at runtime.

32) What are the AOP implementation?

There are 3 AOP implementation.
1.    Spring AOP
2.    Apache AspectJ
3.    JBoss AOP

» Spring MVC Interview Questions


33) What is the front controller class of Spring MVC?

The DispatcherServlet class works as the front controller in Spring MVC.

34) What does @Controller annotation?

The @Controller annotation marks the class as controller class. It is applied on the class.

35) What does @RequestMapping annotation?

The @RequestMapping annotation maps the request with the method. It is applied on the method.

36) What does the ViewResolver class?

The View Resolver class resolves the view component to be invoked for the request. It defines prefix and suffix properties to resolve the view component.

37) Which ViewResolver class is widely used?

The org.springframework.web.servlet.view.InternalResourceViewResolver class is widely used.

38) Does spring MVC provide validation support?


Yes.

Comments

Popular posts from this blog

Mockito interview Questions

1.       Question 1. What Is Mockito? Answer : Mockito allows creation of mock object for the purpose of Test Driven Development and Behavior Driven development. Unlike creating actual object, Mockito allows creation of fake object (external dependencies) which allows it to give consistent results to a given invocation. 2.       Question 2. Why Do We Need Mockito? What Are The Advantages? Answer : Mockito differentiates itself from the other testing framework by removing the expectation beforehand. So, by doing this, it reduces the coupling. Most of the testing framework works on the "expect-run-verify". Mockito allows it to make it "run-verify" framework. Mockito also provides annotation which allows to reduce the boilerplate code. 3.       Question 3. Can You Explain A Mockito Framework? Answer : In Mockito, you always check a particular class. The dependency in that class is injected using mock object. So, for example, if you have service class

JAVA Expert Interview Questions Answers 2017

Java Basics ::  Interview Questions and Answers Home  »  Interview Questions  »  Technical Interview  »  Java Basics  » Interview Questions 1.     What is the difference between a constructor and a method? A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. 2.     What is the purpose of garbage collection in Java, and when is it used? The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. 3.     Describe synchronization in respect to multithreading. With respect to

Java Example Program to Convert List to Set

import java.util.ArrayList; import java.util.HashSet; import java.util.Set; public class ListToSet {  /**   * @author Amarjit Kumar   * @category interview questions   *   * Description: Convert List to set in java with example program   *   */  public static void main(String[] args) {   ArrayList<String> arrList= new ArrayList<>();   arrList.add("Java");   arrList.add("Java");   arrList.add("List to String");   arrList.add("Example Program");   Set<String> strSet = new HashSet<String>(arrList);   System.out.println(strSet);   System.out.println(arrList);  } } /*  * Java program to convert list to set. Convert ArrayList of string to HashSet  * in java example program How to convert List to Set in java Set<String> strSet  * = new HashSet<String>(arrList); HashSet having a constructor which will take  * list as an argument. Lets see how to convert list to Set using java program.