Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Java Tip 36: Share Java objects using e-mail

The Serializable interface, new with JDK 1.1, simplifies object persistence. Here's how to transfer an object to another user via SMTP e-mail

Object persistence and sharing objects between users are fundamental to many business solutions. For example, a company might provide a mechanism for completing time sheets using a Java applet launched from its Web site. Similarly, the company may provide applets for expense reports, travel itineraries, and bug reports. In each of these scenarios, the data obtained from the user of the applet needs to be shared with the people responsible for payroll, accounts payable, travel reservations, and quality assurance. The people who perform these functions may do so in different cities or countries, are likely to work different hours than the night-owl users who tend to fill out such "forms," and should not be forced to retype the information. Enabling them to "save" and deliver pertinent objects to the business would give such applets a clear advantage over others.

There are several mechanisms for achieving object persistence such as object databases and disk files. Similarly, there are many ways to share objects such as writing data to a socket or implementing CORBA- or SOM-compliant models. Each of these alternatives has its merits and should be considered carefully when you are designing your business solution. But there is also an inexpensive-yet-reliable way to deliver copies of objects around the world using technologies and services accessible by all Internet and intranet users. This is Simple Mail Transport Protocol, or SMTP.

E-mail Java objects

A simple approach to storing and saving objects is to serialize the object and e-mail it to the intended recipient. This has the benefits of:

  • not requiring disk storage on the sending computer or NC

  • using existing systems to transmit, queue, and deliver the objects

  • allowing recipients to retrieve objects with their favorite mail client

  • providing a simple mechanism for distributing copies of the same object to many people


This approach also has its shortcomings. Here are just a few of them:

  • Delivery may be delayed considerably if an e-mail host is down. This is true of all systems, but e-mail servers often fall behind database servers in terms of priority when repairs need to be made.

  • Delivery is not actually guaranteed -- you may have to resend your message if your mail server notifies you that the message was not deliverable.

  • E-mail servers and POP clients may not be able to keep up with very large transaction volumes.


The relevance of these limitations is based on the nature of your application. For many business solutions, these shortcomings may not be important. Part of your job as architect and designer is to determine the best overall mechanisms by taking into consideration price, performance, and need.

Four steps to e-mailing Java objects

There are four steps that your applet must take in order to e-mail Java objects:

  1. Serialize the relevant objects.

  2. Base-64 encode the serialized data (per RFC 1521).

  3. Locate and connect to an SMTP server (RFC 891).

  4. Send the object to the SMTP server.


This article will show you how to mail a hypothetical bug report to the quality assurance (QA) department of your firm.

1 | 2 | 3 |  Next >
Resources