300+ TOP EJB Interview Questions and Answers

EJB Interview Questions for freshers experienced :-

1. What is EJB?

A server-side component, which manages the architecture for constricting enterprise applications and managed is called Enterprise JavaBeans(EJB).

2. When was EJB developed?

EJB was developed by IBM in 1997.

3. Who took over EJB?

EJB was taken over by Sun Microsystems in 1999.

4. 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.

5. What were Entity Beans?

Entity Beans were presented in the earlier versions of EJB consisting of persistent data in distributed objects.

6. Enlist the Declarative Transaction types?

They are:

  • MANDATORY:
  • REQUIRED
  • REQUIRES_NEW
  • SUPPORTS
  • NOT_SUPPORTED
  • NEVER

7. What are versions of EJB?

  • EJB 3.1
  • EJB 3.2
  • EJB 3.2 Final Release (2013-05-28)
  • EJB 3.1 Final Release (2009-12-10)
  • EJB 3.0 Final Release (2006-05-11)
  • EJB 2.1, Final Release (2003-11-24)
  • EJB 2.0 Final Release (2001-08-22)
  • EJB 1.1 Final Release (1999-12-17)
  • EJB 1.0 (1998-03-24)

8. What is J2EE?

A collection of synchronized specifications and procedures, which enable solutions regarding deploying, developing supervising multi-tier server-centric applications, is called J2EE.

9. Enlist the changes in EJB 2.1 ?

The changes made are:

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

10. Enlist the contents of Container. • Container contains?

  • Security support: Used to configure Deployment Descriptor (DD)
  • Persistence support: Used to be persistence in transactions.
  • Transaction management support: Used to configure Deployment Descriptor (DD)
  • Management of Session: Callback methods such as ejbStore (), ejbLoad () are used in the Developer.
  • Management of Life Cycle: Automatic
EJB Interview Questions
EJB Interview Questions

11. 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.

12. Which is more beneficial: Stateful or Stateless Bean?

If a conversational state is needed then, Stateful mode is preferred while Stateless paradigm is preferred for a single business process.

13. 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.

14. 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.

15. Is ejbCreate () method mandatory while defining a Session Bean?

EjbCreate () as being part of the bean’s lifecycle, therefore, it is not mandatory for ejbCreate () method to be present and there will be no errors returned by the compiler.

16. What is Context?

This is a method of binding a name to a specific object by giving an interface like javax.naming.Context.

17. What is Initial Context?

Implementation of available methods in the interface of context such as a context called javax.meaning.InitialContext.

18. Define SessionContext ?

An EJBContext object, the SessionContext is used for accessing the information and container services.

19. Can remove () be a Stateless Session bean?

Yes, remove () can be a Stateless Session bean because the life remains the same till the method is executed.

20. Is state maintained by a Stateless bean?

A Stateless bean contains no-client specific state through client-invoked methods.

21. Can EJB made to handle multiple transactions?

EJB can be made to handle multiple transactions by enabling multiple Entity beans to handle every database and one Session Bean to retain transaction with the Entity Bean.

22. Enlist the CallBack methods of Session Bean?

public interface javax.ejb.SessionBean extends javax.ejb.EnterpriseBean {
Public abstract void ejbCreate();
public abstract void ejbRemove();
Public abstract void ejbActivate (); public abstract void setSessionContext(SessionContext ctx); public abstract void ejbPassivate();
}

23. Enlist the CallBack methods of Entity Bean.

public interface javax.ejb.EntityBean extends javax.ejb.EnterpriseBean {
public abstract void ejbRemove();
public abstract void ejbActivate();
public abstract void ejbStore();
public abstract void ejbPassivate(); public abstract void setEntityContext(EntityContext ctx); public abstract void unsetEntityContext(); public abstract void ejbLoad();
}

24. How can one EJB be called from within another EJB?

An EJB can be called within another EJB by using JNDI which can be used for locating the Home Interface and acquiring the instance.

25. Differentiate Conversational from Non-conversational interactions?

The interaction between the client and the bean is called conversational while where multi method conversations are not held with clients it is known as non-conversational interactions.

26. Define ejb Create() and EjbPostCreate ()?

  • When the method is called before the persistence storage is written with the bean state, it is ejbCreate ().
  • When the method is called after the persistence storage is written with the bean state, it is ejbPostCreate ().

27. Define EAR, WAR and JAR ?

  • JAR files contain all EJB classes.
  • WAR files contain all servlets, web component pages, gif, html, beans, applets, classes and classes.
  • EAR files contain both JAR and WAR files.

28. Differentiate Phantom from Un-repeatable?

When data that did not existed before is inserted, it is read as phantom whereas when data that already existed is changed, un-repeatable occurs.

29. Define ACID Properties?

ACID is Atomicity, Consistency, Isolation and Durability.

  • Atomicity: Operations that are bundled together and projected a single unit of job.
  • Consistency: Guarantees that after a transaction has taken place, there will be consistency.
  • Isolation: Helps protect viewing of other simultaneous incomplete transaction results.
  • Durability: Ensures durability by keeping a transitional log by which the permanent data be recreated by again applying the steps involved.

30. What do you mean by ‘Hot deployment’ ?

The act of redeployment, deployment and un-deployment in Web logic when the server is running in EJB is called Hot Deployment.

31. How can a session bean be configured for transactions of bean-managed?

It can be done by setting transaction-attribute in the deployment sector or XML file.

32. Enlist the technologies embraced in J2EE.

The technologies embraced in J2EE are:

  • Enterprise JavaBeansTM (EJBsTM)
  • JavaServer PagesTM (JSPsTM)
  • Java Servlets
  • The Java Naming and Directory InterfaceTM (JNDITM)
  • The Java Transaction API (JTA)
  • CORBA
  • The JDBCTM data access API.

33. What do you mean Enterprise JavaBeans (EJB) container?

Enterprise JavaBeans container helps in managing the implementation of enterprise beans applications of J2EE.

34. What do you mean by in-memory replication?

When the contents having the memory of a single physical m/c are simulated in all m/c in that cluster, that process is called memory replication.

35. What is Ripple Effect?

During runtime, when the changes made in the various properties of server group, are propagated in every associated clone, this process is known as Ripple Effect.

36. What is Clone?

Server group copies are defined as clone. But unlike Server Groups, clones are linked by means of nodes.

37. What do you mean by bean managed transaction?

If the Container is not wanted by the developer for managing transactions, every database operation can be implemented to write the suitable JDBC code.

38. Differentiate, “find a method” from “select method” in EJB ?

A persistent field is returned by the select method of an entity bean that is related. A remote or local interface is returned by the finder method.

39. What do you mean by abstract schema?

An element of an entity’s bean’s deployment descriptor that defines the persistent fields of bean’s and the relationship existing between them is known as Abstract Schema. It is specific for each entity beans which has managed persistence of container.

40. What do you mean by re-entrant? Can you say that session beans as re-entrant? Can entity beans be specified as re-entrant?

If the entity bean is defined as re-entrant, then it is possible by multiple clients to associate with the Entity bean and get methods executed concurrently inside the entity bean. Synchronization is taken care of by container. There is an exception thrown when an entity beam is defined as non-re-entrant and numerous clients are connected to it concurrently to carry out a method.

41. What do you mean by EJB architecture?

A non-visual component involving a transaction-oriented, distributed enterprise application is called Enterprise beans. They are characteristically deployed in containers of EJB and run on servers of EJB.

The three enterprise bean types are:

  • Session Beans: These enterprise beans are non-persistent and can be stateless or stateful. If a conversational state is needed then, Stateful mode is preferred while Stateless paradigm is preferred for a single business process.
  • Entity Beans: Entity Beans were presented in the earlier versions of EJB consisting of persistent data in distributed objects. They had the ability to be saved in different persistent data stores.
  • Message Driven Beans: Asynchronous execution by means of messaging paradigm is supported. Follow the process of receiving and processing data. They are accessed only through messages and do not have a conversational state maintained.

42. Write the basic requirement of a CMP entity based class in 2.0 from EJB 1.1?

The basic requirement of a CMP is an abstract class which the container extends and gets the methods implemented required for managing the relationships.

43. How can Enterprise JavaBeans be accessed from Active Server Pages?

Enterprise JavaBeans can be accessed from Active Server Pages by:

  • ‘Java 2 Platform’
  • Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0 which has been currently downloaded from the Sun Microsystems.

44. Is having static initializer blocks legal in EJB?

It is legal technically, but static initializer blocks have been used in executing pieces of code before the final execution of any method or constructor when a class is instantiated.

45. What changes have been made in EJB 2.0 specifications?

Changes that have been made in EJB 2.0 specification are:

  • JMS is integrated with EJB.
  • Message Driven Beans.
  • Implementing additional Business methods.

46. What do you mean by EJBDoclet?

JavaDoc doclet, an open source is a doclet which generates good stuff related to EJB from comment tags of custom JavaDoc, which are embedded in the source file of EJB.

47. What do you mean by EJB QL?

A query language which provides navigation through a network comprising enterprise beans and objects which are dependent and are defined by methods of container managed persistence. EJB 2.0 was the platform for introduction of EJB QL. It defines methods of finder which are used for entity beans, which has container managed persistence and has portability across persistence managers and containers. It is helpful in two kinds of finder methods: Finder methods, which have Home interface and return objects of entity. Select methods, which remain unexposed for the client to see but which the Bean provider uses.

48. How does EJB invocation take place?

Home Object reference is retrieved from the Naming Service via JNDI. Home Object reference is returned to the client. The steps are:

  1. Created a new EJB Object via Home Object interface.
  2. Created an EJB Object from the Ejb Object.
  3. Returned an EJB Object reference to the client.
  4. Invoked business method by using EJB Object reference.
  5. Delegate requested to Bean (Enterprise Bean).

49. Can more than a single table be mapped in CMP?

No, more than one table cannot be mapped in a single CMP.

50. Are entity beans allowed to create () methods?

Yes, it is allowed in cases where data is not inserted by using Java application.

EJB Questions and Answers Pdf Download

300+ [LATEST] ejb Interview Questions and Answers

Q1. What Restrictions Are Placed On The Values Of Each Case Of A Switch Statement?

During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

Q2. What Are The Optional Clauses In Ejb Ql?

WHERE and ORDERBY clauses are optional in EJB QL where as SELECT and FROM are required clauses.

Q3. When Is The Finally Clause Of A Try-catch-finally Statement Executed?

The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.

Q4. If A Method Is Declared As Protected, Where May The Method Be Accessed?

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Q5. What Is Session Bean?

Session be are used to shield the client from the complexity of the business logic. They provide access to special trient business services. They are created by the client submitting the query to the database and exist as long as the client server session exists.

Session bean components implement the javax.ejb.SessionBean interface. Client invokes the methods on the session be to access the application in the server.

Q6. Enlist The Contents Of Container, Container Contains?

  • Security support: Used to configure Deployment Descriptor (DD).
  • Persistence support: Used to be persistence in tractions.
  • Traction management support: Used to configure Deployment Descriptor (DD).
  • Management of Session: Callback methods such as ejbStore (), ejbLoad () are used in the Developer.
  • Management of Life Cycle: Automatic

Q7. How Can A Gui Component Handle Its Own Events?

A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Q8. What Is Java?

Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling’s office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly.

Q9. What Is The Difference Between The Jdk 1.02 Event Model And The Event-delegation Model Introduced With Jdk 1.1?

The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, components are required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component’s container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried. In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events.

Q10. What Is The Collection Interface?

The Collection interface provides support for the implementation of a mathematical bag – an unordered collection of objects that may contain duplicates.

Q11. What Is The Difference Between A Choice And A List?

A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.

Q12. Why Are The Methods Of The Math Class Static?

So they can be invoked as if they are a mathematical code library.

Q13. What An I/o Filter?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

 

Q14. What Is Local Client View?

The local client view specification is only available in EJB 2.@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 trparency 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 be can be tightly couple with their clients, allowing access without the overhead typically associated with remote method calls.

Q15. What Is The Purpose Of The File Class?

The File class is used to create objects that provide access to the files and directories of a local file system.

Q16. What Are The Legal Operands Of The Instanceof Operator?

The left operand is an object reference or null value and the right operand is a class, interface, or array type.

Q17. Can I Invoke Runtime.gc() In An Ejb?

You shouldn’t. What will happen depends on the implementation, but the call will most likely be ignored.

Q18. What Advantage Do Java’s Layout Managers Provide Over Traditional Windowing Systems?

Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

 

Q19. What Modifiers Can Be Used With A Local Inner Class?

A local inner class may be final or abstract.

 

Q20. What Is The Highest-level Event Class Of The Event-delegation Model?

The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.

 

Q21. What Is The Difference Between Static And Non-static Variables?

A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Q22. What Is The Difference Between A While Statement And A Do Statement?

A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

Q23. What Is Ejb Server?

An EJB server is a high-level process or application that provides a run-time environment to support the execution of server applications that use enterprise be. An EJB server provides a JNDI-accessible naming service, manages and coordinates the allocation of resources to client applications, provides access to system resources, and provides a traction service. An EJB server could be provided by, for example, a database or application server.

Q24. Which Math Method Is Used To Calculate The Absolute Value Of A Number?

The abs() method is used to calculate absolute values.

 

Q25. 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 be 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.

Q26. What Class Allows You To Read Objects Directly From A Stream?

The ObjectInputStream class supports the reading of objects from input streams.

Q27. What Is The Difference Between Sessioncontext And Entitycontext?

Since EnterpriseBe live in a managed container, the container is free to call  your EJB components methods at its leisure. The container houses the information like current status of bean,security credentials of the user currently accessing the bean in one object is called EJBContext Object. A context represents a way for be to perform callbacks and modify their current status Sessioncontext is EJB context for session bean Entitycontext is EJB context for entity bean Message driven context is EJB context for message driven bean

Q28. How Are The Elements Of A Gridlayout Organized?

The elements of a GridBad layout are of equal size and are laid out using the squares of a grid.

Q29. 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.

Q30. Describe The Life Cycle For Stateful Be.

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.

Q31. Enlist The Declarative Traction Types?

They are:

  • MANDATORY
  • REQUIRED
  • REQUIRES_NEW
  • SUPPORTS
  • NOT_SUPPORTED
  • NEVER

Q32. When Was Ejb Developed?

EJB was developed by IBM in 1997.

Q33. Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?

The non-Unicode letter characters $ and _ may appear as the first character of an identifier

Q34. 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.

Q35. How Can The Checkbox Class Be Used To Create A Radio Button?

By associating Checkbox objects with a CheckboxGroup.

Q36. Enlist The Enterprise Be Types?

They are:

  • Session Be: Expanded as “Stateful”,”Stateless” and “Singleton”, A Remote or Local interface is used to access the EJB files.
  • Message Driven Be (MDB): Asynchronous execution by me of messaging paradigm is supported.

Q37. Name The Containers Which Uses Border Layout As Their Default Layout?

Containers which uses Border Layout as their default are: window, Frame and Dialog classes.

Q38. When Does The Compiler Supply A Default Constructor For A Class?

The compiler supplies a default constructor for a class if no other constructors are provided.

Q39. What Does A Well-written Oo Program Look Like?

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

Q40. How Are This () And Super () Used With Constructors?

This() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Q41. What Is Ejb Container?

An EJB container is a run-time environment that manages one or more enterprise be. The EJB container manages the life cycles of enterprise bean objects, coordinates distributed tractions, and implements object security. Generally, each EJB container is provided by an EJB server and contains a set of enterprise be that run on the server.

Q42. What Happens When You Invoke A Thread’s Interrupt Method While It Is Sleeping Or Waiting?

When a task’s interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.

 

Q43. Define Context?

This is a method of binding a name to a specific object by giving an interface like javax.naming.Context

Q44. 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);

 

Q45. What Is The Difference Between A Field Variable And A Local Variable?

A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

Q46. What Is An Ejb Context?

EJBContext is an interface implemented by the container. It is a part of the bean-container contract.

  • EntityContext: This is a sub-class of EJBContext that Entity be use.
  • SessionContext: Session be use this subclass.

These EJBContext objects provide the bean class with information about its:

  • Container.
  • Client using the bean.
  • Bean itself.

Q47. Can You Have Virtual Functions In Java?

Yes, all functions in Java are virtual by default. This is actually a pseudo trick question because the word “virtual” is not part of the naming convention in Java (as it is in C++, C-sharp and VB.NET), so this would be a foreign concept for someone who has only coded in Java. Virtual functions or virtual methods are functions or methods that will be redefined in derived classes.

Q48. Who Took Over Ejb?

EJB was taken over by Sun Microsystems in 1999.

Q49. How Does Multithreading Take Place On A Computer With A Single Cpu?

The operating system’s task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

Q50. 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.