j2ee difference

29
J2EE Difference Lakhani Kamlesh J. +91 95 86 331823 [1 | Page ] Lakhani Kamlesh J. [email protected] Lakhani Kamlesh J. [email protected] +91 95 863 31823 Topic J2EE DIFFERENCE

Upload: jdkkamal

Post on 18-Jul-2015

54 views

Category:

Education


0 download

TRANSCRIPT

Page 1: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[1 | P a g e ] Lakhani Kamlesh J.

[email protected]

Lakhani Kamlesh J.

[email protected]

+91 95 863 31823

Topic � J2EE

DIFFERENCE

Page 2: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[2 | P a g e ] Lakhani Kamlesh J.

[email protected]

Forward() SendRediret()

1 When we use forward method request is transfer to other

resource within the same server for further processing.

In case of sendRedirect request is transfer to another

resource to different domain or different server for further

processing.

2 In case of forward Web container handle all process

internally and client or browser is not involved.

When you use SendRedirect container transfers the request

to client or browser so URL given inside the sendRedirect

method is visible as a new request to the client.

3 When forward is called on requestdispather object we

pass request and response object so our old request object

is present on new resource which is going to process our

request

In case of SendRedirect call old request and response object is

lost because it’s treated as new request by the browser.

4 Visually we are not able to see the forwarded address, it is

transparent

In address bar we are able to see the new redirected address

it’s not transparent.

5 Using forward() method is faster then send redirect. SendRedirect is slower because one extra round trip is

required because completely new request is created and old

request object is lost. Two browser request required.

6 When we redirect using forward and we want to use same

data in new resource we can use

request.setAttribute() as we have request object

available.

But in sendRedirect if we want to use we have to store the

data in session or pass along with the URL.

7 It is faster then sendRedirect. It is slower than forward.

8 It will work only within the web application. Through these you can connect to any URL outside the web

application.

9 It is on server side It is on the client side.

10 forward will just forward the request to next page. sendRedirect will first come back to the page where its been

generated and the redirect to next page

11 It is transparent to the browser means URL of the browser

has not been changed.

It is not transparent to the browser means URL of the

browser has been changed.

12 Here request and response object is available to you on

forwarded page.

Here no request-response will be available to you on

redirected page.

13 A forward is performed internally by the servlet. A redirect is a two step process, where the web application

instructs the browser to fetch a second URL, which differs

from the original.

14 Both resources must be part of the same context. This method can be used to redirect users to resources that

are not part of the current context, or even in the same

domain.

15 Forward is marginally faster than redirect. Redirect is marginally slower than a forward, since it requires

two browser requests, not one.

16 Request is forwarded to a new servlet so the request

objects remains the same.

A completely new request is sent by the browser so the

request object changes.

17 The original URL does not changes. The browser is making a new request, so the URL changes.

Page 3: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[3 | P a g e ] Lakhani Kamlesh J.

[email protected]

Include Directive Include Action

1 Include directive is processed at the translation time. Include action is processed at the run time.

2 Include directive can use relative or absolute path. Include action always use relative path.

3 Include directive can only include contents of resource it

will not process the dynamic resource.

Include action process the dynamic resource and result will

be added to calling JSP.

4 We cannot pass any other parameter Here we can pass other parameter also using JSP:param

5 We cannot pass any request or response object to calling

JSP to included file or JSP or vice versa.

In this case it’s possible.

6 Syntax:

<%@ include file="fileName" %>

Syntax:

<jsp:include page=”relativeURL” />

7 The include directive includes the content at page

translation time.

The include action includes the content at request time.

8 The include directive includes the original content of the

page so page size increases at runtime.

The include action doesn’t include the original content rather

invokes the include() method of vendor provided class.

9 It’s better for static pages. It’s better for dynamic pages.

10 Its execution is slower. Its execution is faster.

11 It includes static content. It include static or dynamic content.

12 Include directive is used to include static resources during

translation time.

include Action is used to include dynamic content or static

content during runtime.

13 If you modify a jsp that is included in < @ include> tag then

the change will not be reflected since we are not compiling

the jspwith < @ include>.

Here it gets reflected when using jsp:include.

14 The include directive, includes the content of the specified

file during the translation phase–when the page is

converted to a servlet.

The include action, includes the response generated by

executing the specified page (a JSP page or a servlet) during

the request processing phase–when the page is requested by

a user.

15 The include directive is used to statically insert the

contents of a resource into the current JSP.

The include standard action enables the current JSP page to

include a static or a dynamic resource at runtime.

16 Use the include directive if the file changes rarely. It’s the

fastest mechanism.

Use the include action only for content that changes often,

and if which page to include cannot be decided until the main

page is requested.

Page 4: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[4 | P a g e ] Lakhani Kamlesh J.

[email protected]

GET POST

1 Transmits the request parameters in the form of a query

string that is appended to the request URL.

Transmits the request parameters within the body of the

request.

2 Limits you to a maximum of 256 characters in the URL,

excluding the number of characters in the actual path.

Does not limit the size of the URL, for submitting name /

value pairs, as they are transferred in the header and not in

the URL.

3 Allows you to retrieve path. Allows you to retrieve, save or update data. It also allows you

to order a product or send an e – mail message.

4 Considers the request as cacheable. Does not consider the request to be cacheable.

5 Limited amount of data can be sent because data is sent in

header.

Large amount of data can be sent because data is sent in

body.

6 Not secured because data is exposed in URL bar. Secured because data is not exposed in URL bar.

7 Can be bookmarked. Cannot be bookmarked.

8 Idempotent Non – idempotent.

9 It is more efficient and used than post. It is less efficient and used.

10 The amount of information you can send back using a GET

is restricted as URLs can only be 1024 characters.

You can send much more information to the server this way -

and it's not restricted to textual data either. It is possible to

send files and even binary data such as serialized Java

objects!

11 doGet() is a request for information; it does not (or should

not) change anything on the server. (doGet() should be

idempotent).

doPost() provides information (such as placing an order for

merchandise) that the server is expected to remember.

12 Parameters are not encrypted. Parameters are encrypted.

13 doGet() is faster if we set the response content length since

the same connection is used. Thus increasing the

performance.

doPost() is generally used to update or post some

information to the server. doPost() is slower compared to

doGet() since doPost() does not write the content length.

14 doGet() should be idempotent. i.e. doGet() should be able

to be repeated safely many times.

This method does not need to be idempotent. Operations

requested through POST can have side effects for which the

user can be held accountable.

15 doGet() should be safe without any side effects for which

user is held responsible.

This method does not need to be either safe.

16 The request parameters gets appended to the URL hence

visible in address bar.

Request parameters are sent as a part of body so are not

visible.

17 GET request pages can be cached (Allows bookmarking). Disallows bookmarking.

18 GET request should be idempotent i.e repeating the

request over and over again should not have any side

effect.

POST request does not need to be idempotent

Page 5: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[5 | P a g e ] Lakhani Kamlesh J.

[email protected]

Forward() method sendRedirect() method

1 Forward() method sends the same request to another

resource.

sendRedirect() method sends new request always

because it uses the URL bar of the browser.

2 Forward() method works at server side. sendRedirect() method works at client side.

3 Forward() method works within the server only. sendRedirect() method works within an outside the

server.

4 It is used to invoke another server from one servlet with is

same server

it can send request to page on another server

5 It forward the same request and response object from one

servlet to another servlet.

It does not send request and response object to another

servlet.

6 Redirection occurs within server. It sends response code to client side application to send the

request to another server or resources.

7 This method is available through RequestDispatcher

Object.

This is method of response object.

8 It transfer control to another servlet for further processing. It send response to browser and then browser again sends

request for second servlet or resource.

9 Data submitted to first servlet will be available for second

servlet.

Data of first servlet is not available for second servlet.

10 It is transparent to the browser means url of the browser

has not been changed.

It is not transparent to the browser means url of the browser

has been changed.

11 Here request and response object is available to you on

forwarded page.

Here no request-response will be available to you on

redirected page.

12 It is faster then sendRedirect. It is slower than forward.

13 It will work only within the web application. Through these you can connect to any URL outside the web

application.

14 forward will just forward the request to next page sendRedirect will first come back to the page where its been

generated and the redirect to next page

15 A forward is performed internally by the servlet. A redirect is a two step process, where the web application

instructs the browser to fetch a second URL, which differs

from the original.

16 Since both resources are part of same context, the original

request context is retained.

Because this involves a new request, the previous request

scope objects, with all of its parameters and attributes are no

longer available after a redirect.

(Variables will need to be passed by via the session object).

17 Both resources must be part of the same context (Some

containers make provisions for cross-context

communication but this tends not to be very portable).

This method can be used to redirect users to resources that

are not part of the current context, or even in the same

domain.

18 Any browser reload of the resulting page will simple repeat

the original request, with the original URL.

A browser reloads of the second URL, will not repeat the

original request, but will rather fetch the second URL.

19 The browser is completely unaware that it has taken place,

so its original URL remains intact.

The browser, in this case, is doing the work and knows that

it's making a new request.

20 Forward is marginally faster than redirect. Redirect is marginally slower than a forward, since it

requires two browser requests, not one.

Page 6: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[6 | P a g e ] Lakhani Kamlesh J.

[email protected]

21 Request is forwarded to a new servlet so the request

objects remains the same.

A completely new request is sent by the browser so the

request object changes.

22 The original URL does not changes. The browser is making a new request, so the URL changes.

Property forward() sendRedirect()

1 Defined interface Defined in RequestDispatcher Defined in HttpServletResponse

2 Signature void forward(ServletRequest request,

ServletResponse response)

void sendRedirect(String url)

3 Client awareness Client is not aware of that he is getting

response from a different Servlet as the URL

will not change in client’s browser.

Client can know easily as the URL (from where he is

getting response) changes in the client browser’s

prompt.

4 Execution control Execution control changes to another Servlet

on the same server without client being

informed that altogether a different Servlet is

going to process his request.

Control changes to client

5 Where is what? Forward is done on server side without

client’s knowledge.

Browser issues a new request on the URL that is

redirected (sent as parameter) by the server and

client can easily aware of.

6 Where happens Everything happens on server side within the

Web container and client is not involved.

sendRedirect() causes the Web container to return

to the client’s browser. Client intrun can redirect to

different servers or domains.

7 Speed Faster as forward runs on server-side entirely

and no extra network trip is required.

Due to extra round trip between browser-server-

browser (running on client as well as on server

side), it is slower.

8 Content forward() sends the same request to another

resource of the same Web application.

Calls another page with a different request URL but

not on the same request.

9 Usage Used when processing is done by another

Servlet

Used when wanted to redirect the client request to

another Web site (completely out of current

context) or to redirect the errors to another

resource

10 Reusability forward() reuses the current request object Redirects create a new request object; consequently

looses the original request with all its parameters

and attributes.

11 Ttansfer of

parameters

Original request and response objects

transfer data coming from client along with

additional information set with setAttribute()

method (if any) to another resource request

and response objects.

Redirect action sends header back to the client.

Browser uses the URL contained in the header to

call a new resource. As client initiates a new

request, the original request and response objects

are lost and fresh ones are to be created.

12 Transfer control Internally, the Servlet container transfers

control of client request to another servlet (or

JSP).

This method sends the HTTP response to client

browser to allow the client to send another request

with a different URL. Usage of this method is

equivalent to opening a new browser window and

Page 7: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[7 | P a g e ] Lakhani Kamlesh J.

[email protected]

typing the URL.

13 What is sent? Server sends the response (information

required) to the client.

With this method, server sends a URL to the client.

14 Visual difference Client cannot see the address of new resource

that honours the client request in the address

bar of the browser.

Client can see the new redirected address in

address bar.

15 Examples Calling another resource to process the data

like validation of Login data.

Calling advertisements on the Web page or payment

gateways.

16 Task separation With this method, the responsibility of

handling the client request can be distributed

between many Servlets (or JSPs).

Used to transfer control altogether to a different

domain. Also used to write separation of tasks.

17 Back and Forward

buttons

As everything happens on server with

forward, nothing is stored on browser

history. So, Back and Forward buttons will

not work.

As client makes new request and updated in

browser history, back and forward buttons work.

18 URL Use only relative URLs with forward(). Use absolute URLs.

19 MVC to hide Useful in MVC design pattern to hide

JSP/Servlet from direct access.

Once redirected to client, server looses control.

20 Which one to

prefer?

If you would like to forward the client request

to a new resource on the same server for

further process, prefer forward() where data

of the original resource can be passed to the

new resource.

If you would like to transfer the control to a new

server or domain where client treats as a new task,

prefer sendRedirect(). If the data of the original

resource (which client requested) is needed in the

new resource, store them in Session object and

reuse.

Page 8: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[8 | P a g e ] Lakhani Kamlesh J.

[email protected]

Applets Servlets

1 Applets are the programs at the client side. Servlets are the programs at the server side.

2 Applets can make request to servlets. The servlets are intended to response the applets or HTML

program.

3 Applets may have graphical user interface (CGI). Servlets have no graphical user interface.

4 Applets are run the web browser. Servlet run by web server or application.

5 Applet can’t call another applet. Servlet can call another servlet.

6 Applet have class file for loading browser. Servlet having URL for loading web browser.

7 Applet provides user interface regularly builds web

application.

Servlet provide care functionally for that services regarding

build web application.

TCP UDP

1 TCP stands for transmission control protocol. UDP stands for user datagram protocol.

2 It is a connection oriented protocol with

acknowledgement. When a file or messages send it will

get delivered unless connections fails. If connection lost,

the server will request the lost part. Hence it is called

reliable protocol.

It is a connectionless protocol without any acknowledgement.

When you send a data or message, you don’t know if it’ll get

there, it could get lost on the way. Hence it is called unreliable

protocol.

3 The message will get transferred in an orderly manner. The message transfer have no order.

4 It is slower than UDP. It is a faster protocol.

5 When the low level parts of the stream arrive in the

wrong order resend requests have to be sent and all the

out of sequences parts have to be back together so this

protocol is called heavyweight protocol.

No ordering of messages no tracking connections. Hence UDP

is called lightweight protocol.

6 Examples: Email, FTP, Secure Shell protocol makes use of

TCP.

Examples: Streaming media applications such as movies, voice

over IP (VOIP), online multiplayer games makes use of UDP.

Page 9: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[9 | P a g e ] Lakhani Kamlesh J.

[email protected]

ServletContext ServletConfig

1 It is an Object to be shared by all servlets and JSPs. This object is associated to specific servlet.

2 Unlimited store of data as per as server capability. Limited support for data handling.

3 Can be used to collaboration between multiple servlet. It is for single servlet.

4 Data stored here can be access from any servlet and JSP. Data stored here can be access from the servlet for which this

object is associated.

5 It is created using getServletContext() method of

Servlet class.

Created using getServletConfig() method.

6 Only Single instance available within web application. Multiple instances for each servlet.

7 Contains global properties like classpath, context path etc. Only contains property related to specific servlet.

8 Package: javax.servlet.ServletConfig Package: javax.servlet.ServletContext.

9 It is used by the servlet container to pass the information

to the servlet during initialization.

It defines the list of methods that are available to all servlet in

the application.

10 Methods:

getInitParameter(), getInitParameterNames(),

getServletName().

Methods:

getServletContext(),getRequestDispatcher(String url).

11 After Servlet class is instantiated, the container

createsServletConfig object that can be optionally passed

as a Parameter to the init() method.

It is very useful interface supplied by servlet Container to

provide services to web application & enables servlets to log

events &access information.

12 E.g. public void init(ServletConfigConfig) E.g. ServletContextsc= getServletContext().

13 The ServletConfig interface is implemented by the servlet

container in order to pass configuration information to a

servlet. The server passes an object that implements the

ServletConfig interface to the servlet's init() method.

A ServletContext defines a set of methods that a servlet uses to

communicate with its servlet container.

14 The param-value pairs for ServletConfig object are

specified in the <init-param> within the <servlet> tags in

the web.xml file.

The param-value pairs for ServletContext object are specified

in the <context-param> tags in the web.xml file.

15 This is also an interface from javax.servlet package. This is an interface from javax.servlet package.

16 Also written in web.xml file. Written in web.xml file.

17 The same method, getInitParameter(), exists in

ServletContext also to read.

Method to read is getInitParameter() of ServletConfig.

18 Ofcourse, with <context-param> also. Code maintenance is easier as and when <param-value> is

changed, the servlet need not be compiled again.

19 The same thing here also. For each <context-param>,

there will be one <param-name> and one </param-

value>.

For each <init-param>, there will be one <param-name> and

one </param-value>.

20 One web.xnl file can have any number of <context-

param> tags also.

One <servlet> can contain any number of <init-param> tags.

21 Used for providing common information for all the

servlets under execution.

Used for providing initialization data for a particular servlet.

22 Written inside <context-param> tag. Written inside <servlet> tag.

23 It is global data sharable by all servlets. This data can be

used to communicate with servlet container.

It is local data for a specific servelt.

Page 10: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[10 | P a g e ] Lakhani Kamlesh J.

[email protected]

24 Important methods are getInitParameter(),

getInitParameterNames(), getRequestDispatcher(),

setAttribute() and getAttribute().

Important methods are getServletName(), getServletContext(),

getInitParameter() and getInitParameterNames().

25 Only one ServletContext object is available for the whole

application.

A separate ServletConfig object is available for each servlet.

Session Cookie

1 Data on server-side. Data on client side.

2 Unlimited side of data as per as server capability. Limited support for data handling.

3 It can store any type of data. Only text.

4 Age of data is not fixed. Fixed.

5 Destroy after session timeout or logout. Remains on client machine.

6 Less data traveling over the network. All cookie need to travel each time client sends request to

server.

7 More secure mechanism to session tracking. Less secure.

8 Client identifies itself each time it makes a request and

server stores and retrieves data related to that client –

sessions.

Server sends data to the client and forces the client to send it

back with each request it makes cookies.

9 Session works even when client has disable cookies in

their browser.

Cookie cannot work when client has disable cookies in their

browser.

10 Session does not have any type. Cookie has two types

(1) Persistent / Permanent

(2) Transient

11 Session is expired using invalidate() method of

HttpSession class.

Transient Cookie is expired when browser is closed and

persistent cookie is expired after given time.

12 We can get creation time as well as last access time of the

session using methods of HttpSession.

We cannot get creation time and last accessed Time of the

cookie.

Page 11: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[11 | P a g e ] Lakhani Kamlesh J.

[email protected]

GenericServlet HTTPServlet

1 Generic Servlet class is super class/parent class of HTTP

servlet in servlet architecture.

HTTP servlet class is sub class/child class of Generic Servlet

class in servlet architecture.

2 The javax.servlet package contains the generic interfaces

and classes that are implemented &extended by the

servlets.

The javax.servlet.http package contains the classes that are

extended when creating http specific servlets.

3 This class implements Servlet interface. This class extends Generic Servlet class.

4 This class implements Servlet Config which handles

initialization parameter & Servlet Context.

This class implements service() of generic class by calling

method specific implementation to http request method(i.e.

doGet() and doPost()).

5 Servlet that extends this class are protocol independent.

They do not contain any support for HTTP or other

protocol.

Servlet that extends this class have built-in support for HTTP

protocol.

6 The GenericServlet does not include protocol-specific

methods for handling request parameters, cookies,

sessions and setting response headers.

The HttpServlet subclass passes generic service method

requests to the relevant doGet() or doPost() method.

7 GenericServlet is not specific to any protocol. HttpServlet only supports HTTP and HTTPS protocol.

8 javax.servlet.GenericServlet javax.servlet.http.HttpServlet

9 GenericServlet defines a generic, protocol-independent

servlet.

HttpServlet defines a HTTP protocol specific servlet.

10 To write a GenericServlet you need abstract service() to

be overridden.

A subclass of HttpServlet must override at least one method of

doGet(), doPost(),doPut(), doDelete(), init(), destroy(),

getServletInfo()

11 Signature:

public abstract class GenericServlet extends

java.lang.Object implements Servlet, ServletConfig,

java.io.Serializable

Signature:

public abstract class HttpServlet extends GenericServlet

implements java.io.Serializable

12 Generic Servlet does not support cookies, session supports cookies, sessions

Page 12: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[12 | P a g e ] Lakhani Kamlesh J.

[email protected]

Servlet JSP

1 A Servlet is a Java class implementing the

javax.servlet.Servlet interface that runs within a Servlet

engine

JSP pages contain a mixture of HTML, Java scripts, JSP

elements, and JSP directives, which will compiled by the JSP

engine into a servlet

2 To build servlet [javax.servlet.*;] and

[javax.servlet.http.*;] package require.

JSP program require [javax.servlet.jsp.*;] package.

3 Two types of servlet HTTP servlet generic servlet. JSP uses only HTTP servlet.

4 Servlet first loaded in to memory and then invoke HTTP

requests.

JSP file directly loaded on web browser because they are

already using HTTP servlet.

5 Servlet is dynamic HTML page code using Java

Code.

JSP is dynamic HTML code having java code when necessary.

6 Servlet file is having extension .java JSP file is having extension .jsp

