401K to Roth IRA


Rules for 2011

■ If you are married and filing a joint tax return, your Roth IRA contribution is reduced if your income is at least $169,000.  If your income is at least $179,000, you cannot make a Roth IRA contribution.

■  If you are single or claim head of household status, your Roth IRA contribution is reduced if your income is at least $107,000.  If your income is at least $122,000, you cannot make a Roth IRA contribution. 

You may not be eligible to open a Roth IRA if your 2008 income is more than $116,000 for single filers and $169,000 for married and joint filers. If you make too much money, you will need to roll over to a traditional IRA.

You will be given a choice as to how you want your 401(k) money. Your first choice should be to have it rolled over directly to your new Roth IRA. They will send it over without you ever touching it. Your 401(k) company might not allow this. Some insist on issuing you a check then having you pass it along to the Roth IRA company. If this is the case,
be sure the check is made out to the new Roth IRA. This is very important. If the check is made out to you, then it will be considered a redemption and subject to an immediate 10 percent tax penalty if you are less than 
59 1/2.. A roll-over check should never be made out to you.

To meet the 60-day rule, start counting on the day after you receive the check and include the day you deposit the money into your IRA. For example, if you get the check on Sept. 1, you must get the money into your IRA on or before Oct. 31. There's no extension for weekends or holidays.


What is a Roth IRA?

Roth IRA is a retirement investment vehicle. Within a Roth IRA you can purchase any investment that you’d like – cash, bonds, options, CD’s, stocks, mutual funds, etc

Are Roth IRA Contributions Tax Deductible?

No.

What are the Benefits to having a Roth?

Contributions that you make to a Roth IRA are after tax, meaning that you’ve already paid taxes on them. As a result, you do not have to pay taxes on them ever again. This includes distributions when you withdraw the funds in retirement. This can be advantageous because many people predict that they will be taxed higher in retirement than they currently are. Also, some people want to lower their taxable income or pass off their IRA to their heirs, tax free.

How does a Roth differ from a Traditional IRA?

Contributions to traditional IRA’s are tax deductible at the time of contribution, however you must pay tax on your distributions in retirement. Contributions to Roth’s, on the other hand, are taxed now so that distributions in retirement are tax free. You basically decide whether or not you want to be taxed now or taxed later when choosing which to contribute to.

When can I Withdraw Contributions, Tax and Penalty Free?

At any time. You already paid the taxes on them.

When can I Withdraw Earnings Tax and Penalty Free?

Earnings distributions can be made without tax and penalty at age 59 and 1/2 if they have been held for a minimum of 5 years.

Are there any other Times Earnings are Tax and Penalty Free?

Yes, in the event of death, disability, or first time home purchase.

What if Earnings are Taken out Before Retirement Age?

They are subject to income tax and may also be subject to a 10% penalty.

What is the Contribution Deadline for a Roth IRA?

You can contribute up until the tax filing deadline in the following year. In other words, for the 2008 tax year, you can contribute up until April 15, 2009. For the 2009 tax year, it is April 15, 2010.

Intellipoint

The Explorer also comes with Intellipoint software to help users configure the mouse’s four buttons and scroll wheel for more than 30 actions (including cut and paste, Flip 3D, undo, exit program, precision booster and — my favourite — a magnification window).

How to import bookmarks from other browser into Chrome

 Wrench, Options, Personal Stuff, import data from other browser.

Viewing the Contents of a JAR File

jar tf <jar file name>

The t option indicates that you want to view the table of contents of the JAR file.
The f option indicates that the JAR file whose contents are to be viewed is specified on the command line.

You could also use v option, which will give you additional information.

OperationCommand
To create a JAR filejar cf jar-file input-file(s)
To view the contents of a JAR filejar tf jar-file
To extract the contents of a JAR filejar xf jar-file
To extract specific files from a JAR filejar xf jar-file archived-file(s)
To run an application packaged as a JAR file (requires the Main-class manifest header)
java -jar app.jar
To invoke an applet packaged as a JAR file
<applet code=AppletClassName.class
        archive="JarFileName.jar"
        width=width height=height>
</applet>

Adobe, HTML5 and jQuery

Adobe is contributing to the open source jQuery Mobile project, an effort to create a touch screen–happy framework for building mobile applications across platforms. It's based on the jQuery JavaScript and user-interface libraries. "We're working very closely with the jQuery organization," Wadhwani said. "We're doing a lot to help them create mobile components and to help them create the capacity to develop more interactive and more engaging animation experiences."

Wadhwani and company see jQuery Mobile as the ideal framework for building truly cross-platform HTML5 apps. "When you look at our customer base that's doing HTML development, jQuery is the top framework that people are using," Wadhwani said. "We've looked at a number of frameworks ... we want to make sure that HTML – and jQuery in particular – can give you the productivity gains that are necessary, to make it something that a broad base of developers and designers can leverage, as opposed to just the tip of the spear."

As Adobe man John Nack puts it: "This isn’t about one technology (HTML, Flash) 'vs.' another; it’s about putting customers, and the solutions to their problems, ahead of any technology. So, let’s stick a fork in the 'Adobe doesn’t like/doesn’t support HTML5' canard once and for all. Can I get an amen?"

Link

jQuery

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

Installing jQuery is as easy as placing it within your web application and using the HTML <script> tag to include it in your pages, like this:

<script type="text/javascript" src="scripts/jquery-1.4.js"></script>

JSON in Java


Download the zip from here.

Here is a snippet code how to use it:

JSON

JSON solves 2 problems:

1. It's a text, so it's very easy for network transmission. -- faster.

  • get JSON Data String from server: request.reponseText

2. It could also be easily converted into an object, which is very convenient for data manipulation. --convenient.

  • var itemDeatils = eval( '(' + JSON_DATA_STRING + ')'); //JavaScript's build-in function eval() could easily turn JSON Data String that you got from server into an object.
  • now you could use dot notaion on "itemDetails" now.

Inner Classes

Recently we had a very hard time to figure a problem with our client. I sent them a patch, but they had some problem with the patch, and I don't have the same from my side. We have tried many ways to figure it out. Then this morning, they found the problem: there is something wrong with my patch.

My patch is pretty simple, only contains a Java class, but the problem is this Java class contains an inner class, and I didn't include this inner class in the patch. That's why they had the problem.

Stopped, Unable to validate WebLogic Domain

I got this error when I tried to start WebLogic through Eclipse:

Stopped, Unable to validate WebLogic Domain

Here is why:

when eclipse is working on java 6 (and it has to, because oracle development tools for helios requires java 6) and weblogic is running on java 5.

The workaround is simple:

add

-Dsun.lang.ClassLoader.allowArraySyntax=true

after -vmargs string in eclipse.ini

Cola: Real-Time Shared Editing

 Link

Eclipse Save Action

Apache Solr

Apache Solr is an open source server build on top of Apache Lucene.

So basically Solr is an HTTP wrapper around an inverted index provided by Lucene. An inverted index could be seen as a list of words where each word-entry links to the documents it is contained in. That way getting all documents for the search query "dzone" is a simple 'get' operation.

JBoss Seam

Seam is a frame-work that sits on top of another framework (Java EE).

  • Seam simplifies Java EE: Seam provides a number of shortcuts and simplifications to the standard Java EE framework, making it even easier to effectively use Java EE web and business components.
  • Seam extends Java EE: Seam integrates a number of new concepts and tools into the Java EE framework. These extensions bring new functionality within the Java EE framework.

development methodology

I usually hate things like this, but what can I do? It's a game that everyone else is playing, so be a player, and be done it.

Agile Methods
  • Agile Modeling
  • Agile Unified Processing (AUP)
  • Dynamic Systems Development Method (DSDM)
  • Extreme Programming (XP)
  • Scrum
  • Velocity tracking
XP: advocates frequent "releases" in short development cycles, which is intended to improve productivity and introduce checkpoints where new customer requirements can be adopted.

EJB Packaging

TypeDescriptionDescriptorContents
CARClient application archivesapplication-client .xmlThick Java client for EJBs
EAREnterprise application archiveapplication.xmlOther Java EE modules such as EJB-JARs.
EJB-JAREJB Java archiveejb-jar.xmlSession beans, message-driven beans, and optionally entities. Needs a persistence.xml if entities are packaged.
RARResource adapter archivesra.xmlResource adapters.
WARWeb application archivesweb.xmlWeb application artifacts such as servlets, JSPs, JSF, static files, etc. Entities can also be packaged in this module. Needs a persistence.xml if entities are packaged.
Java EE 5 made the deployment descriptor optional, even in the EAR. This is a departure from previous versions of Java EE, where it was mandatory. The Java EE 5.0.compliant application servers deploy by performing automatic detection based on a standard naming convention or reading the content of archives.

Good EJB Article Place

Link

Stateless Session Interfaces

In addition to local invocation within the same JVM and remote invocation through RMI, stateless beans can be invoked remotely as web services.

Local Interface
Remote Interface
Web Service Endpoint Interface

Unable to locate tools.jar

$ant -version
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Apache Ant(TM) version 1.8.2 compiled on December 20 2010

It turns out that I have only installed JRE not JDK.

After install Java JDK and set JAVA_HOME.

$ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010

Outlook Data Locations

Click File->Data File Management->Data Files

C:\Users\hliu\AppData\Local\Microsoft\Outlook

outlook.ost: Mailbox
archive.pst: Archive Folder

TextPad Micro Location

I have a couple of very useful TextPad Micros. Today I though I better to make sure that I have some backup on them just in case something bad happened to my PC.

Spend a couple of minutes, I found there (my pc is Vista)

C:\Users\hliu\AppData\Roaming\Helios\TextPad\5.0

How to install Micros:
  1. put the micro files into the location, usually its extension is .tmp.
  2. Click Configure->Preferences->Micros, add the new micros into "Micros on menu".

BlazeDS + J2EE Example

Now suppose you have already setup BlazeDS in your J2EE App Server, let's say Tomcat here.

in your Flex's main.mxml, you have something like

<mx:RemoteObject id="srv" destination="product"/>

<mx:Button label="Get Data" click="srv.getProducts()"/>   

You see here we define a RemoteObject whose destination is "product", what's is "product"?

You should find "product" in blazeds\WEB-INF\flex\remoting-config.xml

    <destination id="product">
        <properties>
            <source>flex.samples.product.ProductService</source>
        </properties>
    </destination>

You see here we link product to a Java class called ProductService. So really, in main.mxml, when you call "srv.getProducts()", it's really calling ProductService.getProducts().

Now you see, how we could use Java class in Flex.

BlazeDS + J2EE

You can use Adobe LiveCycle Data Services, or the open-source version of LCDS called BlazeDS, to call public methods of Java classes as if they were local objects in a Flex client application.

BlazeDS is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe Flex and Adobe AIR applications for more responsive rich Internet application (RIA) experiences.

Configure an existing J2EE web application to support BlazeDS by performing the following steps:

Here are some useful link1 link2

Suppose you download the updated BlazeDS into folder blazeds-turnkey-4.0.0.14931/, and your existing J2EE application is under Tomcat/webapp/blJ2EEApp/

  • Add the BlazeDS JAR files and dependent JAR files to the WEB-INF/lib directory.
    • Copy all .jar files from blazeds-turnkey-4.0.0.14931/WEB-INF/lib to Tomcat/webapp/blJ2EEApp/WEB-INF/lib
  • Edit the BlazeDS configuration files in the WEB-INF/flex directory.
    • Copy blazeds-turnkey-4.0.0.14931/WEB-INF/flex folder to Tomcat/webapp/blJ2EEApp/WEB-INF
  • Define MessageBrokerServlet and a session listener in WEB-INF/web.xml.
    • Copy part of blazeds-turnkey-4.0.0.14931/WEB-INF/web.xml to Tomcat/webapp/blJ2EEApp/WEB-INF/web.xml
      • MessageBroker Servlet part

JRE version mismatch

Here is the error:

cannot access oracle.jdbc.OracleTypes bad class file: C:\bea\wlserver_10.3\server\lib\ojdbc6.jar(oracle/jdbc/OracleTypes.class)

class file has wrong version 50.0, should be 49.0


Again, this is a Java version mismatch.

ojdbc6.jar is compiled using JDK6, while Eclipse has Java 1.5 as the execution environment. Change Eclipse's JRE should do it.

Input Disappeared

I found this problem happen quite often.

If you like me, I sometimes use Chinese input, so I need switch my input, but often the Input language Icon on the right-bottom corner disappeared.

Here is the solution:

go to control panel, click Regional and Language Options, Click Keyboards and Languages, then click Change keyboards.., then click OK, after that the input icon will show up.

Chrome

So I am working on my blog, and I tried to color some of my words, pretty simple tasks, right? Not in Chrome.

The problem only exists in Chrome, not in Firefox and IE.

I dig a little bit more, it seems related to something called "Apple-style-span", and Chrome and Safari have problem to handle it.

Wait a minute, I just found Blogger now has a new editor, and this new editor seems resolving this problem now.

Here is how to enable the new editor:

blog's Settings | Basic tab. Near the bottom of the page you will see a field called Select Post Editor, and from there you simply need to select Updated Editor and save your settings.

Access Restriction Error

One of my colleges got this error in Elipse:

Access restriction: The constructor BASE64Encoder() is not accessible due to restriction on required library C:\bea\jdk160_14_R27.6.5-32\jre\lib\rt.jar

The way we fix this problem:

In Java Build Path, we remove and re-add JRE System Library fixed this problem.

RPC vs RMI


RPC (Remote Procedure Call) is the predecessor of RMI (Remote Method Invocation).

RMI is the Java answer to RPC.

The only reason to use an RPC web service instead of RMI/IIOP would stem from the desire to have the functionality accessible to a wider variety of clients who may or may not be behind a firewall.

Not only is there more overhead due to the SOAP based marshalling/unmarshalling, but it makes it harder to deal with state. Your web service must be essentially stateless from a transaction perspective. If you needed to create a web service that was stateful, you could do it (...I have), but if you want to have a "transaction" that spans multiple calls to the service, you can't rely on the EJB container to handle it for you. You would need to write logic for compensatory transaction and even uglier, you'd need to deal with the issue of what happens if the web service client stops interacting with you mid transaction. There's no event model/call back mechanism to handle this sort of thing.

Keep in mind with EJB 2.0 you can get even more speed by making the interfaces local.That being said, that is not to knock web services. I think they're great, but they are not necessarily the solution to every problem. I expect web services will be treated by some developers just like XML was. When XML became "hot" people wanted to use everywhere for everything whether it made sense or not. Web services is simply another tool, just like a hammer. I just wouldn't use it to drive in a screw. :-)

Session Bean

Session beans are the only EJB components that are invoked directly by clients.

Another word, entity bean or Message-Driven Bean could not be invoked directly by clients.

Then who could invoke Entity Bean or MDB?


  • Stateless: This type of bean does not maintain any conversational state on behalf of a client application.
  • Stateful: This type of bean maintains state, and a particular instance of the bean is associated with a specific client request. Stateful beans can be seen as extensions to client programs that are running on the server.
After Java EE5, a stateless session bean class is any standard Java class that has a class-level annotation of @Stateless. Although you don't have to have @Stateless annotation, you could use deployment descriptors, and if dd is used, it could override annotation.

Stateless Session Bean Callback Methods:
  • PostConstruct
  • PreDestroy
Stateful Session Bean Callback Methods: 
  • PostConstruct: Denoted with the @PostConstruct annotation. Any method in the bean class can be marked with this annotation.
  • PreDestroy: Denoted with the @PreDestroy annotation.
  • PreActivate: Denoted with the @PreActivate annotation.
  • PrePassivate: Denoted with the @PrePassivate annotation.

Making the Most of Java's Metadata

Part 1

EJB2 vs EJB3

EJB2

a. heavyweight programming model
b. direct use of the Java Naming Directory Interface (JNDI)
c. a verbose XML deployment descriptor.

EJB3

a. metadata annotations
b. dependency injection
c. minimal deployment descriptors, and .

EJB3 Annotation

History

a. java doc
b. xdoclet
c. EJB3 annotation

Is Tomcat enterprise ready?

Learn where Tomcat fits, and doesn't, in your enterprise

When Java developers start talking about application servers, Tomcat is often thrown into the mix. After all, it's one of the most popular options for lightweight development scenarios, and in many cases meets the need for an application server, even though it is technically a Web server. In this article Jeff Hanson engages the question of whether Tomcat is an app server, first by explaining what differentiates application servers, Web servers, and Java EE containers, and then by evaluating Tomcat's suitability to a variety of common Java enterprise development scenarios.

Confusion over whether Tomcat is an application server tends to result in heated discussion among Java developers -- some claiming it absolutely is and some that it definitely is not. In truth, Tomcat often is used as an app server, and for some scenarios it is perfectly suited to that role. For developers using Tomcat as an app server, it makes sense to classify it as such, regardless of formal definition.

In this article I tackle the question of whether Tomcat is an application server. I start by explaining the distinctions between app servers, Web servers, and Java EE containers, and then look at some scenarios where a Web server like Tomcat could be used appropriately as an app server. I show a scaled architecture, starting with the sort of lightweight implementation where Tomcat shines, and concluding with a complex service-oriented architecture, where you would be better off with a full-fledged Java EE application server.

Java EE as a point of reference

Java Platform, Enterprise Edition, or Java EE, is the de facto standard for developing server-side Java applications. As such it is the foundation on which all other server-side Java technologies, including app servers, must rest. Java EE compliance is an essential factor when evaluating the difference between Web servers and application servers.

Java EE extends Java Platform, Standard Edition (Java SE) to support Web services, an enterprise component model, management APIs, and communication protocols for designing and implementing service-oriented architectures, distributed applications, and Web applications. (Note that Web applications are only one sector that Java EE seeks to support.)

A compliant Java EE application server must support features such as an Enterprise JavaBeans (EJB) server and container; JNDI capabilities; a Java Message Service (JMS) framework; a Java Transaction API (JTA) framework; and J2EE Connector Architecture. Java EE servers usually support a hierarchical classloader architecture enabling such functionality as EJB loading/reloading, WAR loading/reloading, manifest-specified utilities, and so on.

Java EE defines containers for client applications, servlets, and EJB components. These containers provide structure and functionality that facilitate the deployment, persistence, and execution of supported components.

Java EE also defines a standard architecture for connecting Java EE applications and application servers to heterogeneous Enterprise Information Systems, such as ERP systems, mainframes, database systems, and non-Java legacy applications. The J2EE Connector Architecture enables a provider of an enterprise system to expose the system using a standard interface known as a resource adapter. The resource adapter allows an application server or enterprise application to use the same interface for different enterprise system vendors. Resource adapters operate within the address space of a host application server.

Figure 1 shows the tiers and components of a typical Java EE application architecture.

Illustration of a typical Java EE application architecture.

Figure 1. A typical Java EE application architecture (click to enlarge)

A Java EE application server is needed to support some, but not all, of the components shown in Figure 1. Using a Java EE server gives you the convenience of hosting a system in a pre-tested environment that offers all of the Java enterprise development services. In some cases, however, the Java EE server brings unnecessary overhead to an execution environment that only requires one or two of these services.

For instance, many Java-based Web applications are deployed to environments that only support the technologies found in a Web server/container, such as servlets, JSPs, and JDBC. In these scenarios you might choose to construct a system piecemeal, using sundry frameworks and providers. Some developers would choose to use Tomcat in place of the Java EE application server given these environmental constraints.

Oftentimes the decision of whether to use an application server or Web server depends on the type of communication needed between application components, so let's consider those options next.

EARs, WARs, JARs, and Java EE

A Java EE application may contain one or more Java EE components such as EJBs, Web modules, resource adapters, or J2EE application client modules. Each Java EE component can have an associated deployment descriptor -- an XML file that describes the component. Java enterprise components are deployed using the Java Archive (JAR) file format, which branches into additional formats to handle various component types.

The Java Archive (JAR) file format is based on the ZIP file format and enables you to bundle multiple Java EE components into a single file. A JAR file can contain Java class files, XML descriptor files, auxiliary resources, static HTML files, and other files associated with each Java EE component. A standard Java Web application is deployed in a Web Application Archive (WAR) file, which is a JAR file with the extension of .war. A standard Java EE application is deployed in an Enterprise Application Archive (EAR) file, which is a JAR file with an extension of .ear.

A WAR file is a specialized JAR file containing Web application components such as servlets, JSP files, HTML files, deployment descriptors, utility JAR files, etc. A WAR file can be deployed to a Web server such as Tomcat.

An EAR file is a specialized JAR file containing Java EE application components such as Web applications (WAR files), EJBs, resource adapters, etc. An EAR file can be deployed to a Java EE application server such as JBoss, WebLogic, or WebSphere. Java EE application servers load EAR files at runtime and deploy the components found within each file as Web applications, resource adapters, EJBs, and so on, based on the instructions found in each component's deployment descriptor.

Figure 2 illustrates the components found in many typical Java EE application server deployments.

Diagram of the components found in many typical Java EE application server deployments.

Figure 2. Components of a typical Java EE application server deployment

An EAR file can contain multiple Web applications along with other resources and auxiliary components. Deploying an application as an EAR file within the structure of a Java EE application server environment enables the app server to isolate each Web application within a separate class-loading and resource-loading context. Web applications in the Java EE app server environment can share resources in common, such as utility class files.

In a Java EE environment, specialized containers are designated to handle component isolation and resource sharing. These containers are, in turn, managed by the application server. Containers provide an isolated context wherein Java EE components are deployed and execute. Containers provide an abstraction layer between the components, ensuring that they seldom interact directly. Instead, components can use the protocols and APIs of the container to interface with each other and with other application services. This layer of abstraction enables containers to provide ancillary services required by the component, such as pooling, transaction management, and state management.

Web applications vs. enterprise applications

For some, the confusion over Tomcat's definition points to the deeper question of what differentiates an enterprise application from a Web application. Traditionally, a Java enterprise application is defined as a combination of the following components and technologies:

  • EAR files
  • Java Servlets
  • JavaServer Pages or JavaServer Faces
  • Enterprise JavaBeans (EJB)
  • Java Authentication and Authorization Service (JAAS)
  • J2EE Connector Architecture
  • JavaBeans Activation Framework (JAF)
  • JavaMail
  • Java Message Service (JMS)
  • Java Persistence API (JPA)
  • Java Transaction API (JTA)
  • The Java Management Extensions (JMX) API
  • Java API for XML Processing (JAXP)
  • The Java API for XML-based RPC (JAX-RPC)
  • The Java Architecture for XML Binding (JAXB)
  • The SOAP with Attachments API for Java (SAAJ)
  • Java Database Connectivity (JDBC) framework

A Java Web application, meanwhile, is said to combine a subset of Java enterprise application components and technologies, namely:

  • WAR files
  • Java Servlets
  • JavaServer Faces or JavaServer Pages
  • Java Database Connectivity (JDBC) framework

Popular frameworks such as Apache Struts, Spring, Hibernate, and others have obscured the traditional distinctions between Java enterprise and Java Web applications. Each new framework offers a slightly different view of how to accomplish the same tasks. Each framework attempts to solve a given set of challenges in a more efficient manner, possibly using a different set of underlying technologies.

Perhaps, this obscurity might be cleared up by observing the behavior of components deployed within different scenarios for a typical Java-based enterprise/Web application. These scenarios are discussed next.

Java EE application scenarios

In a typical Java EE Web application, an HTML client posts a request to a server where the request is handled by the Web container of the application server. The Web container invokes the servlet that is configured to handle the specific context of the request.

The initial HTML client request is illustrated in Figure 3.

An HTML client posts a request to an application server.

Figure 3. Initial HTML client request

Once the servlet has received the initial request, some form of request dispatching ensues in order to perform the necessary business logic for completing the request.

One or more business services or components are then invoked to perform business logic, as illustrated in Figure 4.

Business services or components are invoked to perform business logic.

Figure 4. Business services or components in the JEE architecture

Most business services or components require access to some form of data storage or information system. Oftentimes an abstraction layer between the business service and the data store is provided in order to protect against future changes in the data store. DAOs (data access objects) are often employed as data abstraction components in this situation, as shown in Figure 5.

One or more DAOs are invoked to perform business logic

Figure 5. DAOs are invoked to perform business logic (click to enlarge)

When the DAO invocation step is complete, the response data is passed back up the chain of command, usually as one or more Java beans. The Java beans are then passed to some type of state machine and/or view manager in order to organize and format the markup response.

When processing is complete for a given request, a formatted response is passed back to the HTML client, as illustrated in Figure 6.

A formatted response is passed back to the HTML client.

Figure 6. A response is passed back to the HTML client (click to enlarge)

The scenario depicted in Figure 6 can be implemented using a very limited set of Java EE technologies, including servlets, JDBC, and JSP or another view technology. Tomcat or any Web server providing a servlet engine and JSP engine could be used as the app server in this scenario.

Scaling into complexity

Now, suppose we add a requirement to the application for asynchronous messaging between business service components. In a Java-based system, this would typically be handled using the Java Message Service (JMS), as shown in Figure 7.

JMS handles asynchronous messaging between business service components.

Figure 7. JMS handles asynchronous messaging between business service components (click to enlarge)

Most Web servers do not offer JMS as a standard feature, but it is simple enough to add a JMS implementation to a Web server environment. So, once again, the application scenario depicted in Figure 7 could be handled quite easily with just a Web server providing a servlet engine and JSP engine.

Next, suppose we add the requirement for connectivity between business services and disparate enterprise information systems. Java EE offers the Java Connector Architecture as a common standard to meet this challenge. Using the Java Connector Architecture, the application architecture evolves to something similar to what you see in Figure 8.

The Java Connector Architecture handles connectivity between business services and EISs.

Figure 8. JCA handles connectivity between business services and EISs (click to enlarge)

The architecture is now approaching a complexity that is arguably better suited for a Java EE application server. A Web server such as Tomcat could possibly be used in combination with other frameworks to meet the requirements, but system management and monitoring complications might make the server/framework mix impractical.

Finally, Figure 9 presents a moderately complex, Java-based, service-oriented architecture employing all of the technologies discussed so far, along with communication between multiple WAR deployments, EJBs, and Web services.

Diagram of a moderately complex SOA.

Figure 9. A moderately complex service-oriented architecture (click to enlarge)

The architecture in Figure 9 has entered the realm of complexity that requires a tested, scalable, manageable Java EE enterprise application server. Once again, a development team with the proper skill level could use Tomcat for the Web tier and piece together technologies and frameworks to support the business and data tiers. Whether that effort would be well spent is questionable, particularly given the option to use a full-fledged application server.

Using Tomcat as an application server

Building scalable solutions

It is not uncommon for Java enterprise applications to scale along the lines suggested by the example in this article, growing in complexity as new requirements are added. While Tomcat (or any Web server) might suit your initial application requirements, it could become problematic in the long run, as the system gradually requires more complex deployment, management, and monitoring solutions. A Java EE application server is more scalable than a Web server, providing tight integration between containers and deployment contexts for each additional technology. In many cases, choosing a Java EE app server is the more cost-effective solution for the long run.

As the evolving application example in the previous section shows, Apache Tomcat can be used as an application server, especially for less complex Java EE Web applications. According to some figures, Tomcat is the Web/application server environment most used by Java developers. Tomcat's popularity is due to its ease of use and support for many features considered to be standard in a Java Web application environment, including WAR file deployment, JNDI resources, JDBC data sources, JSP support, session replication, virtual hosting support, clustering support, and JMX-based management and monitoring. Tomcat is also a favorite for Java enterprise development due to the fact that its runtime performance as a standalone server is very competitive.

With Tomcat version 6, some new features have been added including asynchronous HTTP request handling via Comet, thread pool sharing, non-blocking connectors, enhanced JMX management and monitoring, Servlet 2.5, and JSP 2.1.

Even with these new features, however, Tomcat does not support the entire Java EE stack. Where Tomcat and other Web servers fall short is in the area of features such as distributed transactions, EJBs, and JMS. Applications requiring support for these components are usually more at home in with a Java EE application server such as JBoss, Geronimo, WebLogic, WebSphere, or Glassfish. Many Java EE application servers actually use Tomcat as their Web container.

In conclusion

The formal distinction between Java EE application servers and Web servers is clear, but the real-world distinction is less obvious. While Tomcat is not strictly speaking an application server, this article has shown that it works quite well in that capacity, up to a point.

When attempting to determine the server environment best suited to a particular application or system, it is helpful to break down the requirements of the system and determine which Java EE components will need to be supported. For simpler Web applications that will not scale much, Tomcat is a fast, reliable, lightweight solution. For more complex enterprise applications, SOAs, or even highly scalable Web applications, a full-fledged Java EE application server is usually the more cost-effective choice.

About the author

Jeff Hanson has more than 20 years experience as a software engineer, including working as senior engineer for the Windows OpenDoc project and as chief architect for the Zareus SOA platform. The author of numerous articles and books, he is the chief architect for Max Software Inc., where he leads design and implementation teams building desktop and server applications for the content-control industry using C++, PHP, and JEE.

All contents copyright 1995-2011 Java World, Inc. http://www.javaworld.com