J2EE applications support a range of clients. J2EE clients run on a number of platforms including laptops, desktops, palmtops, and cell phones. These clients can connect through an intranet, the Internet, a wireless network, a wired network, or a combination of wired and wireless networks. Clients can be thin, server-dependent, and browser-based or rich and stand-alone. Applications designers must make a couple of key design decisions regarding clients. They need to decide which type of client best suits their requirements. They also need to decide whether to allow access to the application by more than one type of client.
A number of other issues should be examined when designing the client tier. These issues include network, security, and platform considerations. You should remember that a client is network-dependent and that networks are unreliable. Ideally, the client should connect to the network on an ad-hoc basis, transmit the minimum amount of data necessary, and function quite well when the server is inaccessible. Client connection is impacted by network-security requirements. For example, external firewalls limit the number of protocols a client can use. Platform considerations influence client-design. For example, a mobile device would be unable to display a huge volume of data.
The J2EE platform favors thin-client architectures. However, a J2EE client will need to deal with a range of design issues including the ability to:
contain logic for user interface presentation
validate user inputs
communicate with the server using a common protocol
maintain the conversational state
Browser Clients Design Issues
Browser clients receive all their presentation logic from web servers and cannot function independently of the server. Browser clients are relatively easy to design and implement. Browsers are widely available, and their interfaces are familiar to many users, but the functionality they provide to the user is limited.
Browser clients can perform some user interface validation, typically by using JavaScript. Validating user input on the client side reduces the validation workload on the server, but the amount of validation code that needs to be downloaded can be substantial.
The HTTP request-response mechanism is used for communications between browser client and server when browser clients connect to a J2EE application over the Web.
Web-based applications need to maintain conversational or session state for individual clients. Browsers can use cookies or URL rewriting to maintain session state. Both mechanisms are open to unauthorized access. Therefore, it is recommended that servers should maintain conversation state for browsers.
Java Clients Design Issues
Java clients fall into three categories:
applications
applets
MIDlets
Application clients are similar to standard desktop applications in that they depend less on servers than browser clients. Applet clients are now rarely used. These user-interface components run for the most part in a web browser. MIDlet clients are small applications that are used for cell phones, two-way pagers, and palmtops.
Java application and applet clients can use the Java Foundation Classes/Swing API to create sophisticated user interfaces. Java MIDlets can use the MIDP User Interface API. This is designed to cope with the limited data-input capabilities of current mobile technologies. Java applications are difficult to program, but they offer a much richer user experience. Java clients are also more responsive than thin clients and can even be used offline. Java clients use less bandwidth than a browser client that requests the same data. They can also be programmed to make fewer connections than a browser client to a server.
Java clients can be designed to handle most of the user-input validation, preventing invalid data from reaching the server in the first place and reducing the network overhead of validation calls between the client and server. Java clients are flexible in the way they can connect to J2EE applications and can connect directly to the web, Enterprise JavaBeans (EJB), and Enterprise Information System (EIS) tiers.
Java clients that connect to the web tier of a J2EE application do this using the HTTP protocol. This, however, introduces complexity because of the need to translate between HTTP requests and responses and application events. Fortunately, EJB clients do not need to be programmed to perform these functions, because the clients connect to the EJB tier directly using Remote Method Invocation (RMI) calls. However, there are restrictions on EJB clients. First, applet and application clients are the only Java clients that can access EJBs directly. Second, you cannot use an EJB client when a firewall is in place that separates a server and its clients. Although Java clients can access the EIS tier directly, it is not recommended because it would bypass the business logic and transaction management on the J2EE server.
Finally, Java clients have the facility to cache and manipulate large amounts of state in memory and can therefore manage session state independently. This is advantageous when latency is high or when each connection expends significant bandwidth. It is important to remember that the server has the power to enforce business rules regardless of a client's actions. Applications also need to enforce data synchronization schemes when Java clients manipulate enterprise data.