next up previous contents
Next: Exercise 1: File handling Up: Lab 2: Guest book Previous: Lab 2: Guest book

Subsections

General information about the lab



Creating a project

For this lab, you will need to create a new empty project.



Packages

You will most likely benefit from putting your code in Java packages . A good split may be to put server code in the server package, client code (for the applets) in the client package and common code (such as objects that will be sent from the applet to the client or vice versa, or other code used by both clients and servers) in the common package.



Separating constants from the code

Whenever you write a program that is not completely trivial, it is important not to use ``magic constants'' directly in the code. Instead, create a separate class that contains the constants as final static fields, and use those fields in your other classes.

For example, you may want to create a class called common.Constants that contains (among other things) a field public static final int PORT = 8765; that contains the port number for your server. If you reference this port number in more than one place - for example, in the applet and in the server - and you need to change it, it is far easier to change it only in the Constants class. This class can also eventually contain fields for the name of the guest book data file you will use, the URL of the database you will use, and so on.



Error handling

You must always take care of all exceptions that can occur, and you must not use a simple catch-all clause such as ``catch (Exception e)'' - if a method call can throw more than one exception, you must explicitly handle each different exception that can be thrown.

You must always deal with the exceptions as well as you can, and attempt to recover gracefully. For example, you will write a server; it can't simply exit when there is an I/O exception - the server must be robust.



The <APPLET> tag

You will write at least two applets in this lab. You can read more about the different arguments to the APPLET tag in the JDK 1.1 documentation.



General information about Java programming

The Java Tutorial contains a lot of information that can be useful to you in this lab.


next up previous contents
Next: Exercise 1: File handling Up: Lab 2: Guest book Previous: Lab 2: Guest book
Jonas Kvarnstrom
2/5/1998