Preparing a Doclet in Java

Doclets javadoc’s output format is determined by a ‘doclet’. The default,standard doclet is built-in to javadoc, and produces the HTML API documentation normally associated with javadoc. If you want to create custom output you can subclass the standard doclet, or you can write your own doclet.

For the adventurous, you can create XML or RTF; A good placed to start your doclet odyssey is at:
http://java.sun.com/j2se/1.4/toolodocs/javadoc/overview.html
Let’s look at a few simple examples of calling javadoc: To run javadoc against all the java files in the current directory,
% javadoc *.java (let us tried to start with an easy one.)
To run javadoc on a package called com.testpkg, first move to the parent directory of the fully qualified package (in other words, the directory containing the package), then
% javadoc –d /home/html-dest com.testpkg
In this case we used the –d flag to indicate the destination directory for the HTML output. So the command line reads, “Run javadoc, put the output in a directory called home/html-dest, and run the utility against all of the java files in the com.testpkg package.”


Other Capabilities javadoc has a wide range of command line options, in fact, a huge range of command-line options…so many that there is a facility that allows you to store your command-line options in a file. Let’s cover some of options you might find useful for your project:
windowtitle Allows you to specify the description that appears in the title bar of your browser window.

-header Allows you to specify a description that appears in the top right of your class documentation.

-footer Allows you to specify a description that appears in the lower
right ‘footer’ area of your class documentation

-bottom Allows you to specify a description that appears in the
bottom of your class documentation

-public Documents only public classes and members.
-protected This is the option if you don’t specify a command-line argument. It documents only protected and public classes and members.

Thanks

How Do A Comment Declared in Java

The Structure of a Comment As you will soon see, a single comment can grow to quite a large size. Comments can contain a wide variety of elements,but there are some restrictions to the order in which you can place these elements.To begin, the first line must start with /** (the / must be in column

1), all of the rows that contain descriptive content start with an * in column 2, and the closing
delimiter is */ with the * in column.

2. Finally, remember that the member declaration follows immediately after the javadoc comment. This format will hold true for any multiline javadoc comment used in documenting classes, interfaces,constructors, methods, instance variables, or exceptions;

