EJB interview question set 1 /EJB Interview Questions and Answers for Freshers & Experienced

What Is Java?What Is The Relationship Between An Event-listener Interface And An Event-adapter Class?



An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

Posted Date:- 2021-09-04 07:41:22

What Does A Well-written Oo Program Look Like?

A well-written OO program exhibits recurring structures that promote abstraction, flexibility, modularity and elegance.

Posted Date:- 2021-09-04 07:39:58

What Is More Advisable To Create A Thread, By Implementing A Runnable Interface Or By Extending Thread Class?

Strategically speaking, threads created by implementing Runnable interface are more advisable. If you create a thread by extending a thread class, you cannot extend any other class. If you create a thread by implementing Runnable interface, you save a space for your class to extend another class now or in future.

Posted Date:- 2021-09-04 07:38:34

How Could Java Classes Direct Program Messages To The System Console, But Error Messages, Say To A File?

The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:
Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);

Posted Date:- 2021-09-04 07:37:08

What's The Difference Between An Interface And An Abstract Class?

An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

Posted Date:- 2021-09-04 07:36:19

Difference Between ejbStore() and ejbLoad()?

One more popular EJB interview question, not seen through it for some time but still an important question on EJB to prepare.

Ans: Both of these methods are used in the context of entity bean for the purpose of synchronizing the instance variable to the corresponding value store in the database. ejbLoad method load or refresh the instance variable from the database and ejbStore method writes variables value back to the database.

Posted Date:- 2021-09-04 07:35:15

Is threading is possible in EJB?

No, Not possible because EJBs are created and managed by container and if in ejbs we allow threading containers life cycle methods will be interrupted by us and also the purpose of EJB is to perform business logic not to controlling a system or implementation level functioning so container will manage the thread and developer can concentrate on business logic.

Posted Date:- 2021-09-04 07:34:34

What are the issues you face with EJB 3.0 ?


These were some of the EJB interview questions for practice if you are going to appear in any Java or J2EE interview which requires EJB skills. There are not many J2EE programmer who understand and use EJB very well. It was more difficult when EJB 2.0 was around but much better with EJB 3.0 and EJB 3.1. Please share if you have any other interesting EJB interview question or if you know answer of any EJB question shared here.

Posted Date:- 2021-09-04 07:33:30

Is Decorator An Ejb Design Pattern?

No. Decorator design pattern, is the one which exhibits very low level runtime polymorphism, for the specific and single object (Instance of the class), but not for atleast for a class. It is the stuff to add specific functionality to a single & pointed object and leaves others like it unmodified. It is having close similarities like aspectJ stuff, but not with EJB stuff.

Posted Date:- 2021-09-04 07:32:05

Why Does Ejb Needs Two Interfaces(home And Remote Interface)

There is a pure division of roles between the two. Home Interface is the way to communicate with the container which is responsible for creating , locating and removing beans and Remote Interface is the link to the bean that allows acces to all methods and members.

Posted Date:- 2021-09-04 07:30:58

What is the difference between EJB and J2EE?

J2EE is a platform for developing distributed enterprise applications that have many features lime security, state management, resource management, transaction management, etc. EJB is a part of J2EE that is an API used for developing enterprise applications. EJB make the application scalable.

Posted Date:- 2021-09-04 07:29:49

Why should we use EJB over Spring?

The reasons to choose EJB over Spring bean are as follows:

EJB has better support for Web services like JAS-WS 2.0 than
Messaging is easy in EJB through Message Driven beans whereas Spring needs to be configured for messaging.

EJB provides better security through JAAS whereas configuration needs to be added to Spring.

Posted Date:- 2021-09-04 07:29:08

Where is ejb-jar.xml located?

The ejb-jar.xml file is located in the following places:

>> In case of a WAR, it is located in the /WEB-INF directory.
>> In case of a JAR, it is located in the /META-INF directory.

Posted Date:- 2021-09-04 07:28:29

What is a home interface in EJB?

The home interface is an interface that has methods that can be associated with all EJB of a class. It specifies the methods used by a client for developing and retrieving a bean instance. For creating a bean instance, the create method is used. For every creates method an ejbCreate method has to be defined.

Posted Date:- 2021-09-04 07:27:22

How to check the EJB version?

The EJB version can be checked by the following ways:

>> The EJB-jar.xml and application.xml file have to be checked. The version is present in the beginning lines of the XML file.
>> The ejb-jar.xml deployment descriptor can be used to find the version of EJB.

Posted Date:- 2021-09-04 07:26:52

Which EJB protocol is used for communication?

