Tuesday, November 4, 2014

Slowing Down Some. No Rush. No Worries.


Team. While we let the embryo grow, let us look at the next step. Each step will be achieved a week at a time. This will allow sufficient learning time for the neophyte JAVA programmer. My goal is that no blog reader be left behind. This week’s step will be the processing of the output HTML file with a buffered file reader. This requires using some classes from the java.io.* package which handles file processing and the exceptions associated with files. For those of you who are not familiar with computing abstractions, one views every source of data or place which one puts data as a file. Each file has a special number which describes it location. This number is called the “file handle” since with it one can “handle” and control the follow of data in or out of a file.

In JAVA, one can get a handle on a file by creating a reader or writer for that entity. The file reader which JAVA provides does not allow for buffering which streamlines processing. So, one must wrap the file reader with an object which provides this:

java.io.BufferedReader aBufferedReader =

new java.io.BufferedReader( new java.io.FileReader( aXHTMLStencilFileName ) );

The fully qualified names for the objects are provided here. This reinforces the name and purpose of the packages from which they come. We will eventually rewrite our code with import statements and the above will become:

Import java.io.*;


BufferedReader aBufferedReader =

new BufferedReader( new FileReader( aXHTMLStencilFileName ) );

When one processes a file, certain exceptions can occur. One being the file is not found based on the name given. JAVA has mechanisms for handling such conditions when they arise. These are the subclasses of the exception object and the try-catch-finally construct. With this construct, one places any instructions which might generate an exception within the try portion and uses one or more catch portions for processing specific exception types. The finally portion is for any “final” housekeeping which must be done. However, we will not use this approach yet. For simplicity, we will let any exception which occurs be thrown upward until it reaches the top-level of our program and we will print an exception message stack trace at that point. This will increase the simplicity in development. We can increase the sophistication of the exception handling in the future.

Another goal for this week is creating a validated XHTML template which we will use as a basis for all of our front-end scripting. The HTML snippet in the current example is not based on a current valid XHTML standard.

So skim, the java.io.package (especially the BufferedReader and FileReader ) plus a simple quality XHTML tutorial. Also, try the XHTML validator at http://validator.w3.org/.
If you are a new programmer, I hope that by now you are on your second chapter of the Art & Science of JAVA and enjoying the SEE classes. Also if you are a professional programmer, you should have at least covered the chapters covering control statements, primitive types, and basic objects in Schildt’s JAVA text. Also, the professional might like the freshman refresher provided by the SEE JAVA course.

Next, week we will extract the XHTML stencil filename from an XML parameter file. The following week, we will generate the XHTML source using reflection and the XML  parameter file. Initially, those were the goals for this week, but I thought “Why rush it?” Let us do some ruminating and reasoning. The bird brain philosophy is best “hunt-peck-think”!

So let’s slow down some and do some learning along the way!

Talk with tomorrow. La-La.

No comments:

Post a Comment