for example,
/**
* the descriptive section
* of a multiline javadoc comment
*/
public class Test {

The tag section of the comment begins with the first occurrence of a ‘@’ that starts a new line of the comment (ignoring the leading *). There are two types of tags: standalone and inline. A standalone tag has the general form @tag. An inline tag has the general form { @tag }. Inline tags can be included in the descriptive section of the comment, but once a standalone tag has been encountered in a comment, no more descriptive text can be used in that comment;

for example,
/**
* the descriptive section
* we’re still in the descriptive section
* {@link doStuff doStuff} and
* after this line the tag section will begin:
* @author Joe Beets (the leading @ marked the beginning
* of the tag section.
* @version 2.1
*/

Thanks

Testing Graphical Interface Applications

Testing GUI code can be extremely challenging. By their very nature, GUIs are flexible in their behaviors; even simple GUIs offer billions of possible paths through their features. So how do you test all of these paths? Well, you really can’t, but you can hit the high points, and there are approaches that will help you produce a solid application with a finite amount of testing.

The key is to approach your testing from several radically different perspectives;So, the best way to test a GUI design is to run it by users, let them ask questions, gauge their reactions.The following tips will help you to create a robust and effective test plan:

? One avenue of testing must be use-case testing.

? Have the users run through the system using copies of live work orders
and scenarios.

? If certain scenarios are missing from a set of live work orders, create
simulated work orders to test the remaining system features/use-cases.

? If possible, have the users test the system in parallel with their live
activities. You will want to create duplicate databases for these parallel
tests, and for sure there will be overhead, but parallel testing is a very
effective way to test not only for bugs, but also to verify that the system
can handle all of the scenarios that the users will run across.

? As the developer, it can be hard to really put your system through its paces,
but if you pay attention to your own gut reactions, you can determine those
areas where you are afraid to try to break things. Wherever you hesitate to
tread, tread heavily.

? Enter invalid data everywhere.

? Test the limits of any data ranges that might exist.

? Force shutdowns of your system at critical stages to determine if transactions
are properly encapsulated.

Thanks

Make Messages & User Attraction Interfaces using GUI

Messages and other feedback are the primary ways that you (as the developer) have to respond to the user as she or he is using your application. Use messages to provide warnings when something has gone wrong or might be about to go wrong. Use messages to offer more information about activities that the system is performing (such as “37 occurrences found”), and use messages to display the status of an operation.

Try to use short, positive words and phrases.Use active voice whenever possible: “Print the file by choosing Print now”,as opposed to “The file will be printed by choosing Print”.Minimize the use of jargon or abbreviations in your messages.Ranges should be listed from smaller to larger and from now into the future.Action verbs should come first: “Display active customers” instead of “Activecustomer display”.

If the user selects an option that you think will require more than a few seconds to complete, give the user some sort of indication of status and progress. A system that locks up and gives the user no idea of whether progress is being made or an error has occurred is considered rude and
unfriendly.If the user makes a mistake that can be caught immediately, it is appropriate
to give them some sort of instant feedback such as warning noise or a blinking element.

The use of colors in GUIs is a controversial topic. Used correctly, colors can add aesthetic value and provide visual clues as to how to use and interpret an application.Used incorrectly, colors can be visually distracting, irritating, and confusing. In addition, poor color selections can make attractive displays ugly. In general, it is best to design your displays in monochrome and add only small color highlights.More ambitious color designs should be attempted only when you have the time to study the subject thoroughly.

Thanks

Menu Buttons Embedded with GUI

Menus are a powerful (and necessary) part of almost all GUIs. We focus our attention on the most common implementation of menus, the menu bar. An application’s main menu bar is almost always located at the top of the display—sometimes directly under an application’s title bar, and sometimes separate from the application’s main window and docked to the top of the display.

A navigational command such as Close (close the current document), Print (move to the Print display to initiate a print session), or Exit (end the application).An action command such as Spell Check (invoke the built in spell checker) or Copy (copy the currently highlighted data to the clipboard).

Alter a system setting or parameter, such as Show Toolbar (displays the
application’s toolbar by default) or View Normal (display the current data in the default mode).Within a menu, entries should be grouped in logical subsets, and each subset is typically delineated with a horizontal line or a double space.

Menu commands should be left-justified, and it is common and appropriate to display keyboard shortcut commands, whenever they are available, to the right of the menu entry. Each
application will have its own unique set of menus on the menu bar, but several of the menus will be very consistent from application to application.

These most consistent menus are the File and the Edit. File will vary a bit from application to application, but it will almost always include commands (menu items), for New,Open, Save, Print, Close, and Exit. These commands refer to the current document or project as a whole.

Edit can vary also, but will typically include commands for Undo, Redo, Cut, Copy, Paste, Clear, Select, and Find. These editing commands are used to modify portions of the active document or project. Not to give anything away here, but not having a standard menu bar with standard menus and menu items will cost you big time on your exam score.

Thanks

GUI Widgets in Detail

Widget Labels are strings of text used to identify other widgets. They aretypically placed to the left or above the widget being labeled.Buttons are rectangular-shaped widgets that are used to initiate actions by the system. A button can be used to initiate either an action command or a navigational command. The nature of the command controlled by the button is typically displayed as a “label” inside the boundary of the button.

Text fields and text areas are rectangular-shaped widgets that are used to either display textual data supplied by the system or as an area into which the user can type in data. Use a text field when you need no more than a single line, and a text area when the amount of data might exceed a single line. Text areas can have scroll bars (via the support widget called JScroll Pane), while text fields cannot. Text fields and text areas are typically festooned with a label placed above or to the left of the widget.

JRadioButton widget is named after the buttons found in car radios back in the good ol’ days. These mechanical arrays of buttons were designed so that each one, when pressed, would tune the radio to a particular station. One of the key features of these radio buttons was that only one button could be depressed (in other words, be active) at a time. When an inactive button was pressed, the currently active button would be undepressed, and functionally move to the inactive state.

The radio button widget works in much the same way; use it when you want the user to choose one and only one option from a list of options.JCheckBox widget is often associated with radio buttons. It has a slightly different look and feel, and a different (albeit related) functionality.
Like a radio button, the check box widget presents the user with a list of options. Unlike the radio button widget, the check box widget allows the user to select as many or as few choices as she or he wants.

So, radio buttons are mutually exclusive, but check boxes are not.JList widget presents the user with a list of entries, set inside a rectangle that can have a scroll bar. The entries are arranged in rows, one entry per row, so that the user can use a vertical scroll bar to search the list if there are more entries than can be displayed at one time. The list widget allows the user to select as few or as many entries as she or he wants.

JComboBox widget is part text field, part list. Whennot selected, the combo box resembles a text field with a down arrow button appended to its right end. The user can choose to key data into the field portion of the widget (like a text field), or choose the down arrow, which will cause a temporary list-like widget to appear.

The user can select an option from this temporary list in the same fashion that a normal list selection is made. Once the selection is chosen, it is placed into the text area of the widget and the list portion disappears.

Thanks

Essential Properties Of Graphical User Interface

A GUI will always be better if it’s designed with the help of the end-user community.No matter how many businesses you’ve helped to automate, or how many killer  GUIs  you’ve built in the past, end-user input is essential.Once we’ve got a rough idea what the system’s individual displays ought to look like, it’s time to move to the next level of design.

At this stage in the design, our goal is to create mockup displays that do more than simply satisfy the requirements of the use-cases. We also want to design screens that will be easy to learn, easy to use, and will not irritate the end users over time.Well-designed displays tend to be balanced. By balanced, we mean that the content is approximately balanced left to right and top to bottom.

Another attribute of good-looking displays is that they avoid the feeling of being cluttered. We return to the issue of clutter again later, but for now we mean that the screen elements should
be neatly aligned.Good GUI displays typically let the user issue a variety of commands to the system.For now, we split GUI commands into two broad categories: commands that cause
an action to take place within the current display (action commands), and commands that make the system jump to a new display (navigational commands).

A good rule of thumb is that action commands can occur wherever related elements are being
displayed, but that navigational commands will appear only in the menu bar or toolbar, or at the bottom of the display.Text fields and text areas are rectangular-shaped widgets that are used to either display textual data supplied by the system or as an area into which the user can type in data. Use a text field when you need no more than a single line, and a text area when the amount of data might exceed a single line.

Text areas can have scroll bars (via the support widget called JScroll Pane), while text fields cannot. Text fields and text areas are typically festooned with a label placed above or to the left of the widget.

Thanks

How To Make Use Of Class Granularity

A class should be of the right, you know, granularity. It shouldn’t be too big or too tiny. Rarely is the problem a class that’s too small; however, most not-quite-OO programmers make classes that are too big.A class is supposed to represent a thing that has state and behaviors. Keep asking yourself, as you write each method, if that behavior might not be better suited for some other thing.

For example, suppose you have a Kitchen class that does all sorts of Kitchen things. Like Oven things and Refrigerator things, etc. So now you’ve got Kitchen things (Kitchen being a room)
and Refrigerator things and Oven things all in the same class. That’s three different things. Classes (and thus the objects instantiated from them) really should be specialists. They should do the kinds of behaviors that a thing of that type should do, and no more.

So rather than having the Kitchen class include all the code for Refrigerator and Oven behaviors, have the Kitchen class use a Refrigerator and Oven in a HAS-A relationship. This keeps all three classes simple, and reusable. And that solves your naming problem, so that you don’t have to name your do-everything Kitchen class KitchenFridgeOven.

Another possible cause of a Big Class is that you’ve got too many inner classes defined. Too many meaning some of the inner classes should have been either top-level classes (for reuse) or simply methods of the enclosing class. Make sure your inner or nested classes really need to be included.If you need to make a new subclass to add important functionality, perhaps that
functionality should really be in the parent class (thus eliminating the need for the subclass—you just need to fix the superclass).

When you feel the need to extend a class, always look at whether the parent class should change, or whether you need composition (which means using HAS-A rather than IS-A relationships). Look in the core Java API for a clue about subclassing versus composition: the core API
inheritance hierarchy is really wide but very shallow. With a few exceptions (like GUI components), most class hierarchies are no more than two to three levels deep.

Thanks

Essential Properties Of Using Variables in Class

Don’t use variable names like x and y. What the heck does this mean: int x = 27;27  what? Unless you really think you can lock up job security by making sure nobody can understand your code (and assuming the homicidal maniac who tries won’t find you), then you should make your identifiers as meaningful as possible.They don’t have to be paragraphs. In fact, if it takes a paragraph to explain whata variable represents, perhaps you need to think about your design again.

Or at the least, use a comment. But don’t make them terse! Take a lesson from the core APIs. They could have called ArInBException, but instead they called it
ArrayIndexOutOfBoundsException. Is there any question about what that exception represents? Of course, the big Sun faux pas was the infamous NullPointerException. But despite the use of the forbidden word pointer, everybody knows what it means when they get it. But there could be some confusion if it were called NPTException or even NullException.

Do not reinvent the wheel, and do not—or you’ll automatically fail for certain—use any libraries other than code you developed and the core Java APIs. Resist any temptation to think that you can build something faster, cleaner, more efficient, etc.Even if that’s true, it isn’t worth giving up the benefit of using standard classes that others are familiar with, and that have been extremely, heavily tested in the field.

When you instantiate an Exception, call the constructor that takes a String (or the one that takes another lower-level exception if you’re doing exception chaining). When you create your own Exception class, be sure to put in a constructor that takes a String.

Thanks

Use Methods for standardizing the Class Functionalities

Objects are meant to have both state and behavior; they’re not simply glorified structs. If you need a data structure, use a Collection. There are exceptions to this,however, that might apply to your exam assignment. Sometimes you do need an object whose sole purpose is to carry data from one location to another—usually as a result of a database request.

A row in a table, for example, should be represented as an object in your Java program, and it might not always need methods if its sole job is to be, say, displayed in a GUI table. This is known as the ValueObject pattern.In general, the more public stuff you expose to the world, the less free you are to make changes later without breaking someone else’s code. The less you expose, the more flexibility you have for implementation changes later.

And you know there are always changes. So, making variables, methods, and classes as restricted as you can while limiting what you expose to your “public interface,” you’ll be in good shape down the road. Obviously there are other subtle issues about inheritance (as in, what does a subclass get access to?), so there’s more to consider here, but in general, be
thinking about reducing your exposure (think of it as reducing your liability down
the road).

This is closely related to reducing the scope of variables.If you have a ton of arguments coming into a method, perhaps you need to encapsulate the stuff you need in that method into a class of its own type.

Use polymorphic arguments, return types, and variables whenever possible (in other words, declare a variable, return type, or argument as an interface type rather than a specific class type). Using an interface as the type lets you expose only the definition of what your code can do, and leaves the implementation flexible and extensible and maintainable.

Thanks

Genaral COnsiderations for Programming Knowledge

The general considerations for programming  looks for consistency and appropriateness in your programming style. The following will  lists some key points you should keep in mind when writing your perfectly-formatted code. Some of these will be explained in subsequent sections; several of these points are related to OO design,for example, and we cover them in more detail in that section.

Once again, this is no time to debate the actual merits of these principles. Again, imagine you’ve come into a project team and need to prove yourself as a, what? Yes! Team Player. The first thing the team is looking for is whether you can follow the conventions and standards so that everyone can work together without wanting to throw one another out the seventh floor window and onto the cement fountain below. (Unless you’re a dot-com company and your office now looks over an abandoned gas station.)

These points are in no particular order, so don’t infer that the first ones are more important than the last. You can infer, however, that your exam assessor will probably be asking if you’ve done these things appropriately.Don’t use an instance variable when a local variable will work! Not only does this impact memory use,but it reduces the risk that an object “slips out” to some place it shouldn’t be used, either accidentally or on purpose.

Wait to declare a variable until just before it’s used. And you should always initialize a local variable at the time it is declared (which is just before use), with the exception of try/catch blocks.In that case, if the variable is declared and assigned in the try/catch block, the compiler
won’t let you use it beyond that block, so if you need the variable after a try or catch block, then you’ll have to declare it first outside the try/catch.

Thanks

Architecture For Java Server Pages

The  architecture for servlets & JSP  uses three layers: (1) the presentation layer,or user interface layer, (2) the business rules layer, and (3) the data access layer. In theory, the programmer tries to keep these layers as separate and independent as possible. In practice, though, these layers are often interrelated and that’s especially true for the business and data access layers.
The presentation layer consists of HTML pages and JSPs. Typically, a web designer will work on the HTML stored in these pages to create the look and feel of the user interface. Later, a Java programmer may need to edit these pages so they work properly with the servlets of the application.
The business rules layer uses servlets to control the flow of the application.These servlets may call other Java classes to store or retrieve data from a database, and they may forward the results to a JSP or to another servlet. Within the business layer, Java programmers often use a special type of Java class known as a JavaBean to temporarily store and process data. A JavaBean is typically used to define a business object such as a User or Invoice object.


The data layer works with data that’s stored on the server’s disk. For aserious web application, this data is usually stored in a relational database. However, this data can also be stored in text files and binary files. In addition,the data for an application can be stored in a special type of file that uses Extensible Markup Language, or XML.
• The presentation layer for a typical Java web application consists of HTML pages and
JSPs.
• The business rules layer for a typical Java web application consists of servlets. These
servlets may call other Java classes including a special type of Java class known as a
JavaBean. Chapter 8 will show how to work with JavaBeans.
• The data access layer for a typical Java web application consists of classes that read and
write data that’s stored on the server’s disk drive.
• For a serious web application, the data is usually stored in a relational database. However,
it may also be stored in binary files, in text files, or in Extensible Markup Language
(or XML) files.

Thanks

Available Platforms Necessary for JSP & Servlets

When you use a single PC, you of course need to install all of the required software on that PC. That includes the Java SDK, the web server software, the servlet and JSP engine, and the database management system.In particular, it includes Tomcat, which functions as both a web server and a servlet and JSP engine. It also includes MySQL, which is a DBMS.When you work on a LAN, you can use the same software components, but you divide them between client and server.

To compile and run servlets on the server, the server requires the Java SDK, a combined web server and servlet and JSP engine like Tomcat, and a DBMS like MySQL. To compile servlets on a
client, the client requires the Java SDK and the servlet.jar file, which contains all of the classes required for servlet development in a compressed format.

This JAR file comes with Tomcat, but you can also download it for free from the Sun web site. When you run a web application on a LAN like this, it functions as an intranet. When you work over the Internet, you use the same general components as you do when you work over an intranet. To improve performance, though, you normally have a separate web server like Apache in addition to a servlet and JSP engine like Tomcat.

If necessary, you can also improve the performance of an intranet application by using Apache as the web server. Since the SDK, Apache, Tomcat, and MySQL can be run by most operating
systems, Java web developers aren’t tied to a specific operating system. In fact, the Windows operating system is commonly used for both the client and server computers during development.

But when the applications are ready for use, they are often deployed on a Unix or Solaris server.
When you develop web applications, you can work on platforms at three levels.  If you want to develop web applications on your own PC, you need to install the Java SDK, a web server, a servlet and JSP engine, and a DBMS.
• If you’re working in a small group on a Local Area Network (LAN), the server can run
Tomcat as both the web server and the servlet and JSP engine, and MySQL as the
DBMS. Then, the client just needs the Java SDK and the servlet.jar file, which isn’t part
of the SDK. When you run web applications on a LAN, it functions as an intranet.
• If you’re working in a group over the Internet, you normally use a product like Apache as
the web server and a product like Tomcat as just the servlet and JSP engine. Otherwise,
this works the same as when you’re working over a LAN.

Thanks.

An Intro To Servlet Programming

In contrast to the JSP, the servlet is a Java class that runs on a server and does the processing for the dynamic web pages of a web application. That’s why servlets for a web application are written by web programmers, not web designers.After the processing is done, the servlet returns HTML code to the browser by using the println method of an out object. Note, however, that this makes it more difficult to code the HTML.

In case you’re interested, each servlet for a web application is a Java class that extends (or inherits) the HttpServlet class. Then, each servlet can override the doGet method of the inherited class, which receives both a request and a response object from the web server, and the servlet can get the parameters that have been passed to it by using the getParameter method of the request object.

After that, the servlet can do whatever processing is required by using normal Java code.As you have seen, servlets are actually Java classes so it makes sense to use them for the processing requirements of the web pages in an application.A Sample code using servlet and java is shown below:

public class EmailServlet extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException{
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
String firstName = request.getParameter(“firstName”);
String lastName = request.getParameter(“lastName”);
String emailAddress = request.getParameter(“emailAddress”);
out.println(
“<html>\n”
+ “<head>\n”
+ ” <title>Chapter 5 – Email List application</title>\n”
+ “</head>\n”
+ “<body>\n”
+ “<h1>Thanks for joining our email list</h1>\n”
+ “<p>Here is the information that you entered:</p>\n”
+ ” <table cellspacing=\”5\” cellpadding=\”5\” border=\”1\”>\n”
+ ” <tr><td align=\”right\”>First name:</td>\n”
+ ” <td>” + firstName + “</td>\n”
+ ” </tr>\n”
+ ” <tr><td align=\”right\”>Last name:</td>\n”
+ ” <td>” + lastName + “</td>\n”
+ ” </tr>\n”
+ ” <tr><td align=\”right\”>Email address:</td>\n”
+ ” <td>” + emailAddress + “</td>\n”
+ ” </tr>\n”
+ ” </table>\n”
+ “</html>);


Similarly, JSPs are primarily HTML code so it makes sense to use them for the
design of the web pages in an application.The solution is for a servlet to do the processing for each web page, and then forward the request and response objects to the JSP for the page. That way, the servlet does all the processing, and the JSP does all of the HTML.

With this approach, the JSP requires a minimum of embedded Java code. And that means
that the web designer can write the JSPs with little or no help from the Java programmer, and the Java programmer can write the servlets without worrying about the HTML.

Thanks

Java Server Pages – An Introduction

If you’re already familiar with HTML, you can see that most of this JSP consists of HTML code. In fact, the only Java code in this JSP is shaded. That’s why JSPs are relatively easy to write if you know HTML and keep the Java to a minimum. If a JSP requires extensive Java programming, though, it’s easier to write the Java code with a servlet. In practice, web designers often write the HTML portions of the JSPs, while web programmers write the Java portions.

In case you’re interested, the first three lines of Java code in this JSP get three parameters from the request object that has been passed to it. To do that, the code uses the getParameter method of the object. Then, the three Java expressions that are used later in the JSP refer to the String variables that store the parameters.

When a JSP is requested for the first time, the JSP engine (which is part of the servlet and JSP engine) converts the JSP code into a servlet and compiles the servlet. Then, the JSP engine loads that servlet into the servlet engine, which runs it. For subsequent requests, the JSP engine runs the servlet that corresponds to the JSP.A sample JSP is shown below:
<head>
<title>Chapter 4 – Email List application</title>
</head>
<body>
<%
String firstName = request.getParameter(“firstName”);
String lastName = request.getParameter(“lastName”);
String emailAddress = request.getParameter(“emailAddress”);
%>
<h1>Thanks for joining our email list</h1>
<p>Here is the information that you entered:</p>
<table cellspacing=”5″ cellpadding=”5″ border=”1″>
<tr>
<td align=”right”>First name:</td>
<td><%= firstName %></td>
</tr>
<tr>
<td align=”right”>Last name:</td>
<td><%= lastName %></td>
</tr>
<tr>
<td align=”right”>Email address:</td>
<td><%= emailAddress %></td>
</tr>
</table>


A JavaServer Page, or JSP, consists of Java code that is embedded within HTML code.
This makes it easy to write the HTML portion of a JSP, but harder to write the Java code.
When a JSP is first requested, the JSP engine translates it into a servlet and compiles it.
Then, the servlet is run by the servlet engine.

Thanks.