EJB uses the RMI-IIOP protocol that stands for Internet Inter-ORB Protocol is used for communication that uses a Common Object Request Broker Architecture (CORBA). The IIOP protocol is used for distributed communication and can be executed on all platforms. Here RMI stands for Remote Method Invocation that is used for transferring messages from one JVM to another over a network.

Posted Date:- 2021-09-04 07:26:07

Why don’t we use static in Java EE EJB?

Static class fields that are not final are not allowed in EJB because they make it very difficult to distribute. These static class can behave differently when they run in a single JVM (Java Virtual Machine) which can create problems.

Posted Date:- 2021-09-04 07:25:33

What Is Remote Client View?



The remote client view specification is only available in EJB 2.0. The remote client view of an enterprise bean is location independent. A client running in the same JVM as a bean instance uses the same API to access the bean as a client running in a different JVM on the same or different machine.

Remote interface: The remote interface specifies the remote business methods that a client can call on an enterprise bean.
Remote home interface: The remote home interface specifies the methods used by remote clients for locating, creating, and removing instances of enterprise bean classes.

Posted Date:- 2021-09-04 07:24:35

What Is Local Client View?

The local client view specification is only available in EJB 2.0. Unlike the remote client view, the local client view of a bean is location dependent. Local client view access to an enterprise bean requires both the local client and the enterprise bean that provides the local client view to be in the same JVM. The local client view therefore does not provide the location transparency provided by the remote client view. Local interfaces and local home interfaces provide support for lightweight access from enterprise bean that are local clients. Session and entity beans can be tightly couple with their clients, allowing access without the overhead typically associated with remote method calls.

Posted Date:- 2021-09-04 07:23:50

How is consistency maintained by Stateful Session through transaction updates ?

The data consistency is maintained by updating their fields every time a commitment of the transaction is made.

Posted Date:- 2021-09-04 07:22:34

Which is more beneficial: CMP or BMP?

When “one to one” mapping is involved, and the data is stored persistently is regional database, CMP is preferred. But when no “one to one” mapping is there and data is retrieved from numerous tables having a complex query, Bean Managed Persistence is used.

Posted Date:- 2021-09-04 07:22:10

What Is Deployment Descriptor?

A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR file or an EAR file. It contains metadata describing the contents and structure of the enterprise beans, and runtime transaction and security information for the EJB container.

Posted Date:- 2021-09-04 07:18:03

Static variables in EJB should not be relied upon as they may break in clusters.Why?

Static variables are only ok if they are final. If they are not final, they will break the cluster. What that means is that if you cluster your application server (spread it across several machines) each part of the cluster will run in its own JVM.
Say a method on the EJB is invoked on cluster 1 (we will have two clusters – 1 and 2) that causes value of the static variable to be increased to 101. On the subsequent call to the same EJB from the same client, a cluster 2 may be invoked to handle the request. A value of the static variable in cluster 2 is still 100 because it was not increased yet and therefore your application ceases to be consistent. Therefore, static non-final variables are strongly discouraged in EJBs.

Posted Date:- 2021-09-04 07:15:31

Enlist the changes in EJB 2.1 ?

The changes made are:

>> Message Driven Beans (MDBs): messages are accepted from other >> sources besides JMS.
>> EJB Query Language: New functions had been added.
>> Web services supported.
>> EJB Timer Service: Mechanism based on an event to invoke EJBs at particular times.
>> XML schema
>> Message destinations

Posted Date:- 2021-09-04 07:12:56

What Is The Difference Between Ear, Jar And War File?


Modules are packaged based on their functionality as EAR, JAR and WAR files.

JAR files (.jar) : Modules which contain EJB class files and EJB deployment descriptor are packed as JAR files.
WAR Files (.war) : Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as JAR file.
EAR Files (.ear) : ‘.jar’ & ‘.war’ files are packaged as JAR files. ‘Ear’ stands for enterprise archive. These files are deployed in the application server.

Posted Date:- 2021-09-04 07:11:27

Differentiate ‘stateful Session’ From ‘entity Bean’?

While both undergo activation and passivation; EB have ejbStore () callback to save state through passivation and ejbLoad () callback to load state through activation. But in case of SS, this is not needed because S.S.B fields are serialized through objects by containers.

Posted Date:- 2021-09-04 07:09:47

What Is Lazy Loading?

Heavy weight application consume a lot of time while loading the plug-ins. In lazy loading approach, the plug-ins that are needed at that particular time are loaded and instantiated. This boosts up the performance as only the plug-ins that are used are loaded. This also ensures the efficiency and speeds up the initial load time of the applications. Applications like Eclipse use this approach. In other words, the goal of lazy loading is to dedicate memory only when it is absolutely necessary.

Posted Date:- 2021-09-04 07:08:10

