Thursday, January 19, 2012

Java Interview Question and Java Beginner Tutorial - Part 12

What’s new in the EJB 2.0 specification?

Following are the main features supported in EJB 2.0: Integration of EJB with JMS, Message Driven Beans, Implement additional Business methods in Home interface which are not specific for bean instance, EJB QL.

    Java Interview Question and Java Beginner Tutorial - Part 11

    Can the primary key in the entity bean be a Java primitive type such as int?

    The primary key can’t be a primitive type–use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive)

      Java Interview Question and Java Beginner Tutorial - Part 10

      I have created a remote reference to an EJB in FirstServlet. Can I put the reference in a servlet session and use that in SecondServlet?

      Yes. The EJB client (in this case your servlet) acquires a remote reference to an EJB from the Home Interface; that reference is serializable and can be passed from servlet to servlet. If it is a session bean, then the EJB server will consider your web client’s servlet session to correspond to a single EJB session, which is usually (but not always) what you want.

        Java Interview Question and Java Beginner Tutorial - Part 9

        How do the six transaction attributes map to isolation levels like “dirty read”? Will an attribute like “Required” lock out other readers until I’m finished updating?

        The Transaction Attributes in EJB do not map to the Transaction Isolation levels used in JDBC. This is a common misconception. Transaction Attributes specify to the container when a Transaction should be started, suspended(paused) and committed between method invocations on Enterprise JavaBeans. For more details and a summary of Transaction Attributes refer to section 11.6 of the EJB 1.1 specification.

          Java Interview Question and Java Beginner Tutorial - Part 8

          Is there a guarantee of uniqueness for entity beans?

          There is no such guarantee. The server (or servers) can instantiate as many instances of the same underlying Entity Bean (with the same PK) as it wants. However, each instance is guaranteed to have up-to-date data values, and be transactionally consistent, so uniqueness is not required. This allows the server to scale the system to support multiple threads, multiple concurrent requests, and multiple hosts.

            Java Interview Question and Java Beginner Tutorial - Part 7

            How can I access EJB from ASP?

            You can use the Java 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0, currently downloadable from Sun

              Java Interview Question and Java Beginner Tutorial - Part 6

              Can an EJB send asynchronous notifications to its clients?

               Asynchronous notification is a known hole in the first versions of the EJB spec. The recommended solution to this is to use JMS, which is becoming available in J2EE-compliant servers. The other option, of course, is to use client-side threads and polling. This is not an ideal solution, but it’s workable for many scenarios.

                Java Interview Question and Java Beginner Tutorial - Part 5

                I am developing a BMP Entity bean. I have noticed that whenever the create method is invoked, the ejbLoad() and the ejbStore() methods are also invoked. I feel that once my database insert is done, having to do a select and update SQL queries is major overhead. is this behavior typical of all EJB containers? Is there any way to suppress these invocations?

                This is the default behaviour for EJB. The specification states that ejbLoad() will be called before every transaction and ejbStore() after every transaction. Each Vendor has optimizations, which are proprietary for this scenario.

                  Java Interview Question and Java Beginner Tutorial - Part 4

                  Is there any way to force an Entity Bean to store itself to the db? I don’t wanna wait for the container to update the db, I want to do it NOW! Is it possible?

                   Specify the transaction attribute of the bean as RequiresNew. Then as per section 11.6.2.4 of the EJB v 1.1 spec EJB container automatically starts a new transaction before the method call. The container also performs the commit protocol before the method result is sent to the client.

                    Java Interview Question and Java Beginner Tutorial - Part 3

                    Is it possible to specify multiple JNDI names when deploying an EJB?

                    No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.

                      Java Interview Question and Java Beginner Tutorial - Part 2

                      Is it possible to write two EJB’s that share the same Remote and Home interfaces, and have different bean classes? if so, what are the advantages/disadvantages?

                      It’s certainly possible. In fact, there’s an example that ships with the Inprise Application Server of an Account interface with separate implementations for CheckingAccount and SavingsAccount, one of which was CMP and one of which was BMP.

                        Are enterprise beans allowed to use Thread.sleep()?

                        Java Interview Question and Java Tutorial - Part 1

                        Are enterprise beans allowed to use Thread.sleep()?

                         Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads