Java,EJB Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Java,EJB Interview Questions & Answers

Switching job? Enterprise JavaBeans (EJB) is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. EJB is a development architecture for building highly scalable and robust enterprise level applications to be deployed on J2EE compliant Application Server such as JBOSS, Web Logic etc. Getting certified in Java programming language will create more opportunities in the competitive world. Strong Communication Skills - Should be interacting with client stakeholders to probe a technical problem. Wisdomjobs has interview questions which are exclusively designed for job seekers to assist them in clearing job interviews. Java EJB interview questions and answers are useful to attend job interviews and get shortlisted for job position.

Java,EJB Interview Questions

Java,EJB Interview Questions
    1. Question 1. Explain Ejb In Brief.

      Answer :

      EJB is a standard for developing server side in JAVA. It specifies agreement between components and application servers that allows components to run on server. They are mainly for complex serer side operations like executing complex algorithm or high volume business. EJB provides the application layer logic, also called as middle tier. It provides a standard specifications-based way to develop and deploy enterprise-class system.

    2. Question 2. When Was Ejb Developed?

      Answer :

      EJB was developed by IBM in 1997.

    3. Question 3. What Happens If Remove( ) Is Never Invoked On A Session Bean?

      Answer :

      Two situations need to be taken under consideration:

      • remove() invoked for a stateless session: In this case it may not matter whether we use remove() or not as in either case, nothing is done. The management of the number of beans in cache is done by container.
      • remove() invoked for a stateful session: Here,
      1. The bean might be kept in cache until the session is timed out after which it is removed or
      2. When there is memory requirement, the data is cached and bean is sent to free pool.

    4. Question 4. Define Context?

      Answer :

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

    5. Question 5. What Is Ejb Client Jar File?

      Answer :

      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.

    6. Question 6. Who Took Over Ejb?

      Answer :

      EJB was taken over by Sun Microsystems in 1999.

    7. Question 7. What Are Create Methods Of Entity Bean?

      Answer :

      The create() method is used to insert data into the database by creating a new instance of CMP entity bean. The creation methods look like this:

      • ejbCreate()
      • ejbPostCreate()

      The creation methods are linked at run time. The container delegates the invocation to these methods when the create() is invoked on home interface. These methods create Entity beans per programmer specified parameters and conditions.

    8. Question 8. Is Ejbcreate () Method Mandatory While Defining A Session Bean?

      Answer :

      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.

    9. Question 9. Describe The Life Cycle For Stateful Beans.

      Answer :

      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.

    10. Question 10. Enlist The Enterprise Beans Types?

      Answer :

      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.

    11. Question 11. What Is Session Bean?

      Answer :

      Session beans are used to shield the client from the complexity of the business logic. They provide access to special transient 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 beans to access the application in the server.

    12. Question 12. Which Is More Beneficial: Cmp Or Bmp?

      Answer :

      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.

    13. Question 13. What Is Ejb Ql?

      Answer :

      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.

    14. Question 14. Enlist The Declarative Transaction Types?

      Answer :

      They are:

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

    15. Question 15. What Is Lazy Loading?

      Answer :

      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.

    16. Question 16. Differentiate ‘stateful Session’ From ‘entity Bean’?

      Answer :

      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.

    17. Question 17. What Is An Ejb Context?

      Answer :

      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 beans use.
      • SessionContext: Session beans use this subclass.

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

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

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

      Answer :

      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.

    19. Question 19. Enlist The Contents Of Container, Container Contains?

      Answer :

      • 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

    20. Question 20. What Is Deployment Descriptor?

      Answer :

      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.

    21. Question 21. What Is Ejb Server?

      Answer :

      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 beans. 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 transaction service. An EJB server could be provided by, for example, a database or application server.

    22. Question 22. What Is Ejb Architecture(components)?

      Answer :

      Enterprise beans-An enterprise bean is a non-visual component of a distributed, transaction-oriented enterprise application. Enterprise beans are typically deployed in EJB containers and run on EJB servers.

      There are three types of enterprise beans: session beans, entity beans, and message-driven beans.

      1. Session beans: Session beans are non-persistent enterprise beans. They can be stateful or stateless. A stateful session bean acts on behalf of a single client and maintains client-specific session information (called conversational state) across multiple method calls and transactions. It exists for the duration of a single client/server session. A stateless session bean, by comparison, does not maintain any conversational state. Stateless session beans are pooled by their container to handle multiple requests from multiple clients.
      2. Entity beans: Entity beans are enterprise beans that contain persistent data and that can be saved in various persistent data stores. Each entity bean carries its own identity. Entity beans that manage their own persistence are called bean-managed persistence (BMP) entity beans. Entity beans that delegate their persistence to their EJB container are called container-managed persistence (CMP) entity beans.
      3. Message-driven beans: Message-driven beans are enterprise beans that receive and process JMS messages. Unlike session or entity beans, message-driven beans have no interfaces. They can be accessed only through messaging and they do not maintain any conversational state. Message-driven beans allow asynchronous communication between the queue and the listener, and provide separation between message processing and business logic.

    23. Question 23. What Is Ejb Container?

      Answer :

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

    24. Question 24. What Is Local Client View?

      Answer :

      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.

    25. Question 25. What Is Remote Client View?

      Answer :

      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.

    26. Question 26. What Are The Optional Clauses In Ejb Ql?

      Answer :

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

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

      Answer :

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

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

      Answer :

      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.

    29. Question 29. Is Decorator An Ejb Design Pattern?

      Answer :

      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.

    30. Question 30. What Is The Difference Between Sessioncontext And Entitycontext?

      Answer :

      Since EnterpriseBeans 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 beans 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

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

      Answer :

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

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

      Answer :

      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.

       

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

      Answer :

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

       

    34. Question 34. Can You Have Virtual Functions In Java?

      Answer :

      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.

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

      Answer :

      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.

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

      Answer :

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

    37. Question 37. What Is Java?

      Answer :

      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.

    38. Question 38. What Is The Relationship Between An Event-listener Interface And An Event-adapter Class?

      Answer :

      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.

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

      Answer :

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

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

      Answer :

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

       

    41. Question 41. How Can A Gui Component Handle Its Own Events?

      Answer :

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

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

      Answer :

      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.

    43. Question 43. How Are The Elements Of A Gridbaglayout Organized?

      Answer :

      The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes. 

    44. Question 44. What Is The Difference Between A Choice And A List?

      Answer :

      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.

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

      Answer :

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

    46. Question 46. Under What Conditions Is An Object's Finalize() Method Invoked By The Garbage Collector?

      Answer :

      The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.

       

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

      Answer :

      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.

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

      Answer :

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

    49. Question 49. What Class Of Exceptions Are Generated By The Java Run-time System?

      Answer :

      The Java runtime system generates RuntimeException and Error exceptions.

    50. Question 50. What Is The Relationship Between A Method's Throws Clause And The Exceptions That Can Be Thrown During The Method's Execution?

      Answer :

      A method's throws clause must declare any checked exceptions that are not caught within the body of the method.

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

      Answer :

      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.

    52. Question 52. How Is It Possible For Two String Objects With Identical Values Not To Be Equal Under The == Operator?

      Answer :

      The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

    53. Question 53. Why Are The Methods Of The Math Class Static?

      Answer :

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

    54. Question 54. What Are The Legal Operands Of The Instanceof Operator?

      Answer :

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

    55. Question 55. How Are The Elements Of A Gridlayout Organized?

      Answer :

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

    56. Question 56. What An I/o Filter?

      Answer :

      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.

       

    57. Question 57. If An Object Is Garbage Collected, Can It Become Reachable Again?

      Answer :

      Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

    58. Question 58. What Advantage Do Java's Layout Managers Provide Over Traditional Windowing Systems?

      Answer :

      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.

       

    59. Question 59. What Is The Collection Interface?

      Answer :

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

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

      Answer :

      A local inner class may be final or abstract.

       

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

      Answer :

      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.

    62. Question 62. What Is The Difference Between The Paint() And Repaint() Methods?

      Answer :

      The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

    63. Question 63. What Is The Purpose Of The File Class?

      Answer :

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

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

      Answer :

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

       

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

      Answer :

      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.

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

      Answer :

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

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

      Answer :

      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.

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

      Answer :

      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.

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

      Answer :

      By associating Checkbox objects with a CheckboxGroup.

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

      Answer :

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

    71. Question 71. What Happens When You Invoke A Thread's Interrupt Method While It Is Sleeping Or Waiting?

      Answer :

      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.

       

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

EJB(Enterprise JavaBeans) Tutorial