What Is Ejb Ql?

EJB QL stands for Enterprise Java Beans - Query Language. It was introduced in the EJB 2.0 specification. QL provides navigation across network of EJBs and dependent objects which are defined by means of container managed persistence. Persistence is the ability to save the current state of a bean. EJB QL is portable across containers and persistence managers.

Finder Methods: These are defined in the home interface of an entity bean and which return entity objects.
Select methods: These are not exposed to the client. However, these are used by bean providers to select persistence values or entity objects related to entity bean which the query is defined on.

Posted Date:- 2021-09-04 07:07:45

Which Is More Beneficial: Cmp Or Bmp?

When “one to one” mapping is involved, and the data is stored persistently is regional database, CMP is preferred. But when no “one to one” mapping is there and data is retrieved from numerous tables having a complex query, Bean Managed Persistence is used.

Posted Date:- 2021-09-04 07:07:15

Can I develop an Entity Bean without implementing the create() method in the home interface?

As per the specifications, there can be ‘ZERO’ or ‘MORE’ create() methods defined in an Entity Bean. In cases where create() method is not provided, the only way to access the bean is by knowing its primary key, and by acquiring a handle to it by using its corresponding finder method. In those cases, you can create an instance of a bean based on the data present in the table. All one needs to know is the primary key of that table. i.e. a set a columns that uniquely identify a single row in that table. Once this is known, one can use the ‘getPrimaryKey()’ to get a remote reference to that bean, which can further be used to invoke business methods.

Posted Date:- 2021-09-04 07:05:35

What are transaction attributes?

The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean’s home or component interface or when the method is invoked as the result of the arrival of a JMS message. (Sun’s EJB Specification) Below is a list of transactional attributes:

1. NotSupported – transaction context is unspecified.
2. Required – bean’s method invocation is made within a transactional context. If a client is not associated with a transaction, a new transaction is invoked automatically.
3. Supports – if a transactional context exists, a Container acts like the transaction attribute is Required, else – like NotSupported.
4. RequiresNew – a method is invoked in a new transaction context.
5. Mandatory – if a transactional context exists, a Container acts like the transaction attribute is Required, else it throws a javax.ejb.TransactionRequiredException.
6. Never – a method executes only if no transaction context is specified.

Posted Date:- 2021-09-04 07:05:11

What is meant by POJO class in Java?

Acronym for Plain Old Java Object. POJO, or Plain Old Java Object, is a normalJava object class (that is, not a JavaBean, EntityBean etc.) and does not serve any other special role nor does it implement any special interfaces of any of the Javaframeworks.
Following are the key components of persistence API in EJB:

Entity – A persistent object representing the data-store record. It is good to be serializable.
EntityManager – Persistence interface to do data operations like add/delete/update/find on persistent object(entity). It also helps to execute queries using Query interface.
Persistence unit (persistence.xml) – Persistence unit describes the properties of persistence mechanism.
Data Source (*ds.xml) – Data Source describes the data-store related properties like connection url. user-name,password etc.

Posted Date:- 2021-09-04 07:04:45

What is advantage of putting business logic in EJB over stored procedure?

This is another tough Java question on EJB interview. Putting complex business logic in stored procedure is not a good idea but its been there for long time. Main advantage of using EJB over stored procedure is that you don't need to port your SQL Stored procedure code when you change database e.g. form Sybase to Oracle or Oracle to SQL Server.

Posted Date:- 2021-09-04 07:00:40

What was shortcomings of EJB 2.0 ?

If you have mentioned in your resume that you have worked on EJB 2.0, then better be prepared for this EJB interview question. It's not difficult to answer if you have indeed worked in EJB 2.0. There are several pain e.g. writing those local and remote interfaces, too many boiler plate coding etc.

Posted Date:- 2021-09-04 07:00:08

Can we run EJB in web server like Tomcat ?

One of the tricky interview question on EJB. No you can not run EJB in web server like Tomcat. You need application server like Glassfish, WebLogic or Websphere to run Enterprise Java beans.

Posted Date:- 2021-09-04 06:59:39

Enlist the Declarative Transaction types?

They are:

>> MANDATORY:
>> REQUIRED
>> REQUIRES_NEW
>> SUPPORTS
>> NOT_SUPPORTED
>> NEVER

Posted Date:- 2021-09-04 06:58:33

Describe The Life Cycle For Stateful Beans.

Between the client and the session bean, the state of the conversation can be maintained using a stateful session bean. The instance variables contain a state only during the invocation by a client method.

It implements ‘javax.ejb.SessionBean’ interface and is deployed with the declarative attribute ‘stateful’.

They have instance fields that can be initialized and modified by the client with each method invocation. The bean can use the conversational states as its business process methods.

Posted Date:- 2021-09-04 06:57:42

What Is Ejb Client Jar File?

An EJB client JAR file is an optional JAR file that can contain all the class files that a client program needs to use the client view of the enterprise beans that are contained in the EJB JAR file. If you decide not to create a client JAR file for an EJB module, all of the client interface classes will be in the EJB JAR file.

Posted Date:- 2021-09-04 06:57:02

Enlist the Enterprise Beans types?

They are:
<> Session Beans: Expanded as “Stateful”,”Stateless” and “Singleton”, A Remote or Local interface is used to access the EJB files.

<> Message Driven Beans (MDB): Asynchronous execution by means of messaging paradigm is supported.

Posted Date:- 2021-09-04 06:54:42

Who took over EJB?

EJB was taken over by Sun Microsystems in 1999.

Posted Date:- 2021-09-04 06:53:55

When was EJB developed?

EJB was developed by IBM in 1997.

Posted Date:- 2021-09-04 06:53:35

What is software architecture of EJB?

Session and Entity EJBs consist of 4 and 5 parts respetively:
1. A remote interface (a client interacts with it),
2. A home interface (used for creating objects and for declaring business methods),
3. A bean object (an object, which actually performs business logic and EJB-specific operations).
4. A deployment descriptor (an XML file containing all information required for maintaining the EJB) or a set of deployment descriptors (if you are using some container-specific features).
5.A Primary Key class – is only Entity bean specific

Posted Date:- 2021-09-04 06:53:08

What is meant by EJB container?

It manages and coordinates the allocation of resources to the applications. Enterprise beans typically contain the business logic for a J2EE application. TheEJB server must provide one or more EJB containers. An EJB container manages the enterprise beans contained within it.

Posted Date:- 2021-09-04 06:52:44

How many types of session beans are available in EJB?

The different types of session beans are available in EJB are:

<> Stateful session beans
<> Stateless session beans
<> Singleton session beans

Posted Date:- 2021-09-04 06:52:23

What are the benefits of EJB?

Following are the key benefits of EJB.

<> Simplified development of large scale enterprise level application.
<> Application Server/ EJB container provides most of the system level services like transaction handling, logging, load balancing, persistence mechanism, exception handling and so on. Developer has to focus only on business logic of the application.
<> EJB container manages life cycle of ejb instances thus developer needs not to worry about when to create/delete ejb objects.

Posted Date:- 2021-09-04 06:51:38

What is a EJB call?

EJB Calls from Servlets. A servlet can call Enterprise JavaBeans to perform additional processing. A typical application design often uses servlets as a front-end to do the initial processing of client requests, with EJBs being called to perform the business logic that accesses or updates a database.

Posted Date:- 2021-09-04 06:50:40

What are session beans in EJB?

A session bean is a bean component developed by the client for storing the session data for a specific session. It performs different operations for the client. In the case of system failure, the session bean cannot be recovered. The bean is transactional but can be stateless or stateful. They get destroyed as soon as the session gets over.

Posted Date:- 2021-09-04 06:48:33

What is EJB container?

An EJB container is also called the application server that is an environment used for executing applications. It handles the security authorization and transactional management of an application so that the developer can focus on the important business logic.

The container also handles object pooling and life cycle management. Commonly used EJB containers are Glassfish, JBoss and Weblogic.

Posted Date:- 2021-09-04 06:45:41

What are some of the important features of EJB?

The important features of EJB are as follows:

<> The EJB architecture is scalable, portable, distributed and transactional.
<> EJB components do not contain any system level programming and have only business logic.
<> EJB components are platform independent and are coded in Java.
The life cycle of EJB instances is managed by the EJB container.

Posted Date:- 2021-09-04 06:45:10

What is EJB and what does EJB stand for?

EJB stands for Enterprise Java Beans that is a Java application-programming interface. It is a server-side API and is used for developing enterprise applications which are large, high performing and scalable. Any EJB application can be executed in a server that complies with the J2EE 1.3 standards.

Posted Date:- 2021-09-04 06:44:22

Search
R4R Team
R4R provides EJB Freshers questions and answers (EJB Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,EJB interview question set 1 ,EJB Freshers & Experienced Interview Questions and Answers,EJB Objetive choice questions and answers,EJB Multiple choice questions and answers,EJB objective, EJB questions , EJB answers,EJB MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for EJB fresher interview questions ,EJB Experienced interview questions,EJB fresher interview questions and answers ,EJB Experienced interview questions and answers,tricky EJB queries for interview pdf,complex EJB for practice with answers,EJB for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .