YouTube Icon

Interview Questions.

Top 50 Java & Ejb & Spring Interview Questions - Jul 26, 2022

fluid

Top 50 Java & Ejb & Spring Interview Questions

Q1. What Is Message Driven Bean In Ejb?

A message pushed bean is a form of agency bean that is invoked via EJB box while it receives a message from queue or subject matter. Message pushed bean is a stateless bean and is used to do assignment asynchronously.

 

Q2. What Are The Benefits Of Ejb?

Following are the key blessings of EJB.

Simplified improvement of large scale agency level application.

Application Server/ EJB container presents most of the device level services like traction coping with, logging, load balancing, patience mechanism, exception coping with and so on. Developer has to recognition handiest on enterprise common sense of the software.

EJB box manages existence cycle of ejb instances as a result developer needs no longer to worry about whilst to create/delete ejb gadgets.
 

Q3. What Is Class Level Interceptor In Ejb?

Class stage interceptor is invoked for each method of the bean. Class stage interceptor can be applied both with the aid of annotation or via xml(ejb-jar.Xml).

Q4. What Is A Session Bean In Ejb?

Session bean shops facts of a selected consumer for a single consultation. It may be stateful or stateless. It is much less aid intensive compared to entity be. Session bean gets destroyed as soon as consumer consultation terminates.

Q5. What Is Abstraction?

It refers back to the capability to make a class abstract in OOP. It enables to lessen the complexity and also improves the maintainability of the system.

Q6. What Are The Benefits Of Ioc?

IOC or dependency injection minimizes the amount of code in an utility. It makes clean to check programs, since no singletons or JNDI research mechanisms are required in unit exams. Loose coupling is promoted with minimum attempt and least intrusive mechanism. IOC packing containers assist eager instantiation and lazy loading of offerings.

Q7. Explain The Aop Module

The AOP module is used for growing aspects for our Spring-enabled application. Much of the help has been supplied with the aid of the AOP Alliance in an effort to ensure the interoperability between Spring and different AOP frameworks. This module also introduces metadata programming to Spring.

Q8. What Are The Common Implementations Of The Applicationcontext?

The FileSystemXmlApplicationContext box loads the definitions of the be from an XML record. The complete direction of the XML bean configuration file should be supplied to the constructor.

The ClassPathXmlApplicationContext box also loads the definitions of the be from an XML document. Here, you need to set CLASSPATH properly because this container will look bean configuration XML record in CLASSPATH.

The WebXmlApplicationContext: field loads the XML report with definitions of all be from inside a web software.

Q9. Explain The Jdbc Abstraction And Dao Module

With the JDBC abstraction and DAO module we may be certain that we preserve up the database code smooth and easy, and save you issues that result from a failure to shut database resources. It offers a layer of significant exceptions on top of the mistake messages given via numerous database servers. It also uses Spring’s AOP module to offer traction control services for gadgets in a Spring utility.

Q10. Which Types Of Exceptions Are Caught At Compile Time?

Checked exceptions can be caught on the time of application compilation. Checked exceptions should be handled with the aid of the use of strive trap block within the code so one can successfully compile the code.

Q11. A Person Says That He Compiled A Java Class Successfully Without Even Having A Main Method In It? Is It Possible?

Main method is an entry point of Java magnificence and is needed for execution of this system but; a category receives compiled effectively despite the fact that it doesn’t have a primary approach. It can’t be run although.

Q12. Can Variables Be Used In Java Without Initialization?

In Java, if a variable is utilized in a code with out previous initialization by a valid price, application doesn’t assemble and gives an error as no default value is assigned to variables in Java.

Q13. When Abstract Methods Are Used?

If you need a category to comprise a particular approach however you want the real implementation of that approach to be decided by using infant training, you can declare the approach within the determine magnificence as summary.

Q14. What Is Stateless Session Bean In Ejb?

A stateless session bean is a kind of business enterprise bean which is normally used to do impartial operations. A stateless session bean as in line with its call does now not have any associated consumer state, but it may keep its instance country. EJB Container commonly creates a pool of few stateless bean's gadgets and use those gadgets to manner consumer's request. Because of pool, instance variable values aren't guaranteed to be identical throughout lookups/method calls.

Q15. What Is An Interface?

An interface is a set of summary techniques. A elegance implements an interface, thereby inheriting the summary methods of the interface.

Q16. What Is Spring Configuration File?

Spring configuration record is an XML document. This file incorporates the instructions data and describes how these instructions are configured and brought to every other.

Q17. What Is Stateful Session Bean In Ejb?

A stateful session bean is a kind of agency bean which keep the conversational nation with consumer. A stateful consultation bean as according to its name keeps related patron country in its example variables. EJB Container creates a separate stateful session bean to process client's each request. As quickly as request scope is over, statelful consultation bean is destroyed.

Q18. How Jdbc Can Be Used More Efficiently In Spring Framework?

JDBC may be used extra effectively with the assist of a template class furnished through spring framework known as as JdbcTemplate.

Q19. How Jdbctemplate Can Be Used?

With use of Spring JDBC framework the load of useful resource management and error handling is decreased loads. So it leaves developers to put in writing the statements and queries to get the facts to and from the database. JdbcTemplate offers many convenience methods for doing things which include converting database statistics into primitives or items, executing prepared and callable statements, and presenting custom database blunders managing.

Q20. Describe Different States Of A Thread.

A thread in Java can be in either of the subsequent states:

Ready: When a thread is created, it’s in Ready nation.

Running: A thread presently being done is in jogging kingdom.

Waiting: A thread looking forward to every other thread to unfastened certain assets is in waiting state.

Dead: A thread which has long gone dead after execution is in useless state.

Q21. What Is A Traction?

A traction is a single unit of work gadgets which follows the ACID properties. ACID stands for Atomic, Consistent,Isolated and Durable.

Q22. Explain

@javax.Ejb.MessageDrivenBean annotation specifies that a given ejb magnificence is a message pushed bean. Following are its attributes:

call - Used to specify call of the message driven bean.

MessageListenerInterface - Used to specify message listener interface for the message driven bean.

ActivationConfig - Used to specify the configuration information of the message-pushed bean in operational environment of the message pushed bean.

MappedName - Used to specify the JNDI name of the message pushed bean.

Description - Used to offer description of the message pushed bean.

Q23. What Is Entity Bean In Ejb?

Entity be represents chronic facts garage. User statistics can be stored to database via entity be and afterward can be retrived from the database within the entity bean.

Q24. Can A Dead Thread Be Started Again?

In java, a thread that is in dead kingdom can’t be commenced once more. There is not any way to restart a dead thread.

Q25. When Throws Keyword Is Used?

If a way does now not cope with a checked exception, the method need to declare it using the throwskeyword. The throws keyword seems on the give up of a way's signature..

Q26. How Can We Use Primitive Data Types As Objects?

Primitive records sorts like int may be treated as objects via the use of their respective wrapper instructions. For instance, Integer is a wrapper magnificence for primitive data type int. We can follow extraordinary methods to a wrapper magnificence, similar to another item.

Q27. When Super Keyword Is Used?

If the method overrides considered one of its superclass's methods, overridden method can be invoked thru the usage of the key-word super. It can be also used to consult a hidden discipline.

Q28. Explain

@javax.Ejb.Local annotation is used to specify Local interface(s) of a session bean. This neighborhood interface states the commercial enterprise techniques of the consultation bean (which can be stateless or stateful).

This interface is used to reveal the commercial enterprise strategies to nearby clients which can be jogging in equal deployment/software as EJB.

Following are its attributes:

price - Used to specify the listing of local interfaces as an array of interfaces.

Q29. Explain

@javax.Ejb.Stateless annotation specifies that a given ejb magnificence is a stateless consultation bean.Following are its attributes:

call - Used to specify name of the session bean.

MappedName - Used to specify the JNDI call of the session bean.

Description - Used to offer description of the consultation bean.

Q30. What Are The Differences Between Stateful Session Bean And Stateless Session Bean?

Following are the differences between stateful consultation bean and stateless consultation bean:

EJB Container creates a separate stateful consultation bean to procedure patron's every request.While EJB Container generally creates a pool of few stateless bean's objects and use these items to technique customer's request.

As quickly as request scope is over, statelful consultation bean is destroyed but stateless bean remains active.

A stateful consultation bean is a form of business enterprise bean which keep the conversational nation with purchaser. A stateful session bean as according to its name maintains related purchaser kingdom in its example variables Whereas due to pool of stateless consultation be, instance variable values are not guaranteed to be identical throughout lookups/method calls in stateless consultation be.

Q31. Can A Class In Java Be Inherited From More Than One Class?

In Java, a category may be derived from only one magnificence and no longer from multiple classes. Multiple inheritances isn't always supported by means of Java.

Q32. Explain The Object/relational Mapping Integration Module

