EARN 400$ PER WEEK

Custom Search
Showing posts with label J2EE. Show all posts
Showing posts with label J2EE. Show all posts

Monday, November 15, 2010

IMP FAQ’s related to J2EE:

1. Why beans are used in J2EE architecture instead of writing all the code in jsp's?

In order to separate the business logic and presentation logic beans are used. We write the business logic in the Beans. Where there is a change in business processes we have to modify only the bean code not jsp code and vice versa.

2. Explain MVC (Model-View-Controller) architecture?

MVC: - In model view controller design pattern, the software has split into 3 pieces.

MODEL: Responsible for Managing Data. The business logic (the core business transactions and processing), necessary to accomplish the goal of the interaction (calculations, queries, and / or updates to a database, etc). Business logic should be separated from UI logic. This makes it possible to have different clients (for ex browser and GUI) using the same beans. Separating the 2 also makes the business components easier to re-use, maintain, and update or change.

Ex. Java Beans

VIEW: Responsible for generating the views. It involves the presentation layout (the actual HTML output), for the result of the interaction. For HTML clients, this can be done using JSP.

Ex: JSP

CONTROLLER: Responsible for user interactions & co-ordinate with MODEL &VIEW. It is the Presentation logic (the logical connection between the user and EJB services), necessary to process the HTTP request, control the business logic, and select an appropriate response. This can be provided by Java Servlets or Session Beans.


3. Difference between Application Server & Web server?

Application servers used for enterprise solutions, web servers are used middle tier web applications.

Web servers are used for running web applications, the features are very less to compare application server the application server is specific to application. And it can run all the applications including web application.

Ex:- web-logic, web-sphere, Jbose.

All are providing the more features than web server like tomcat.

4. Which bean can be called as Multi-Threaded bean?

Stateless session bean can be called as Multi-Threaded bean as for every request of users is handled by creating a new threaded for the same object.

5. Difference between SAX and DOM?

SAX stands for Simple API for XML. It is a standard interface for event based XML parsing. Programmers provide handlers to deal with different events as the document is passed.

If we use SAX API to pass XML documents have full of control over what happens when the event occurs as result, customizing the parsing process extensively. For example a programmer might decide to stop an XML document as soon as the parser encounters an error that indicate that the document is invalid rather than waiting until the document is parsed. Thus improve the performance.

DOM stands for Document Object Model. DOM reads an xml document into memory and represents as it as tree. Each node of tree represents a particular piece of data from the original document. The main drawback is that the entire xml document has to be read into memory for DOM to create the tree which might decrease the performance of an application as the xml document get larger.

6. What is difference between stateless and state full session beans?

Stateless:

1) Stateless session bean maintains across method and transaction

2) The EJB server transparently reuses instances of the Bean to service different clients at the per-method level (access to the session bean is serialized and is 1 client per session bean per method.

3) Used mainly to provide a pool of beans to handle frequent but brief requests. The EJB server transparently reuses instances of the bean to service different clients.

4) Do not retain client information from one method invocation to the next. So many require the client to maintain on the client side which can mean more complex client code.

5) Client passes needed information as parameters to the business methods.6) Performance can be improved due to fewer connections across the network.

Stateful:

1) A stateful session bean holds the client session's state.

2) A stateful session bean is an extension of the client that creates it.

3) Its fields contain a conversational state on behalf of the session object's client. This state describes the conversation represented by a specific client/session object pair.

4) Its lifetime is controlled by the client.

5) Cannot be shared between clients.


7. What is a servlet Context? How do you get it?

ServletContext is also called as application object. And this can be used for logging (stores some kind of information) getting context parameters, getting the request dispatcher and storing the global data.

We can get the ServletContext obj using ServletContext.

i.e. ServletContext sc = getServletContext ();

8. What is Servlet Config? How do you get it?

ServletConfig can be used to get the initialization Parameters, to get the reference to the ServletContext. There can be multiple ServletConfig objects in a web application. Each servlet has one Config object.

The configuration information is:

Servlet name, initialization parameters servlet context object.

9. What is Request Dispatcher? How do you get it?

The name itself reveals that it is used to dispatch the control to requesting resource. It is an interface used to include any resource with in our servlet or forward the controller to any other resource. It contains two methods.

Forward (“---url”);

Include (“---url”);

For getting this we have a method in servlet context interface. So we can get it by servlet context object

sc.getRequestDispatcher ();

Tuesday, November 9, 2010

Enterprise Java Beans:

EJB stands for Enterprise Java Bean and is the widely-adopted server side component architecture for J2EE. it enables rapid development of mission-critical application that are versatile, reusable and portable across middle-ware while protecting IT investment and preventing vendor lock-in.

EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.

EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE.

Key Features of the EJB technology:

1. EJB components are server-side components written entirely in the Java programming language

2. EJB components contain business logic only - no system-level programming & services, such as transactions, security, life-cycle, threading, persistence, etc. are automatically managed for the EJB component by the EJB server.

3. EJB architecture is inherently transactional, distributed, portable multi-tier, scalable and secure.

4. EJB components are fully portable across any EJB server and any OS.

5. EJB architecture is wire-protocol neutral--any protocol can be utilized like IIOP, JRMP, HTTP, DCOM, etc.

Benefits of the EJB technology:

o Rapid application development

o Broad industry adoption

o Application portability

o Protection of IT investment

There are three kinds of enterprise beans:

Session Bean: Session Bean is used to represent a work-flow on behalf of a client. There are two types: Stateless and Stateful. Stateless bean is the simplest bean. It doesn't maintain any conversational state with clients between method invocations. Stateful bean maintains state between invocations.

Entity Bean: Entity Bean is a Java class which implements an Enterprise Bean interface and provides the implementation of the business methods. There are two types: Container Managed Persistence (CMP) and Bean-Managed Persistence (BMP).

Message-driven beans: A message-driven bean combines features of a session bean and a Java Message Service (JMS) message listener, allowing a business component to receive JMS. A message-driven bean enables asynchronous clients to access the business logic in the EJB tier.

Persistence in EJB is taken care of in two ways Container managed persistence (CMP) or bean managed persistence (BMP), depending on how you implement your beans:

1. For CMP, the EJB container which your beans run under takes care of the persistence of the fields you have declared to be persisted with the database - this declaration is in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon as the method you have executed is finished, the new data is persisted to the database by the container.

2. For BMP, the EJB bean developer is responsible for defining the persistence routines in the proper places in the bean, for instance, the ejbCreate (), ejbStore (), ejbRemove () methods would be developed by the bean developer to make calls to the database. The container is responsible, in BMP, to call the appropriate method on the bean. So, if the bean is being looked up, when the create () method is called on the Home interface, then the container is responsible for calling the ejbCreate () method in the bean, which should have functionality inside for going to the database and looking up the data.

EJBContext

EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called Session Context. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions.