|
|
Applications:
From the time you begin programming you start to develop a style of writing programs much
the same as someone who writes stories develops a style. If you write software only for
your own use and you will be the only one maintaining it, then the most important thing
about your style is that it produces results you are happy with. If, however, you write
software that will be extended and/or maintained by others there are some important
elements you should incorporate into your style. Your success in this will have a direct
impact on the amount of mean nasty e-mails you receive and your ability succeed and prosper
in software development.
High quality in software, in large measure, dependants on the consistency with which it is
written. Certainly, there are other factors that will impact on the quality of your
programs, but for now I'll concentrate on consistency. Part of your style will need to be
consistency; that is doing things in the same way. Part of this comes naturally, as I have
never yet met someone that likes to rewrite code they have already written. The usual
practice is to use and build libraries of standard objects and methods that can easily be
pulled from a library and reused in a new program. All programming environments come with
such libraries and provide a means for you to add your own libraries of objects and methods.
This saves you the effort of rewriting code and saves on debugging since before you put
something into the library you make sure it is thoroughly tested.
Applets require certain methods (as in behavior of a class). Good programming practice
as taught by the Sun Java Tutorial and other sources of training require certain additional
methods and practices. For instance, browsers depend on applets having methods for
initialization (init()), to start the applet (start()), to stop the applet (stop()), and to
destroy the applet (destroy()). Add to this elements like code that is always neat; that
has lots of white space, lots of comments, the brackets line up, and the various elements
of a class, function, object, or method are in predictable places. These put you well on
the road to software that is written consistently.
Using this model for programming an applet with the defined control mechanisms and the
other features described above will serve well for application programs as well. In case
you haven't read the other articles in my Java pages yet, the difference between an
applet and an application is: An application will run on a computer with out the need for
a web browser. An Applet only runs in the context of a web browser under the direct control
the web browser. As it turns out, it is very straightforward to take a program of this
structure and make both applet and application versions. This is another way in which
consistence can be brought to your program code. Now certainly I have written applets that
I doubt I will ever want application versions of and visa versa. This doesn't negate the
value of this addition consistency in writing style.
All Java applications require a main() method. This is where the Java Virtual Machine (JVM)
looks to start execution. A program structured as described above can be used as an applet
or an application. The application version will have a main() method which controls the
application via the init(), start(), etc. methods that are part of the consistent structure.
In the case of an applet, it may use space allocated on a web page to present itself. An
application version would include a JFrame to be the main application window. In the case
of the Java Toy Compulator, this program is an applet that already uses a JFrame to display
the applet in a separate window from the browser. In this case the application version was
simpler to make since the window for the application to use was already programmed in.
Java provides nicely for programming consistency. Further, both applet and application
versions of a given program can be created that differ in predictable ways that further
enhance consistency in program creation.
Go to my:
Java Toys
The links at the bottom of your screen will take you to the main topic areas