Spring also helps for the usage of of an item/relational mapping (ORM) tool over instantly JDBC by means of offering the ORM module. Spring provides guide to tie into several famous ORM frameworks, together with Hibernate, JDO, and iBATIS SQL Maps. Spring’s traction management helps each of those ORM frameworks as well as JDBC.

Q33. Explain The Spring Mvc Module

MVC framework is furnished by means of Spring for constructing web applications. Spring can effortlessly be incorporated with other MVC frameworks, but Spring’s MVC framework is a higher choice, because it makes use of IoC to offer for a easy separation of controller good judgment from enterprise items. With Spring MVC you could declaratively bind request parameters in your business items.

Q34. Which Are The Spring Framework Modules?

The simple modules of the Spring framework are :

Core module

Bean module

Context module

Expression Language module

JDBC module

ORM module

OXM module

Java Messaging Service(JMS) module

Traction module

Web module

Web-Servlet module

Web-Struts module

Web-Portlet module

Q35. What Are The Key Components Of Persistence Api In Ejb?

Following are the key components of persistence API in EJB:

Entity - A continual object representing the information-save document. It is ideal to be serializable.

EntityManager - Persistence interface to do facts operations like upload/delete/update/locate on chronic object(entity). It also allows to execute queries the use of Query interface.

Persistence unit (persistence.Xml) - Persistence unit describes the properties of persistence mechanism.

Data Source (*ds.Xml) - Data Source describes the statistics-keep related properties like connection url. User-call,password and many others.

Q36. What Is Default Interceptor In Ejb?

Default interceptor is invoked for each bean inside deployment.Default interceptor can be implemented only through xml (ejb-jar.Xml).

Q37. What Are The Types Of Advice?

Spring components can work with five kinds of recommendation stated beneath:

earlier than: Run recommendation before the a method execution.

After: Run recommendation after the a technique execution no matter its outcome.

After-returning: Run advice after the a way execution simplest if technique completes efficiently.

After-throwing: Run recommendation after the a technique execution only if method exits with the aid of throwing an exception.

Around: Run advice earlier than and after the recommended technique is invoked.

 

Q38. What A Remote Session Bean Is Used In Ejb?

If ejb customer is in unique surroundings wherein ejb session bean is to be deployed then we use far off consultation bean.

Q39. How Finally Used Under Exception Handling?

The in the end key-word is used to create a block of code that follows a attempt block. A ultimately block of code usually executes, whether or no longer an exception has befell.

Q40. What Is Method Level Interceptor In Ejb?

Method degree interceptor is invoked for a selected approach of the bean. Method level interceptor can be implemented both with the aid of annotation of thru xml(ejb-jar.Xml).

Q41. What Is Abstract Class?

These training can not be instantiated and are both partly applied or never implemented. This class incorporates one or greater summary strategies which are simply technique declarations without a frame.

Q42. Explain

EJB 3.Zero offers option to embed JAVA POJO (Plain Old Java Object) into an entity bean and lets in to map column names with the strategies of the embedded POJO elegance. A java POJO to be embedded ought to be annotated as @Embeddable.

Q43. Can We Call A Non-static Method From Inside A Static Method?

Non-Static strategies are owned by way of items of a category and have object stage scope and in order to call the non-Static strategies from a static block (like from a static fundamental technique), an item of the elegance wishes to be created first. Then using item reference, those methods can be invoked.

 

Q44. Is Message Driven Bean A Stateless Bean?

Message pushed bean is a stateless bean and is used to do undertaking asynchronously.

Q45. Which Are The Two Subclasses Under Exception Class?

The Exception elegance has two major subclasses : IOException class and RuntimeException Class

Q46. Explain The Core Container (application Context) Module?

This is the fundamental Spring module, which provides the fundamental capability of the Spring framework. BeanFactory is the coronary heart of any spring-based totally application. Spring framework became constructed on the top of this module, which makes the Spring container.

Q47. Can We Use Goto In Java To Go To A Particular Line?

In Java, there is not goto key-word and java doesn’t aid this feature of going to a particular classified line.

 

Q48. What Does A Spring Application Look Like?

An interface that defines the functions.

The implementation that includes residences, its setter and getter methods, capabilities etc.,Spring AOP 

The Spring configuration XML file.

Client application that makes use of the characteristic

Q49. When Throw Keyword Is Used?

An exception can be thrown, either a newly instantiated one or an exception which you just caught, with the aid of the usage of throw keyword.

Q50. Can A Constructor Have Different Name Than A Class Name In Java?

Constructor in Java ought to have equal name because the elegance call and if the name is distinctive, it doesn’t act as a constructor and compiler thinks of it as a normal method.




CFG