7 Look and feel features are not in servlet Look and feel features are there in JSP

8 Servlets is look and act like programs. JSP is document-centric. (HTML + Java code).

9 Client side scripting is not possible with Servlet. But, Some of the JSP functionality can be achieved on the

client, using JavaScript.

10 Servlets are Java programs that are already compiled

which also creates dynamic web content.

JSP is a webpage scripting language that can generate dynamic

content.

11 Servlets run faster compared to JSP. JSP run slower compared to Servlet. JSP compiles into Java

Servlets.

12 Its little much code to write here. It’s easier to code in JSP than in Java Servlets.

13 In MVC, JSP act as a view. In MVC, servlet act as a controller.

14 servlets are best for use when there is more processing

and manipulation involved.

JSP are generally preferred when there is not much processing

of data required.

15 There is no such facility in servlets. The advantage of JSP programming over servlets is that we

can build custom tags which can directly call Java beans.

16 There are no such methods for servlets. We can achieve functionality of JSP at client side by running

JavaScript at client side.

17 Bits of HTML embedded in java code. Bits of java code embedded in HTML.

18 Suitable for coding business layer of enterprise

application.

Suitable for coding presentation layer of enterprise

application.

19 A servlet can support any protocol like HTTP, FTP, SMTP

etc.

A JSP can only be HttpServlet that means the only supported

protocol in JSP is HTTP.

20 Look and act like programs. Java Server Pages is that they are document-centric.

21 Servlets are better for generating binary data, building

pages with highly variable structure, and performing

tasks (such as redirection) that involve little or no output.

JSP is good at generating pages that consist of large sections of

fairly well structured HTML or other character data.

22 It’s ineffective to design webpages. JSP focuses on user interface and presentation.

23 It’s inaccessible to non-programmers. JSP enhances the design capability of servlet, nonprogrammers

can access it.

24 It is difficult to write HTML. Easy to write html.

25 Servlet file ends with .java extension. JSP page file ends with “.jsp” by default.

26 For Execution No need of source files. For Execution Automatic compilation; automatic reloaded;

Page 13: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[13 | P a g e ] Lakhani Kamlesh J.

[email protected]

source files (.jsp) are necessary.

27 Java code is used to write servlet code. JSP scripting elements such as JSP scriplet, expressions,

declaration, JSP actions, comments are embedded into HTML

code.

28 No translation phase is required. JSP page undergoes “Translation Phase” wherein it is

converted to Servlet.

29 Backtracking is not an issue. JSP page gets converted to .java file. So any errors will point to

line number in the converted .java file and not the actual JSP

file. Backtracking this to JSP is challenging.

30 Servlets are Fast because they are pure java classes. JSP is slow because first they converted in java code that in

class file.

31 Servlet is a pure java class Whereas JSP is not a pure java class.

32 Servlets are need Deployment Descriptor file (web.xml). No need of Deployment Descriptor file (web.xml).

JDBC ODBC

1 JDBC can directly used with Java because it uses Java

Interface.

ODBC cannot be directly used with Java because it uses a C

interface.

2 There is no Native code, so drawbacks like security,

implementation are not there.

Calls from Java to native C code have number of drawbacks in

the security, implementation, robustness and automatic

portability of applications.

3 JDBC do not use pointers because it is written in JAVA. ODBC makes use of pointers which have been totally removed

from Java.

4 JDBC is designed to keep things simple while allowing

advance capabilities when required.

But, ODBC mixes simple advanced features together and has

complex options for simple queries.

5 JDBC drivers are written in Java and JDBC code is

automatically installable, secure and portable on all

Java platforms from network computers to mainframes.

But, ODBC requires manual installation of the ODBC driver

manager and driver on all client machines.

6 JDBC is for Java Application. ODBC is for Microsoft.

7 JDBC drivers are written in java and JDBC code is

automatically installable, secure and portable on all

platforms.

ODBC doesn't require manual installation of the ODBC driver

manager and driver on all client machines.

8 JDBC is designed to keep things simple while allowing

advanced capabilities when required.

ODBC mixes simple and advanced features together and has

complex options for simple queries.

9 JDBC doesn't makes use of pointers. ODBC makes use of pointers.

10 JDBC is language dependent. ODBC is language independent.

Page 14: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[14 | P a g e ] Lakhani Kamlesh J.

[email protected]

Statement PreparedStatement

1 Statement interface is used to execute simple SQL

statements with no parameters.

PreparedStatement interface is used to simple as well as

complex statements with parameters

2 In statement object SQL Statements are not precompiled. In PreparedStatement object SQL statements are precompiled.

3 User interaction is not there. User interaction is there.

4 It is mostly used for Static SQL statements. It is mostly used for Dynamic SQL statements.

5 Whenever value of SQL statement is changed, each and

every time we have to compile SQL statement.

Whenever value of SQL statement is changed, we need not

compile SQL statement again.

6 If we want to execute SQL statement many times,

Statement object makes slow execution.

If we want to execute SQL statement many times,

PreparedStatement object makes faster execution.

7 There are no setXXX methods for parameters. There are setXXX methods for parameters.

8 Execute Methods:

1. ResultSetexecuteQuery(String sql)

2. intexecuteUpdate(String sql)

3. boolean execute(String sql)

Execute Methods:

1. ResultSetexecuteQuery()

2. intexecuteUpdate()

3. boolean execute()

9 createStatement( ) of connection interface is used to

create object Statement interface

prepareStatement(String sql) of connection interface is used

to create object of PreparedStatement interface.

10 A standard Statement is used to create a Java

representation of a literal SQL statement and execute it on

the database.

A PreparedStatement is a precompiled statement. This means

that when the PreparedStatement is executed, the RDBMS can

just run the PreparedStatement SQL statement without having

to compile it first.

11 Statement has to verify its metadata against the database

every time.

While a prepared statement has to verify its metadata against

the database only once.

12 If you want to execute the SQL statement once go for

STATEMENT.

If you want to execute a single SQL statement multiple number

of times, then go for PREPAREDSTATEMENT.

PreparedStatement objects can be reused with passing

different values to the queries.

13 It is slower because every time the statements get parsed

and executed.

This is faster because this is precompiled once and gets

executed with different parameters.

14 Statement perform 4 steps each time when query is

executing.

The query execution include 4 steps: parsing query, compile

query, optimized query and executing query. In

PreparedStatement first 3 steps perform only once when

query is submitted initially, only the last step is performed

each time at the time of query submitted.

15 It supply complete query with parameters. It has ability to create an incomplete query and supply

parameter values at execution time.

16 A statement is a static Sql statement. It does not support

parameters.

A PreparedStatement is a dynamic Sql statement. It does

supports parameters.

17 If we want to execute sql statement once it is

recommended to use statement.

If we want to execute sql statements repeatedly it is

recommended to use PreparedStatement.

18 This is suitable for DDL operations. This is suitable for DML operations.

Page 15: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[15 | P a g e ] Lakhani Kamlesh J.

[email protected]

TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE

1 An insensitive resultset is like the snapshot of the data in

the database when query was executed.

A sensitive resultset does NOT represent a snapshot of data,

rather it contains points to those rows which satisfy the query

condition.

2 After we get the resultset the changes made to data are

not visible through the resultset, and hence they are

known as insensitive.

After we obtain the resultset if the data is modified then such

modifications are visible through resultset.

3 Performance not effected with insensitive. Since a trip is made for every ‘get’ operation, the performance

drastically get affected.

RequestDispatcherinclude() RequestDispatcherforward()

1 The RequestDispatcherinclude() method inserts the the

contents of the specified resource directly in the flow of

the servlet response, as if it were part of the calling

servlet.

The RequestDispatcherforward() method is used to show a

different resource in place of the servlet that was originally

called.

2 If you include a servlet or JSP document, the included

resource must not attempt to change the response status

code or HTTP headers, any such request will be ignored.

The forwarded resource may be another servlet, JSP or static

HTML document, but the response is issued under the same

URL that was originally requested. In other words, it is not the

same as a redirection.

3 The include() method is often used to include common

"boilerplate" text or template markup that may be

included by many servlets.

The forward() method is often used where a servlet is taking a

controller role; processing some input and deciding the

outcome by returning a particular response page.

Property ServletRequest ServletContext

1 Context Cannot work outside the present Servlet

context.

Capable to use foreign Servlet context also. Can use

getContext() to obtain RequestDispatcher of other

contexts.

2 Access

Location

getRequestDispatcher() of ServletRequest is

useful to refer the servlets available in the

same Web application.

getRequestDispatcher() of ServletContext is useful to

refer servlets available on other Web applications on

different Web server also.

3 Scope Stored in page level. Scope is application level.

4 Relative

position

request.getRequestDispatcher("url") means

the dispatch is relative to the current HTTP

request. That is, it locates the resource relative

to the request path

getServletContext().getRequestDispatcher("url") means

the dispatch is relative to the root of the current

context.

5 Accessibility Used to call a Servlet or JSP within the current

application available, that too, on the same

Web server.

Used to call a Servlet or JSP exiting on another Web

server.

6 Example

Code

request.getRequestDispatcher("/S2"); where

S2 is the alias name of the Servlet available on

the same server and on the same Web

application.

getServletContext().getRequestDispatcher("/india/S2");

where india is the current context root(in all our earlier

Servlet programs).

Page 16: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[16 | P a g e ] Lakhani Kamlesh J.

[email protected]

ServletRequest.getRequestDispatcher(String path) ServletContext.getRequestDispatcher(String path)

1 The getRequestDispatcher(String path) method of

javax.servlet.ServletRequest interface accepts parameter

the path to the resource to be included or forwarded to,

which can be relative to the request of the calling servlet.

If the path begins with a “/” it is interpreted as relative to

the current context root.

The getRequestDispatcher(String path) method of

javax.servlet.ServletContext interface cannot accept relative

paths. All path must start with a “/” and are interpreted as

relative to current context root.

Property forward() sendRedirect()

1 Defined

interface

Defined in RequestDispatcher Defined in HttpServletResponse

2 Signature void forward(ServletRequest request,

ServletResponse response)

void sendRedirect(String url)

3 Client

awareness

Client is not aware of that he is getting

response from a different Servlet as the URL

will not change in client’s browser.

Client can know easily as the URL (from where he is

getting response) changes in the client browser’s

prompt.

4 Execution

control

Execution control changes to another Servlet

on the same server without client being

informed that altogether a different Servlet is

going to process his request.

Control changes to client

5 Where is what? Forward is done on server side without

client’s knowledge.

Browser issues a new request on the URL that is

redirected (sent as parameter) by the server and

client can easily aware of.

6 Where happens Everything happens on server side within the

Web container and client is not involved.

sendRedirect() causes the Web container to return to

the client’s browser. Client intrun can redirect to

different servers or domains.

7 Speed Faster as forward runs on server-side entirely

and no extra network trip is required.

Due to extra round trip between browser-server-

browser (running on client as well as on server side),

it is slower.

8 Content forward() sends the same request to another

resource of the same Web application.

Calls another page with a different request URL but

not on the same request.

9 Usage Used when processing is done by another

Servlet

Used when wanted to redirect the client request to

another Web site (completely out of current context)

or to redirect the errors to another resource

10 Reusability forward() reuses the current request object Redirects create a new request object; consequently

looses the original request with all its parameters and

attributes.

Ttansfer of

parameters

Original request and response objects

transfer data coming from client along with

additional information set with setAttribute()

method (if any) to another resource request

and response objects.

Redirect action sends header back to the client.

Browser uses the URL contained in the header to call a

new resource. As client initiates a new request, the

original request and response objects are lost and

fresh ones are to be created.

Page 17: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[17 | P a g e ] Lakhani Kamlesh J.

[email protected]

11 Transfer

control

Internally, the Servlet container transfers

control of client request to another servlet (or

JSP).

This method sends the HTTP response to client

browser to allow the client to send another request

with a different URL. Usage of this method is

equivalent to opening a new browser window and

typing the URL.

12 What is sent? Server sends the response (information

required) to the client.

With this method, server sends a URL to the client.

13 Visual

difference

Client cannot see the address of new resource

that honours the client request in the address

bar of the browser.

Client can see the new redirected address in address

bar.

14 Examples Calling another resource to process the data

like validation of Login data.

Calling advertisements on the Web page or payment

gateways.

15 Task

separation

With this method, the responsibility of

handling the client request can be distributed

between many Servlets (or JSPs).

Used to transfer control altogether to a different

domain. Also used to write separation of tasks.

16 Back and

Forward

buttons

As everything happens on server with

forward, nothing is stored on browser history.

So, Back and Forward buttons will not work.

As client makes new request and updated in browser

history, back and forward buttons work.

17 URL Use only relative URLs with forward(). Use absolute URLs.

18 MVC to hide Useful in MVC design pattern to hide

JSP/Servlet from direct access.

Once redirected to client, server looses control.

19 Which one to

prefer?

If you would like to forward the client request

to a new resource on the same server for

further process, prefer forward() where data

of the original resource can be passed to the

new resource.

If you would like to transfer the control to a new

server or domain where client treats as a new task,

prefer sendRedirect(). If the data of the original

resource (which client requested) is needed in the

new resource, store them in Session object and reuse.

Include() Forward()

1 include() method inserts the contents of the specified

resource directly in the flow of the servlet response.

forward() forwards the request to another resource in the

same context . Response is generated by the same servlet.

2 Included resource must not attempt to change the

response status code or http headers. Any such attempt

will be ignored.

forwaded resource may be another servlet, jsp or a static html

document but the response is issued under the same URL that

was originally requested.

Page 18: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[18 | P a g e ] Lakhani Kamlesh J.

[email protected]

JDK 1.2 JDK 1.3

1 Features added:

1) Strictfp keyword

2) Reflection

3) Swing API integration into the core classes

4) JVM equipped with a jit compiler

5) Java plug-in

6) Java IDL

7) An IDL implementation for corba interoperability

8) Collections Framework

Features added:

1) Hotspot jvm included

2) JavaSound

3) JNDI included in core libraries

4) Java platform debugger architecture (jpda)

5) RMI was modified to support optional compatibility with

corba

Jboss Tomcat

1 JBoss is a server application based on Java. It implements

full JEE servers (including stuff like EJB, JMS, ...).

Tomcat is a servlet container. It implements only the servlets

and jsp specification.

2 JBoss makes use of the Java EE specification. Tomcat makes use of Sun Microsystems specific specifications.

HTML XHTML

1 HTML is Hypertext Markup Language. XHTML is Extensible Hypertext Markup Language.

2 An application of SGML. An application of XML.

3 Can have empty/open tags e.g. <br>, <p>. All the unclosed tags must be closed e.g. <br/>, <p></p>.

4 No hard rule on structures of the elements e.g.

<p><b>The difference</p></b>.

Structure of the elements should be followed e.g. <p><b>The

difference</b></p>.

5 Attributes have quotes as optional e.g. <font

color=#ff0000>.

Attributes have quotes mandatory e.g. <font color=”#ff0000?>.

6 Attributes values not significant e.g. <input

type=”checkbox” checked>.

Attributes values are important e.g. <input type=”checkbox”

checked = “checked”>.

7 Case insensitive: The tags and attributes can be of

uppercase or lowercase as per the preference.

Case sensitive: The tags and attributes must be of lowercase.

8 All the content can be put under body element. All the content has to be put in blocks (p, under body element.

9 HTML is not mandatory for one root element. XHTML documents must have one root element.

Page 19: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[19 | P a g e ] Lakhani Kamlesh J.

[email protected]

Jboss WebLogic

1 JBoss application server is a free and open source

product.

WebLogic application server is developed by Oracle.

2 Latest version of JBoss server supports Java EE 6 Web

Profile.

But the latest release of WebLogic server only supports Java

EE 5.

3 But since JBoss is dependent on Tomcat Server, this is not

possible in JBoss.

You can change console requirements depending on the

requirements in WebLogic, as Self Console 7001 is included.

4 While Ant alone could be used for deployment in JBoss,

and it is very quick and easy.

Multiple ways of deployment is possible in Web Logic.

5 Configuration and administration is pretty simple in

JBoss, but a UI is not provided.

WebLogic is an expensive product, it has several features that

are not provided in JBoss. For example, WebLogic’s web-based

administrator console can be used for the configuration of JMS,

Data Sources, and security settings, etc.

6 Clustering is supported only for some of the features in

JBoss. Whereas, JBoss does not offers JMS clustering.

While, clustering is supported for all the APIs in WebLogic.

WebLogic offers JMS clustering.

7 But database connectivity is available in JBoss only

through JCA-JDBC wrappers, which means that

sometimes the programmer has to write his own code.

Standard JDBC API is used for database connectivity in

WebLogic.

Page 20: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[20 | P a g e ] Lakhani Kamlesh J.

[email protected]

JDBC 3.0 JDBC 4.0

1 Reusability of prepared statements by connection pools. Auto- loading of JDBC driver class: In JDBC 4 invoking the

getConnection() on DriverManager will automatically load a

driver.

2 In this version there is number of properties defined for

the ConnectionPoolDataSource. These properties can be

used to describe how the PooledConnection objects

created by DataSource objects should be pooled.

Connection management enhancements: In jDBC it may

happen that a Connection is lying idle or not closed in a pool,

then it became stale over time. This will led to the connection

pool run out of resources due to stale connection.

3 A new concept has been added to this API is of savepoints:

One of the useful new features is transactional savepoints.

With JDBC 3.0, the transactional model is now more

flexible.

Support for RowId data type: JDBC introduces support for

ROWID, a data type that had been in use in database products

even before it became part of the SQL.

4 Retrieval of parameter metadata. SQL exception handling enhancements: JDBC 4 addresses the

error handling beautifully. As databases are often remotely

accessible resources, problems such as network failures is

common and it can cause exceptions when executing a

database operation. SQL statements can also cause exceptions.

Prior to JDBC 4, most JDBC operations generated a simple

SQLException.

5 It has added a means of retrieving values from columns

containing automatically generated values.

SQL XML support.

6 Added a new data type i.e. java.sql.BOOLEAN. DataSet implementation of SQL using Annotations: The JDBC

4.0 specification leverages annotations to allow developers to

associate a SQL query with a Java class without a need to write

a lot of code to achieve this association.

7 Passing parameters to CallableStatement.

8 The data in the Blob and CLOB can be altered: JDBC 3.0

introduces a standard mechanism for updating BLOB and

CLOB data.

9 DatabaseMetaData API has been added.

10 It allows stored procedure parameters to be called by

name.

Page 21: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[21 | P a g e ] Lakhani Kamlesh J.

[email protected]

HTML DHTML

1 HTML is Hypertext Markup Language. DHTML is Dynamic Hypertext Markup Language.

2 HTML stands for only static pages. DHTML is Dynamic HTML means HTML + JavaScript.

3 It is referred as a static HTML and static in nature. It is referred as a dynamic HTML and dynamic in nature.

4 A plain page without any styles and Scripts called as

HTML.

A page with HTML, CSS, DOM and Scripts called as DHTML.

5 HTML sites will be slow upon client-side technologies. DHTML sites will be fast enough upon client-side technologies.

HTML 5 HTML 4

1 HTML 5 can use SVG and MathML inline. HTML 4 cannot.

2 HTML 5 allows the storage and use of offline applications. HTML 4 does not.

3 HTML 5 has many new elements that are not present in

HTML 4 e.g <nav>, <footer>.

Added more elements to HTML 5 which does not exist in

HTML 4.

4 HTML 5 has dropped certain elements. The elements exist in HTML 4 has been removed from HTML 5

and few deprecated tags are <font> or <centre>.

5 Is being developed by web hypertext application

technology working group (WHATWG) and W3C HTML

WG.

Was developed by World Wide Web consortium and

WHATWG (web hypertext application technology working

group).

6 It includes multimedia elements (<audio> and <video>). No multimedia support without third party software.

Client Side Server Side

1 Client Side programs run on the user's computer. Server side codes are executed in server and result is

displayed in web browser as HTML.

2 Client Side programming is less secure. Server-side scripts are more secure than client-side.

3 The code which is run on the user's computer using

scripts like Javascript can or may be blocked.

Server-side scripting does not have any limitation of any

browser.

Servlet CGI

1 The Servlets runs as a thread in the web-container

instead of in a separate OS process.

CGI script runs as a new OS process for each request.

2 Only one object is created first time when first

request comes, other request share the same object.

CGI create object every time when request comes to it.

3 Servlet is platform independent CGI is platform dependent.

4 Servlet is fast. CGI is slow.

Page 22: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[22 | P a g e ] Lakhani Kamlesh J.

[email protected]

HTTP HTTPS

1 URL begins with ?http://" in case of HTTP. URL begins with ?https://? in case of HTTPS.

2 HTTP is unsecured. HTTPS is secured.

3 HTTP uses port 80 for communication. HTTPS uses port 443 for communication.

4 HTTP operates at Application Layer. HTTPS operates at Transport Layer.

5 No encryption is there in HTTP. HTTPS uses encryption.

<jsp:include> <jsp:forward>

1

2

3

4

5

6

Param value attribute Param name attribute

1

2

3

4

5

6

JSP Action JSP Custom Action

1

2

3

4

5

6

JTA JTS

1 Java Transaction API. Java Transaction Service.

2 JTA is high level transaction interface. JTS is low level transaction interface.

3

4

5

6

Page 23: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[23 | P a g e ] Lakhani Kamlesh J.

[email protected]

setAutoCommit() getAutoCommit()

1

2

3

4

5

6

Session beans Entity Bean

1

2

3

4

5

6

Java Bean Enterprise Java Bean

1

2

3

4

5

6

RMI Server RMI Client

1

2

3

4

5

6

1

2

3

4

5

6

Page 24: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[24 | P a g e ] Lakhani Kamlesh J.

[email protected]

Hibernate

load() get()

1 Only use the load() method if you are sure that the object

exists.

If you are not sure that the object exists, then use one of the

get() methods.

2 load() method will throw an exception if the unique id is

not found in the database.

get() method will return null if the unique id is not found in

the database.

3 load() just returns a proxy by default and database won’t

be hit until the proxy is first invoked.

get() will hit the database immediately.

4 If object is present in the database it return object

otherwise it returns objectNotFoundException if

object is not found.load() never returns null.

If object is present in the database it return object

otherwise it returns null.

5 load() always returns proxy object. get() never returns proxy object. Proxy object means object

which has id or primarykey property and remaining

properties are uninitialized.

6 load() lazily loads data. load hits the database on demand

i.e. whenever we are calling getter methods on pojo other

than id property, proxied object gets initialized.

get() eagerly loads the data i.e always hit the database.

7 Performance wise it is recommended to use load because

load will hit the database on demand.

Performance wise it is not recommended to use get because it

always hits the database.

8 We have five overloaded methods .public void load

(Object object, Serializable id) throws

HibernateException. This is an extra method which takes

object as argument.

We have four overloaded methods for get() method.

sorted collection order collection

1 A sorted collection is sorting a collection by utilizing the

sorting features provided by the Java collections

framework. The sorting occurs in the memory of JVM

which running Hibernate, after the data being read from

database using java comparator.

Order collection is sorting a collection by specifying the order-

by clause for sorting this collection when retrieval.

2 If your collection is not large, it will be more efficient way

to sort it.

If your collection is very large, it will be more efficient way to

sort it.

Page 25: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[25 | P a g e ] Lakhani Kamlesh J.

[email protected]

JDBC Hibernate

1 With JDBC, developer has to write code to map an object

model's data representation to a relational data model

and its corresponding database schema.

Hibernate is flexible and powerful ORM solution to map Java

classes to database tables. Hibernate itself takes care of this

mapping using XML files so developer does not need to write

code for this.

2 With JDBC, the automatic mapping of Java objects with

database tables and vice versa conversion is to be taken

care of by the developer manually with lines of code.

Hibernate provides transparent persistence and developer

does not need to write code explicitly to map database tables

tuples to application objects during interaction with RDBMS.

3 JDBC supports only native Structured Query Language

(SQL). Developer has to find out the efficient way to

access database, i.e. to select effective query from a

number of queries to perform same task.

Hibernate provides a powerful query language Hibernate

Query Language (independent from type of database) that is

expressed in a familiar SQL like syntax and includes full

support for polymorphic queries. Hibernate also supports

native SQL statements. It also selects an effective way to

perform a database manipulation task for an application.

4 Application using JDBC to handle persistent data

(database tables) having database specific code in large

amount. The code written to map table data to application

objects and vice versa is actually to map table fields to

object properties. As table changed or database changed

then it’s essential to change object structure as well as to

change code written to map table-to-object/object-to-

table.

Hibernate provides this mapping itself. The actual mapping

between tables and application objects is done in XML files. If

there is change in Database or in any table then the only need

to change XML file properties.

5 With JDBC, it is developer’s responsibility to handle JDBC

result set and convert it to Java objects through code to

use this persistent data in application. So with JDBC,

mapping between Java objects and database tables is

done manually.

Hibernate reduces lines of code by maintaining object-table

mapping itself and returns result to application in form of Java

objects. It relieves programmer from manual handling of

persistent data, hence reducing the development time and

maintenance cost.

6 With JDBC, caching is maintained by hand-coding. Hibernate, with Transparent Persistence, cache is set to

application work space. Relational tuples are moved to this

cache as a result of query. It improves performance if client

application reads same data many times for same write.

Automatic Transparent Persistence allows the developer to

concentrate more on business logic rather than this

application code.

7 In JDBC there is no check that always every user has

updated data. This check has to be added by the

developer.

Hibernate enables developer to define version type field to

application, due to this defined field Hibernate updates

version field of database table every time relational tuple is

updated in form of Java class object to that table. So if two

users retrieve same tuple and then modify it and one user save

this modified tuple to database, version is automatically

updated for this tuple by Hibernate. When other user tries to

save updated tuple to database then it does not allow saving it

because this user does not have updated data.

Page 26: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[26 | P a g e ] Lakhani Kamlesh J.

[email protected]

Hibernate EJB 3.0

1 Session–Cache or collection of loaded objects relating to a

single unit of work.

Persistence Context-Set of entities that can be managed by a

given EntityManager is defined by a persistence unit.

2 XDoclet Annotations used to support Attribute Oriented

Programming.

Java 5.0 Annotations used to support Attribute Oriented

Programming.

3 Defines HQL for expressing queries to the database. Defines EJB QL for expressing queries.

4 Supports Entity Relationships through mapping files and

annotations in JavaDoc.

Support Entity Relationships through Java 5.0 annotations.

5 Provides a Persistence Manager API exposed via the

Session, Query, Criteria, and Transaction API.

Provides and Entity Manager Interface for managing CRUD

operations for an Entity.

6 Provides callback support through lifecycle, interceptor,

and validatable interfaces.

Provides callback support through Entity Listener and

Callback methods.

7 Entity Relationships are unidirectional. Bidirectional

relationships are implemented by two unidirectional

relationships.

Entity Relationships are bidirectional or unidirectional.

Dispatch Action LookupDispatchAction

1 It’s a parent class of LookupDispatchAction. Subclass of Dispatch Action.

2 DispatchAction provides a mechanism for grouping a set

of related functions into a single action, thus eliminating

the need to create separate actions for each function.

An abstract Action that dispatches to the subclass mapped

executes method. This is useful in cases where an HTML form

has multiple submit buttons with the same name. The button

name is specified by the parameter property of the

corresponding ActionMapping.

3 If not using Internalization functionality then dispatch

action is more useful.

Lookup Dispatch Action is useful when we are using

Internalization functionality

4 DispatchAction selects the method to execute depending

on the request parameter value which is configured in the

xml file.

LookupDispatchAction looks into the resource bundle file and

find out the corresponding key name. We can map this key

name to a method name by overriding the

getKeyMethodMap() method.

5 DispatchAction is not useful for I18N. LookupDispatchAction is used for I18N.

Page 27: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[27 | P a g e ] Lakhani Kamlesh J.

[email protected]

Struts Spring

1 Struts is a sophisticated framework offering the easy 2

develop, structured view/presentation layer of the MVC

applications. Advanced, robust and scalable view

framework underpinning reuse and separation of

concerns to certain extent.

Springs is a Lightweight Inversion of Control and Aspect

Oriented Container Framework. Every work in the last

sentence carry the true purpose of the Spring framework. It is

just not a framework to integrate / plug in at the presentation

layer. It is much more to that. It is adaptable and easy to run

light weight applications, it provides a framework to integrate

OR mapping, JDBC etc., Infact Struts can be used as the

presentation tier in Spring.

2 Struts features strictly associate with presentation stuff. It

offers Tiles to bring in reuse at presentation level. It offers

Modules allowing the application presentation to

segregate into various modules giving more modularity

there by allowing each module to have its own

Custom/Default Request Processor.

Spring provides Aspect Oriented programming, it also solves

the separation of concerns at a much bigger level. It allows the

programmer to add the features (transactions, security,

database connectivity components, logging components) etc.,

at the declaration level. Spring framework takes the

responsibility of supplying the input parameters required for

the method contracts at runtime reducing the coupling

between various modules by a method called dependency

injection / Inversion of Control.

3 Struts is developed with a Front Controller and dispatcher

pattern. Where in all the requests go to the ActionServlet

thereby routed to the module specific Request Processor

which then loads the associated Form Beans, perform

validations and then handovers the control to the

appropriate Action class with the help of the action

mapping specified in Struts-config.xml file.

Spring does not route the request in a specific way like this,

rather it allows to you to design in your own way however in

allowing to exploit the power of framework, it allows you to

use the Aspect Oriented Programming and Inversion of

Control in a great way with great deal of declarative

programming with the XML. Commons framework can be

integrated to leverage the validation in spring framework too.

Morethan this, it provides all features like JDBC connectivity,

OR Mapping etc., just to develop & run your applications on

the top of this.

4 Struts 2 integrates with Dojo AJAX framework closely and

provides many complex UI components out-of-box, such

as datepicker, tooltips, etc.

Spring is not.

5 Struts 2 has AJAX theme. Spring has not.

6 Struts 2 tags are stylesheet-driven, making it easier to

develop consistent pages.

Spring is not.

7 Struts 2 checkboxes are stateful, and require no special

handling.

Spring is not.

8 Struts is mainly a presentation layer framework, like

redirecting to a particular page ,doing client side

validations etc which otherwise very tedious using jsp

and servlets.

Spring is a complete J2EE framework having seven

independent layers which can be used all together or few

layers integrated with some other framework. Spring provides

declarative transaction management and AOP. One layer of

spring is for presentation purpose like struts but for only

presentation layer, struts is better than spring.

9 If you want a bunch of taglibs that generate form fields Whereas Spring is not in this area.

Page 28: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[28 | P a g e ] Lakhani Kamlesh J.

[email protected]

and so forth, Struts is probably the better choice.

10 Our UI is mostly click-driven and light on data and

validation. It seems to me that most people run into

difficulties with Struts when they start moving a lot of

data from HTTP into the model.

In Spring this problem does not exist.

Spring Struts

1 Spring is an application framework in which Spring MVC

is one of the modules of Spring framework.

Struts is a web framework which can be used to develop web

applications.

2 Spring implements IOC Design Pattern. Struts implement MVC Design Pattern.

3 It provides abstraction layer on multiple Java/J2EE

technologies including Servlet, JSPs. Also provides

abstraction on other framework software.

It provides abstraction layer only on Servlet, JSP technology.

4 Spring is a Layered Architecture. Struts is a not a Layered Architecture.

5 Spring Framework is said to be a non-invasive means it

doesn’t force a programmer to extend or implement their

class from any predefined class or interface given by

Spring API.

Struts is said to be invasive. In Struts we used to extend Action

Class.

It forces the programmer that, the programmer class must

extend from the base class provided by Struts API.

6 Spring provides easy integration with ORM, JDBC

technologies.

In Struts, integrating with ORM, JDBC technology, we need to

do manually coding.

7 Gives built-in middleware services like transaction,

logging, connection pooling etc.

Doesn’t give built-in middleware services.

8 Spring is Lightweight framework. Struts is Heavyweight framework.

9 It is not easy to integrate with other client side

technologies.

It is easy to integrate with other client side technologies.

10 Spring MVC just provides tags for basic HTML form tags. Struts 2 provides many out-of-box JSF styled complex and

composite tags Such as: Ajax DOJO tag

11 For View component, Spring allows JSP, Velocity,

Freemarker, Excel and PDF.

For View component Struts allows only JSP.

12 Spring MVC provides more handler mappings. Struts doesn’t have specific handler mappings but uses Action

mappings.

13 Spring clear module division between Model, View and

Controller.

Struts mixes Controller and Model.

14 Advantages of Spring Framework:

1) Transaction management

2) Support for Messaging

3) Support and Integration with Other Frameworks

(E.g.: Hibernate, Struts, Tapestry.. etc)

Advantages of Struts Framework:

1) Excellent support for Tag Library, which has wide

industry acceptance.

2) Easy to integrate with other client side technologies.

Page 29: J2EE Difference

J2EE Difference

Lakhani Kamlesh J.

+91 95 86 331823

[29 | P a g e ] Lakhani Kamlesh J.

[email protected]

Struts JSF

1 Struts is an open source framework. JSF is a Specification.

2 Struts actions are tied to Struts API. JSF action methods can be implemented in Java objects.

3 In Struts, there are no such event models. JSF has event model which reacts on value changes, actions

and phase changes in JSF lifecycle.

4 In Struts, there is no Dependencies Injection. JSF uses Dependencies Injection.

5 Struts use the notation to define navigation. JSF supports navigation by defining a navigation rule in the

faces configuration file.

6 Struts tag generates HTML directly. JSF component tag does not generate HTML instead they refer

a component renderer pair on the server.

Session Bean Entity Bean

1 Object state Maintained by the container in the main

memory across transactions. Swapped to

secondary storage when deactivated.

Maintained in the database or other resource

manager. Typically cached in the memory in a

transaction.

2 Object sharing A Session object can be used by only one

client.

An entity object can be shared by multiple clients. A

client may pass an object reference to another

client.

3 State

externalization

The container internally maintains the session

object's state. The state is inaccessible to

other programs.

The entity object's state is typically stored in a

database. Other programs, such as an SQL query,

cab access the state in the database.

4 Transactions The state of a session object can be

synchronized with a transaction but is not

recoverable.

The state of an entity object is typically changed

transitionally and is recoverable.

5 Failure recovery A session object is not guaranteed to survive

failure and restart of its container. The

references to session objects held by a client

becomes invalid after the failure.

An entity object survives the failure and the restart

of its container. A client can continues using the

references to the entity objects after the container

restarts.

RMI EJB

1 In RMI, middleware services such as security, transaction

management, object pooling etc. need to be done by the

java programmer.

In EJB, middleware services are provided by EJB Container

automatically.

2 RMI is not a server-side component. It is not required to

be deployed on the server.

EJB is a server-side component, it is required to be deployed

on the server.

3 RMI is built on the top of socket programming. EJB technology is built on the top of RMI.