Friday, June 25, 2010

EJB

QUESTION: What are the main benefits of J2EE?
ANSWER: J2EE provides the following:

Faster solutions delivery time to market. J2EE uses "containers" to simplify development. J2EE containers provide for the separation of business logic from resource and lifecycle management, which means that developers can focus on writing business logic -- their value add -- rather than writing enterprise infrastructure. For example, the Enterprise JavaBeansTM (EJBTM) container (implemented by J2EE technology vendors) handles distributed communication, threading, scaling, transaction management, etc. Similarly, Java Servlets simplify web development by providing infrastructure for component, communication, and session management in a web container that is integrated with a web server.

Freedom of choice. J2EE technology is a set of standards that many vendors can implement. The vendors are free to compete on implementations but not on standards or APIs. Sun supplies a comprehensive J2EE Compatibility Test Suite (CTS) to J2EE licensees. The J2EE CTS helps ensure compatibility among the application vendors which helps ensure portability for the applications and components written for J2EE. J2EE brings Write Once, Run AnywhereTM (WORATM) to the server.

Simplified connectivity. J2EE technology makes it easier to connect the applications and systems you already have and bring those capabilities to the web, to cell phones, and to devices. J2EE offers Java Message Service for integrating diverse applications in a loosely coupled, asynchronous way. J2EE also offers CORBA support for tightly linking systems through remote method calls. In addition, J2EE 1.3 adds J2EE Connectors for linking to enterprise information systems such as ERP systems, packaged financial applications, and CRM applications.

By offering one platform with faster solution delivery time to market, freedom of choice, and simplified connectivity, J2EE helps IT by reducing TCO and simultaneously avoiding single-source for their enterprise software needs.

QUESTION: Name a few Design Patterns used in J2ee applications
ANSWER: MVC, Front Controller, Session Facade, Data Access Object

QUESTION: What is the deployment order for the deployed server components in WebLogic server?
ANSWER:
JDBC Connection Pools
JDBC Multi Pools
JDCB Data Sources
JDBC Tx Data Sources
JMS Connection Factories
JMS Servers
Connector Components
EJB Components
Web App Components

QUESTION: Why do the create() or find() method return the remote reference or a primary key only?
ANSWER: The EJB Specification prohibits this behavior, and the weblogic.ejbc compiler checks for this behavior and prohibits any polymorphic type of response from a create() or find() method.
The reason the create() and find() methods cannot return any object or primitive type is similar to the reason that regular constructors can be cast into the class itself or any of it?s super classes.

For example
A a = new A() or
A b = new B() where B is a child of A.
You cannot do, for example Vector v = new A();

QUESTION: Which XML parser comes with WebLogic Server 6.1?
ANSWER: We bundle a parser, based on Apache's Xerces 1.3.1 parser, in WebLogic Server 6.1. In addition, we include a WebLogic proprietary high-performance non-validating parser that you can use for small to medium sized XML documents. The WebLogic XML Registry allows you to configure the parser you want to use for specific document types.

QUESTION: Can I use the getAttribute() and setAttribute() methods of Version 2.2 of the Java Servlet API to parse XML documents?
ANSWER: Yes. Use the setAttribute() method for SAX mode parsing and the getAttribute() method for DOM mode parsing. Using these methods in a Servlet, however, is a WebLogic-specific feature. This means that the Servlet may not be fully portable to other Servlet engines, so use the feature with caution.

QUESTION: How can I run multiple instances of the same servlet class in the same WebLogic Server instance?
ANSWER: If you want to run multiple instances, your servlet will have to implement the SingleThreadModel interface. An instance of a class that implements the SingleThreadModel interface is guaranteed not to be invoked by multiple threads simultaneously. Multiple instances of a SingleThreadModel interface are used to service simultaneous requests, each running in a single thread.
When designing your servlet, consider how you use shared resources outside of the servlet class such as file and database access. Because there are multiple instances of servlets that are identical, and may use exactly the same resources, there are still synchronization and sharing issues that must be resolved, even if you do implement the SingleThreadModel interface.

QUESTION: Are enterprise beans allowed to use Thread.sleep()?
ANSWER: 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

QUESTION: 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?
ANSWER: 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.

QUESTION: Is it possible to specify multiple JNDI names when deploying an EJB?
ANSWER: No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.

QUESTION: 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?
ANSWER: 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.