<?xml version="1.0" encoding="ISO-8859-1"?><document xmlns:cinclude="http://apache.org/cocoon/include/1.0"><header><title>Java Workshop</title></header><body><section><title>About</title>
    <section class="page" id="index.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Welcome to the Java Workshop</title>
        <p><em>The programs in this book have been included for instructional value, the author does not offer any warranties or representations in respect of their fitness for a particular purpose, nor does the publisher accept any liability for any loss or damage arising from their use.</em></p>
        <section>
            <title>About The Book</title>            
            <section>
                <title>Introduction</title>
                <p>The original idea behind the Java Workshop was to introduce some of the practicalities faced when developing software using the Java Platform. As such, the original book focused on developing software using the Java Platform and not so much on the tools or the practical side of things. In revising the text, I decided to shift the focus somewhat to a new direction, the tools that a Java Developer should have in his / her toolbox.</p>
                <p>It has often been said that the right tools for the job can make the job a lot easier. This is even more so when one considers the practice of developing software. When one uses the right tools, suddenly the task at hand becomes easier and quicker to accomplish creating a marked improvement in productivity. This book therefore focuses on the practical aspects of developing in Java specifically looking at common tasks and at the tools that make accomplishing these tasks easier and faster.</p>
                <p>This is not a book that teaches Java. Instead it is a book that showcases typical tools found in a Java developer's toolbox. If you are looking for a book that teaches Java you should look elsewhere and once you've found such a book, you should couple it with this one, I guarantee the result will be worth it.</p>
            </section>
            <section>
                <title>An "Open Source Book"?</title>
                <p>The idea behind this is far from original. Credit must be given to Bruce Eckel's <strong>Thinking in Java</strong>, which is freely available on the web and also available in printed format. While I used a similar concept, the Java Workshop differs fundamentally in that it may be redistributed and modified, much like open source software. For those that are a little finicky about details, the license is available here: <link href="#licence.html">License</link>.</p>
            </section>
            <section>
                <title>Who The Book Is For</title>
                 <p>This book is for anyone interested in Java. Whether that interest is purely in an academic sense or truly a passion for the language, I hope that everyone can gain something from this book. </p>
                 <p>The target audience is specifically students who are learning Java for the first time. I remember when I first learnt Java, many of the trivialities were far from trivial and even the simple task of setting an environment variable was no small feat. I hope that if anything, this book will help students to accomplish these and many more trivial tasks and that they will not seem like small miracles. </p>
                 <p>The goal of this book is to introduce students to the practicalities of the Java language and provide them with enough references to pursue the topic further. In this regard, each topic is presented in a simplistic manner and a topic does not cover all there is, especially those topics that are extremely broad like XML. Rather a brief introduction is given and then a list of suitable references for further information.</p>
            </section>
        </section>
        <section>
            <title>Overview</title>
            <p>Ironically my vision for the first edition was to showcase a number of tools for Java developers, however the book also included a large amount of theoretical content which was contrary to the idea of an introduction to the practicalities of programming with the Java platform; this second edition is much closer to a manifestation of that original vision than the first edition was.</p>
            <p>I focused each chapter around a certain piece of software that I have found exceedingly useful, a tool that I consider to be an essential item in each developer's toolbox. This means that each chapter focuses around performing a specific task.</p>
            <section>
                <title>Topics Presented In The Book</title>
                <section>
                    <title><strong>Installing The Java Development Kit</strong></title>
                    <p>Installing the Java Development Kit (JDK) is not difficult but it can be tricky for people that have never done it before. One of the most important learning experiences novice programmers can have is to install the JDK an     set the PATH variable. Not only is it an enriching experience but also the satisfaction gained from accomplishing this task is monumental. I hope that the steps outlined in this theme will guide many to successfully install Java on their computers.</p>
                </section>
                <section>
                    <title><strong>Using The Eclipse Integrated Development Environment</strong></title>
                    <p>With all the IDEs available, many students may wish to become familiar with one of them and use it to write their programs with. The choice of which IDE to use is not an easy one, yet Eclipse has become the industry standard IDE surpassing many of its competitors. This chapter will look at installing and using this invaluable tool that every Java Developer should have.</p>
                </section>
                <section>
                    <title><strong>Creating and Using Java Packages</strong></title>
                    <p>Understanding Java Packages is key when one wishes to organize one's source code and this chapter will look at how to create and use Java Packages.</p>
                </section>
                <section>
                    <title><strong>Using the Javadoc Tool to Produce an Application Programmer Interface</strong></title>
                    <p>This chapter will focus on the importance of comments and the correct way to write Javadoc comments and will show how to use the Javadoc tool to produce an API. </p>
                </section>
                <section>
                    <title><strong>Using the Jar Tool to Create Libraries and Executable Java Archive Files</strong></title>
                    <p>Java Archives or jar files have become the most popular form of packaging and distributing Java software. It is thus imperative for students to understand what a jar file actually is, how to create one, view the contents and extract the contents as well as package software in an executable jar file.</p>
                </section>
                <section>
                    <title><strong>Using Apache Ant to Simplify the Build Process</strong></title>
                    <p>Small projects can quite easily be compiled from the command-line. Medium to large projects can become tedious to compile and package and therefore a build tool of some sort can make the process easier. In this regard, Apache Ant is simply the best build tool available. This chapter will discuss Ant and how to use it. </p>
                </section>
                <section>
                    <title><strong>Using JUnit Framework to Perform Unit Testing</strong></title>
                    <p>Unit testing is perhaps one of the most important aspects of software development. This chapter looks at how unit testing can be performed using the JUnit package.</p>
                </section>
                <section>
                    <title><strong>Using Apache Log4J to Perform Logging</strong></title>
                    <p>Logging is a very important way of debugging code as it provides a mechanism to see what a program is doing at every step of the way. This chapter looks at logging using the Apache Log4J package.</p>
                </section>
                <section>
                    <title><strong>Processing XML with Apache Xerces</strong></title>
                    <p>XML is used in a number of places and it is useful to know how to process it. This chapter will look at how to process XML using the Xerces parser as well as perform transformations using Apache Xalan.</p>
                </section>
            </section>
        </section>
        <section>
            <title>Software and Versions Used</title>
            <p>Keeping up to date with rapidly changing technologies is difficult at best. Below is the list of software and versions used during the writing of this book, by the time you read this there will no doubt be newer versions of some if not all the software listed below.</p>
            <table>
                <tr>
                    <th colspan="1" rowspan="1">Tool</th>
                    <th colspan="1" rowspan="1">URL</th>
                    <th colspan="1" rowspan="1">Chapter</th>
                    <th colspan="1" rowspan="1">Description</th>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">JDK 1.5.0</td>
                    <td colspan="1" rowspan="1"><link href="http://java.sun.com">java.sun.com</link></td>
                    <td colspan="1" rowspan="1">1, 3-5</td>
                    <td colspan="1" rowspan="1">The Java 2 Standard Edition SDK</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">Eclipse 3.0</td>
                    <td colspan="1" rowspan="1"><link href="http://www.eclipse.org">eclipse.org</link></td>
                    <td colspan="1" rowspan="1">2</td>
                    <td colspan="1" rowspan="1">The Eclipse IDE</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">Apache Ant 1.6.5</td>
                    <td colspan="1" rowspan="1"><link href="http://ant.apache.org">ant.apache.org</link></td>
                    <td colspan="1" rowspan="1">6</td>
                    <td colspan="1" rowspan="1">The Apache Ant build tool</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">JUnit 3.2</td>
                    <td colspan="1" rowspan="1"><link href="http://junit.sourceforge.net">junit.sourceforge.net</link></td>
                    <td colspan="1" rowspan="1">7</td>
                    <td colspan="1" rowspan="1">JUnit unit testing framework</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">Apache Log4J 1.2.11</td>
                    <td colspan="1" rowspan="1"><link href="http://logging.apache.org">logging.apache.org</link></td>
                    <td colspan="1" rowspan="1">8</td>
                    <td colspan="1" rowspan="1">Apache Log4J logging framework</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">Apache Xerces 2.7.1</td>
                    <td colspan="1" rowspan="1"><link href="http://xml.apache.org">xml.apache.org</link></td>
                    <td colspan="1" rowspan="1">9</td>
                    <td colspan="1" rowspan="1">Apache Xerces XML parser</td>
                </tr>
                <tr>
                    <td colspan="1" rowspan="1">Apache Xalan 2.7.0</td>
                    <td colspan="1" rowspan="1"><link href="http://xml.apache.org">xml.apache.org</link></td>
                    <td colspan="1" rowspan="1">9</td>
                    <td colspan="1" rowspan="1">Apache Xalan XML Transformation tool</td>
                </tr>
            </table>
        </section>
        <section>
        &#9;<title>Conventions Used</title>
        &#9;<p><em>Italic</em> is used for emphasis.</p>
        &#9;<p><code>Constant width</code> is used for all code fragments, paths and filenames.</p>
        &#9;<p><em><code>Constant width italic</code></em> is used for general placeholders that indicate some item is replaced for an actual value.</p>
        &#9;<p><strong><code>Constant width bold</code></strong> is used for emphasis in a code fragment.</p>
        </section>
        <section>
            <title>Reach Out</title>
            <p>I would like your feedback. After you have had a chance to use this book please take a moment to e-mail me with your evaluation. I'd like to know what you liked, what was useful and more importantly what wasn't of use. Although I will read all mails I recieve, I cannot guarantee a reply.</p>
            <p><code>tcmiller@users.sourceforge.net</code></p>
            <p>Despite numerous efforts to ensure this book is error free, some errors have most likely slipped through. Even still, some of the material in this book will change or no longer be applicable over time. Please let me know of any errors or omissions in this text.</p>
            <p>Trevor C. Miller</p>
            <p><em>Pretoria, South Africa, January 5, 2006</em></p>
        </section>
        <section>
            <title>Acknowledgements</title>
            <p>This book would not have been possible if it were not for the aid and assistance of a number of people. First I would like to thank the people of Sun Microsystems, the Apache Software Foundation, IBM, and of course the Fedora Linux Community. All the software used to write this book came from these organizations that have all produced open source software of such a high standard that it often exceeds that of commercial software. The book was written on Windows using custom software that I wrote to produce the XML content. This was then transformed into static HTML using Apache Forrest. The book was also tested on Linux using Fedora Core.</p>
            <p>I wish to thank all those wonderful people that I've had the pleasure tutoring and teaching, whether it was Java, C, C++ or Delphi. These people truly inspired me by persevering, and in those times they even challenged me by asking awkward questions that I at times didn't have an answer for. While I was teaching programming to these people, they in return taught me much; about teaching, about people and most importantly, about myself. To them I am ever grateful.</p>
            <p>Lastly, writing this book wouldn't have been possible if it weren't for the music of Leftfield, Michelle Branch and 30 Seconds To Mars.</p>
        </section>
    </section>
    <section class="page" id="download.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Download the Java Workshop</title>
&#9;&#9;<section>
&#9;&#9;&#9;<title>Editions</title>
&#9;&#9;&#9;<p>You can get the latest edition <link href="http://sourceforge.net/project/showfiles.php?group_id=157002">here</link>.</p>
&#9;&#9;</section>
&#9;&#9;<section>
&#9;&#9;&#9;<title>Extracting The Archives</title>
&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;<title>Windows</title>
&#9;&#9;&#9;&#9;<p>It is recommended that you download the zip distribution archive. Windows XP has a native built-in Zip tool that allows you to extract zip archives. Other versions can use the Jar tool bundled with the JDK to extract the contents of the archive. Tools like Winzip and ZipGenius can extract the zip archive as well as the tarball.</p>
&#9;&#9;&#9;</section>
&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;<title>Linux / Unix</title>
&#9;&#9;&#9;&#9;<p>Most Linux and Unix distributions have the <code>tar</code> utility so it is recommended that you download the tarball. If you do not have <code>tar</code> you may have <code>unzip</code> in which case it is advisable to get the zip archive. If you do not have any of these utilities you can use the Jar tool bundled with the JDK to extract the contents of the zip archive.</p>
&#9;&#9;&#9;</section>
&#9;&#9;</section>
    </section>
    <section class="page" id="licence.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Java Workshop Licence</title>
        <p><strong>Licensed under the Academic Free License version 2.1</strong></p>
        <source xml:space="preserve">
This Academic Free License (the "License") applies to any original work 
of authorship (the "Original Work") whose owner (the "Licensor") has 
placed the following notice immediately following the copyright notice 
for the Original Work: 

Licensed under the Academic Free License version 2.1 

1) Grant of Copyright License. Licensor hereby grants You a world-wide, 
   royalty-free, non-exclusive, perpetual, sublicenseable license to do 
   the following: 

A. to reproduce the Original Work in copies; 
B. to prepare derivative works ("Derivative Works") based upon the Original 
   Work; 
C. to distribute copies of the Original Work and Derivative Works to the 
   public; 
D. to perform the Original Work publicly; and 
E. to display the Original Work publicly. 

2) Grant of Patent License. Licensor hereby grants You a world-wide, 
   royalty-free, non-exclusive, perpetual, sublicenseable license, under 
   patent claims owned or controlled by the Licensor that are embodied in 
   the Original Work as furnished by the Licensor, to make, use, sell and 
   offer for sale the Original Work and Derivative Works. 

3) Grant of Source Code License. The term "Source Code" means the preferred 
   form of the Original Work for making modifications to it and all available 
   documentation describing how to modify the Original Work. Licensor hereby 
   agrees to provide a machine-readable copy of the Source Code of the 
   Original Work along with each copy of the Original Work that Licensor 
   distributes. Licensor reserves the right to satisfy this obligation by 
   placing a machine-readable copy of the Source Code in an information 
   repository reasonably calculated to permit inexpensive and convenient 
   access by You for as long as Licensor continues to distribute the Original 
   Work, and by publishing the address of that information repository in a 
   notice immediately following the copyright notice that applies to the 
   Original Work. 

4) Exclusions From License Grant. Neither the names of Licensor, nor the 
   names of any contributors to the Original Work, nor any of their 
   trademarks or service marks, may be used to endorse or promote products 
   derived from this Original Work without express prior written permission 
   of the Licensor. Nothing in this License shall be deemed to grant any rights 
   to trademarks, copyrights, patents, trade secrets or any other intellectual 
   property of Licensor except as expressly stated herein. No patent license is 
   granted to make, use, sell or offer to sell embodiments of any patent claims 
   other than the licensed claims defined in Section 2. No right is granted to 
   the trademarks of Licensor even if such marks are included in the Original 
   Work. Nothing in this License shall be interpreted to prohibit Licensor from 
   licensing under different terms from this License any Original Work that 
   Licensor otherwise would have a right to license. 

5) This section intentionally omitted. 

6) Attribution Rights. You must retain, in the Source Code of any Derivative 
   Works that You create, all copyright, patent or trademark notices from the 
   Source Code of the Original Work, as well as any notices of licensing and 
   any descriptive text identified therein as an "Attribution Notice." You must 
   cause the Source Code for any Derivative Works that You create to carry a 
   prominent Attribution Notice reasonably calculated to inform recipients that
   You have modified the Original Work. 

7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that 
   the copyright in and to the Original Work and the patent rights granted 
   herein by Licensor are owned by the Licensor or are sublicensed to You 
   under the terms of this License with the permission of the contributor(s) 
   of those copyrights and patent rights. Except as expressly stated in the 
   immediately proceeding sentence, the Original Work is provided under this 
   License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied,
   including, without limitation, the warranties of NON-INFRINGEMENT, 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO 
   THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY 
   constitutes an essential part of this License. No license to Original 
   Work is granted hereunder except under this disclaimer. 

8) Limitation of Liability. Under no circumstances and under no legal theory, 
   whether in tort (including negligence), contract, or otherwise, shall the 
   Licensor be liable to any person for any direct, indirect, special, 
   incidental, or consequential damages of any character arising as a 
   result of this License or the use of the Original Work including, 
   without limitation, damages for loss of goodwill, work stoppage, 
   computer failure or malfunction, or any and all other commercial 
   damages or losses. This limitation of liability shall not apply to 
   liability for death or personal injury resulting from Licensor's 
   negligence to the extent applicable law prohibits such limitation. 
   Some jurisdictions do not allow the exclusion or limitation of 
   incidental or consequential damages, so this exclusion and limitation 
   may not apply to You. 

9) Acceptance and Termination. If You distribute copies of the Original 
   Work or a Derivative Work, You must make a reasonable effort under the 
   circumstances to obtain the express assent of recipients to the terms 
   of this License. Nothing else but this License (or another written 
   agreement between Licensor and You) grants You permission to create 
   Derivative Works based upon the Original Work or to exercise any of 
   the rights granted in Section 1 herein, and any attempt to do so except 
   under the terms of this License (or another written agreement between 
   Licensor and You) is expressly prohibited by U.S. copyright law, the 
   equivalent laws of other countries, and by international treaty. 
   Therefore, by exercising any of the rights granted to You in Section 
   1 herein, You indicate Your acceptance of this License and all of its 
   terms and conditions. 

10) Termination for Patent Action. This License shall terminate 
    automatically and You may no longer exercise any of the rights granted 
    to You by this License as of the date You commence an action, including 
    a cross-claim or counterclaim, against Licensor or any licensee alleging 
    that the Original Work infringes a patent. This termination provision 
    shall not apply for an action alleging patent infringement by combinations 
    of the Original Work with other software or hardware. 

11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this 
    License may be brought only in the courts of a jurisdiction wherein the 
    Licensor resides or in which Licensor conducts its primary business, and 
    under the laws of that jurisdiction excluding its conflict-of-law 
    provisions. The application of the United Nations Convention on Contracts 
    for the International Sale of Goods is expressly excluded. Any use of the 
    Original Work outside the scope of this License or after its termination 
    shall be subject to the requirements and penalties of the U.S. Copyright 
    Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, 
    and international treaty. This section shall survive the termination of 
    this License. 

12) Attorneys Fees. In any action to enforce the terms of this License or 
    seeking damages relating thereto, the prevailing party shall be entitled 
    to recover its costs and expenses, including, without limitation, 
    reasonable attorneys' fees and costs incurred in connection with such 
    action, including any appeal of such action. This section shall survive 
    the termination of this License. 

13) Miscellaneous. This License represents the complete agreement concerning 
    the subject matter hereof. If any provision of this License is held to be 
    unenforceable, such provision shall be reformed only to the extent 
    necessary to make it enforceable. 

14) Definition of "You" in This License. "You" throughout this License, 
    whether in upper or lower case, means an individual or a legal entity 
    exercising rights under, and complying with all of the terms of, this 
    License. For legal entities, "You" includes any entity that controls, 
    is controlled by, or is under common control with you. For purposes of 
    this definition, "control" means (i) the power, direct or indirect, to 
    cause the direction or management of such entity, whether by contract or 
    otherwise, or (ii) ownership of fifty percent (50%) or more of the 
    outstanding shares, or (iii) beneficial ownership of such entity. 

15) Right to Use. You may use the Original Work in all ways not otherwise 
    restricted or conditioned by this License or by law, and Licensor 
    promises not to interfere with or be responsible for such uses by You. 

This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights 
reserved. Permission is hereby granted to copy and distribute this 
license without modification. This license may not be modified without 
the express written permission of its copyright owner. 

        </source>
    </section>
&#9;
  </section><section><title>Chapters</title>
    <section class="page" id="chapter1.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Installing Java</title>
        <section>
            <title>Jargon</title>
            <dl>
                <dt><strong>API</strong></dt>
                <dd><em>Application Programming Interface</em>, Set of related classes and methods that provide certain functionality. The API represents the parts of a class exposed through access modifiers to code written by other programmers.</dd>
                <dt><strong>Compiler</strong></dt>
                <dd>A computer program that translates a high-level programming language into machine language. The program fed into the compiler is called the source program; the generated machine language program is called the object program.</dd>
                <dt><strong>Computer</strong></dt>
                <dd>An electronic device that has the ability to store, retrieve, and process data, and can be programmed with instructions that it remembers. The physical parts that make up a computer (the central processing unit, input, output, and memory) are called hardware. Programs that tell a computer what to do are called software.</dd>
                <dt><strong>Environment Variable</strong></dt>
                <dd>A variable that specifies how an operating system or another program runs, or the devices that the operating system recognizes.</dd>
                <dt><strong>JDK</strong></dt>
                <dd><em>Java Development Kit</em>, A software package that contains the minimal set of tools needed to write, compile, debug, and run Java applets and applications.</dd>
                <dt><strong>Java</strong></dt>
                <dd>Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly.</dd>
                <dt><strong>Platform</strong></dt>
                <dd>In computing, a platform describes some sort of framework, either in hardware or software, which allows software to run. Typical platforms include a computer's architecture, operating system, or programming languages and their runtime libraries.</dd>
                <dt><strong>Program</strong></dt>
                <dd>A set of intangible instructions that tells a computer how to operate. Computer programs are also known as software.</dd>
                <dt><strong>SDK</strong></dt>
                <dd><em>Software Development Kit</em> A set of programs that allows software developers to create products to run on a particular platform or to work with an API.</dd>
                <dt><strong>Software</strong></dt>
                <dd>A computer program that helps the user accomplish a specific task; for example, a word processing program. Application programs should be distinguished from system programs, which control the computer.</dd>
            </dl>
        </section>
        <section>
            <title>Introduction</title>
            <p>In order to develop software using the Java language you will need to install a suitable compiler and interpreter on your computer. This will enable you to compile and run Java programs that you write.</p>
            <p>This is not a complex process but varies depending on which platform you use. The platform will dictate the method you use to set variables as different platforms use different methods for achieving this task. Windows itself has different ways depending on which version of Windows you use. Linux and Unix based platforms also have numerous different ways of performing the same task.</p>
            <p>Once you have installed Java, you may wish to consult some references. There are a number of excellent references available to Java programmers; some of these include Sun Microsystems's Java Page and the Java API.</p>
            <p>You can get the JDK @ <link href="http://java.sun.com">java.sun.com</link></p>
        </section>
        <section>
            <title>How to install the JDK</title>
            <p>For this installation, the latest version of Java was used at the time of writing, Java 1.5.0, but previous and later versions should work just fine.</p>
            <section>
                <title>Microsoft Windows 95</title>
                <section>
                    <title>Installing the JDK</title>
                    <ol>
                        <li>
                            <p>Run the setup program <code>jdk-1_5_0-windows-i586.exe</code></p>
                            <p><img src="images/howto_java_95_01.jpg" alt="Running the setup program."/></p>
                        </li>
                        <li>
                            <p>Click "Continue" on the warning message.</p>
                            <p><img src="images/howto_java_95_02.jpg" alt="Warning message."/></p>
                        </li>
                        <li>
                            <p>Click "Accept Terms in License Agreement" then click on the Next button.</p>
                            <p><img src="images/howto_java_95_03.jpg" alt="Licence Agreement."/></p>
                        </li>
                        <li>
                            <p>Select the components to install. If you are low on free space you can leave out the Demos and Source Code.</p>
                            <p><img src="images/howto_java_95_04.jpg" alt="Components to Install"/></p>
                        </li>
                        <li>
                            <p>The wizard will now install the JDK files on your system. This may take a while.</p>
                            <p><img src="images/howto_java_95_05.jpg" alt="Installing the files"/></p>
                        </li>
                        <li>
                            <p>Click the Next button to install the J2SE Runtime Environment</p>
                            <p><img src="images/howto_java_95_06.jpg" alt="Install the Java Runtime Environment"/></p>
                        </li>
                        <li>
                            <p>In the next dialog select the browsers to integrate the JRE with, I recommend all. Click the Next button.</p>
                        </li>
                        <li>
                            <p>The installation should be complete! Click the Finish button.</p>
                            <p><img src="images/howto_java_95_07.jpg" alt="Installation complete"/></p>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Setting the Path Variable</title>
                    <p>We need to set the path variable so that the system can find the Java compiler.</p>
                    <ol>
                        <li>
                            <p>Open the Windows Explorer and navigate to the <code>C:\</code> drive. Right-click on the file named <code>Autoexec.bat</code> and select edit from the menu.</p>
                            <img src="images/howto_java_95_08.jpg" alt="Edit the autoexec.bat file"/>
                            <warning><code>Autoexect.bat</code> may not be visible if it is set as a hidden file. You should set folder options to display hidden files by selecting Options from the Folder menu.</warning>
                        </li>
                        <li>
                            <p>The file may be empty, but it will most likely contain some entries. You should add the following entries at the bottom of the file, after the last entries:</p>
                            <source xml:space="preserve">set JAVA_HOME=C:\Program Files\Java\jdk1.5.0
set PATH="%PATH%;%JAVA_HOME%\bin"</source>
                            <note>If you changed the installation location of java to some other location, you will have to change the location here to.</note>
                        </li>
                        <li>
                            <p>Save the file, close the text editor and restart your computer.</p>
                        </li>
                    </ol>
                </section>
            </section>
            <section>
                <title>Microsoft Windows 98</title>
                <section>
                    <title>Installing the JDK</title>
                    <ol>
                        <li>
                            <p>Run the setup program <code>jdk-1_5_0-windows-i586.exe</code></p>
                            <p><img src="images/howto_java_98_01.jpg" alt="Running the setup program."/></p>
                        </li>
                        <li>
                            <p>If you use Windows 98 First Edition and get the warning message, click "Continue" on the warning message.</p>
                            <p><img src="images/howto_java_98_02.jpg" alt="Warning message."/></p>
                        </li>
                        <li>
                            <p>Click "Accept Terms in License Agreement" then click on the Next button.</p>
                            <p><img src="images/howto_java_98_03.jpg" alt="Licence Agreement."/></p>
                        </li>
                        <li>
                            <p>Select the components to install. If you are low on free space you can leave out the Demos and Source Code.</p>
                            <p><img src="images/howto_java_98_04.jpg" alt="Components to Install"/></p>
                        </li>
                        <li>
                            <p>The wizard will now install the JDK files on your system. This may take a while.</p>
                            <p><img src="images/howto_java_98_05.jpg" alt="Installing the files"/></p>
                        </li>
                        <li>
                            <p>Click the Next button to install the J2SE Runtime Environment</p>
                            <p><img src="images/howto_java_98_06.jpg" alt="Install the Java Runtime Environment"/></p>
                        </li>
                        <li>
                            <p>In the next dialog select the browsers to integrate the JRE with, I recommend all. Click the Next button.</p>
                        </li>
                        <li>
                            <p>The installation should be complete! Click the Finish button.</p>
                            <p><img src="images/howto_java_98_07.jpg" alt="Installation complete"/></p>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Setting the Path Variable</title>
                    <p>We need to set the path variable so that the system can find the Java compiler.</p>
                    <ol>
                        <li>
                            <p>Open the Windows Explorer and navigate to the <code>C:\</code> drive. Right-click on the file named <code>Autoexec.bat</code> and select edit from the menu.</p>
                            <img src="images/howto_java_98_08.jpg" alt="Edit the autoexec.bat file"/>
                            <warning><code>Autoexect.bat</code> may not be visible if it is set as a hidden file. You should set folder options to display hidden files by selecting Options from the Folder menu.</warning>
                        </li>
                        <li>
                            <p>The file may be empty, but it will most likely contain some entries. You should add the following entries at the bottom of the file, after the last entries:</p>
                            <source xml:space="preserve">set JAVA_HOME=C:\Program Files\Java\jdk1.5.0
set PATH="%PATH%;%JAVA_HOME%\bin"</source>
                            <note>If you changed the installation location of java to some other location, you will have to change the location here to.</note>
                        </li>
                        <li>
                            <p>Save the file, close the text editor and restart your computer.</p>
                        </li>
                    </ol>
                </section>        
            </section>
            <section>
                <title>Microsoft Windows 2000</title>
                <section>
                    <title>Installing the JDK</title>
                    <note>You should be logged in as Administrator or have Administrative privileges to perform this installation. If not, you should get your System Administrator to do the install for you.</note>
                    <ol>
                        <li>
                            <p>Run the <code>jdk-1_5_0-windows-i586.exe</code> setup program.</p>
                        </li>
                        <li>
                            <p>Select Accept with the Terms in the License Agreement and click the Next button.</p>
                            <p><img src="images/howto_java_2000_01.jpg" alt="Accept the terms in the licence"/></p>
                        </li>
                        <li>
                            <p>Select the components you wish to install. If you are low on disk space you can leave out the Demos and Source Code. Click the Next button to continue.</p>
                            <p><img src="images/howto_java_2000_02.jpg" alt="Select components to install"/></p>
                        </li>
                        <li>
                            <p>The installer will now copy files to your computer, this may take a while.</p>
                            <p><img src="images/howto_java_2000_03.jpg" alt="Copying files to your computer"/></p>
                        </li>
                        <li>
                            <p>Install the Public Java Runtime Environment by clicking the Next button. You should not have to edit any settings here.</p>
                            <p><img src="images/howto_java_2000_04.jpg" alt="Install the runtime environment"/></p>
                        </li>
                        <li>
                            <p>Select which browsers to integrate the runtime environment with. I recommend all.</p>
                            <p><img src="images/howto_java_2000_05.jpg" alt="Select browsers to integrate the runtime with"/></p>
                        </li>
                        <li>
                            <p>That should take care of the installation. The JDK is now successfully installed on your system.</p>
                            <p><img src="images/howto_java_2000_06.jpg" alt="Installation completed."/></p>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Setting the Path Variable</title>
                    <p>We need to set the path variable so that the system can find the Java compiler.</p>
                    <note>We will create the variables in the global system space so that any user on the system can use the java tools. If you don't want this, you can create the variables in the Administrator's user space, but then only the administrator will be able to use the java tools. This might be what you want if there is only one user on the computer.</note>
                    <ol>
                        <li>
                            <p>Right click on the My Computer icon on the desktop and select Properties from the pop up menu. Click the Environment Variables button.</p>
                            <p><img src="images/howto_java_2000_07.jpg" alt="My Computer Properties"/></p>
                        </li>
                        <li>
                            <p>Under the System Variables section click the New button to add a new variable.</p>
                            <p><img src="images/howto_java_2000_08.jpg" alt="Environment Variables"/></p>
                        </li>
                        <li>
                            <p>Add a variable named <code>JAVA_HOME</code> with the value <code>C:\Program Files\Java\jdk1.5.0</code> and click the Ok button.</p>
                            <p><img src="images/howto_java_2000_09.jpg" alt="The Java Home Variable"/></p>
                            <note>If you installed Java to a different location, you should change the value here to reflect this.</note>
                        </li>
                        <li>
                            <p>Lastly edit the variable named <code>PATH</code>, add a semi colon (<code>;</code>) after the last entry in the value field and then add <code>C:\Program Files\Java\jdk1.5.0\bin</code></p>
                            <p><img src="images/howto_java_2000_10.jpg" alt="The PATH variable"/></p>
                        </li>
                    </ol>
                </section>
            </section>
            <section>
                <title>Microsoft Windows XP</title>
                <section>
                    <title>Installing the JDK</title>
                    <note>You should be logged in as Administrator or have Administrative privileges to perform this installation. If not, you should get your System Administrator to do the install for you.</note>
                    <ol>
                        <li>
                            <p>Run the <code>jdk-1_5_0-windows-i586.exe</code> setup program.</p>
                            <p><img src="images/howto_java_xp_01.jpg" alt="Run the setup program"/></p>
                        </li>
                        <li>
                            <p>Select Accept with the Terms in the License Agreement and click the Next button.</p>
                            <p><img src="images/howto_java_xp_02.jpg" alt="Accept the terms in the licence"/></p>
                        </li>
                        <li>
                            <p>Select the components you wish to install. If you are low on disk space you can leave out the Demos and Source Code. Click the Next button to continue.</p>
                            <p><img src="images/howto_java_xp_03.jpg" alt="Select components to install"/></p>
                        </li>
                        <li>
                            <p>The installer will now copy files to your computer, this may take a while.</p>
                            <p><img src="images/howto_java_xp_04.jpg" alt="Copying files to your computer"/></p>
                        </li>
                        <li>
                            <p>Install the Public Java Runtime Environment by clicking the Next button. You should not have to edit any settings here.</p>
                            <p><img src="images/howto_java_xp_05.jpg" alt="Install the runtime environment"/></p>
                        </li>
                        <li>
                            <p>Select which browsers to integrate the runtime environment with. I recommend all.</p>
                            <p><img src="images/howto_java_xp_06.jpg" alt="Select browsers to integrate the runtime with"/></p>
                        </li>
                        <li>
                            <p>That should take care of the installation. The JDK is now successfully installed on your system.</p>
                            <p><img src="images/howto_java_xp_07.jpg" alt="Installation completed."/></p>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Setting the Path Variable</title>
                    <p>We need to set the path variable so that the system can find the Java compiler.</p>
                    <note>We will create the variables in the global system space so that any user on the system can use the java tools. If you don't want this, you can create the variables in the Administrator's user space, but then only the administrator will be able to use the java tools. This might be what you want if there is only one user on the computer.</note>
                    <ol>
                        <li>
                            <p>Right click on the My Computer icon on the desktop and select Properties from the pop up menu. Click the Environment Variables button.</p>
                            <p><img src="images/howto_java_xp_08.jpg" alt="My Computer Properties"/></p>
                        </li>
                        <li>
                            <p>Under the System Variables section click the New button to add a new variable.</p>
                            <p><img src="images/howto_java_xp_09.jpg" alt="Environment Variables"/></p>
                        </li>
                        <li>
                            <p>Add a variable named <code>JAVA_HOME</code> with the value <code>C:\Program Files\Java\jdk1.5.0</code> and click the Ok button.</p>
                            <p><img src="images/howto_java_xp_10.jpg" alt="The Java Home Variable"/></p>
                            <note>If you installed Java to a different location, you should change the value here to reflect this.</note>
                        </li>
                        <li>
                            <p>Lastly edit the variable named <code>PATH</code>, add a semi colon (<code>;</code>) after the last entry in the value field and then add <code>C:\Program Files\Java\jdk1.5.0\bin</code></p>
                            <p><img src="images/howto_java_xp_11.jpg" alt="The PATH variable"/></p>
                        </li>
                    </ol>
                </section>
            </section>
            <section>
                <title>Linux (Red Hat, Fedora Core &amp; Mandrake)</title>                
                <section>
                    <title>Installing the JDK</title>
                    <note>This how-to assumes you have root privileges and that you are to install Java system wide so that all users can use the Java tools.</note>
                    <ol>
                        <li>
                            <p>Start a shell. Copy the Linux installer to the <code>/usr/local</code> directory.</p>
                            <source xml:space="preserve">cp jdk-1_5_0-linux-i586.bin /usr/local</source>
                        </li>
                        <li>
                            <p>Now change into the <code>/usr/local</code> directory and run the installer.</p>
                            <source xml:space="preserve">cd /usr/local
chmod +x jdk-1_5_0-linux-i586.bin
./jdk-1_5_0-linux-i586.bin</source>
                        </li>
                        <li>
                            <p>Read through the license agreement and if you agree type <code>yes</code>. This will start the installer.</p>
                        </li>
                        <li>
                            <p>If everything goes well you should end up with output that ends with:</p>
                            <source xml:space="preserve">Done.</source>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Setting the Path Variable</title>
                    <ol>
                        <li>
                            <p>Create the file named <code>java.sh</code> in the directory named <code>/etc/profile.d</code> using your favourite text editor. I used Vi.</p>
                            <source xml:space="preserve">cd /
touch /etc/profile.d/java.sh
vi /etc/profile.d/java.sh</source>
                        </li>
                        <li>
                            <p>Add the following to the file.</p>
                            <source xml:space="preserve">export JAVA_HOME=/usr/local/jdk1.5.0
export PATH=${PATH}:${JAVA_HOME}/bin</source>
                        </li>
                        <li>
                            <p>Make the script executable.</p>
                            <source xml:space="preserve">chmod +x /etc/profile.d/java.sh</source>
                        </li>
                        <li>
                            <p>Log out and then log in again for the changes to take effect.</p>
                        </li>
                    </ol>
                </section>
            </section>
            <section>
            &#9;<title>Sun Solaris</title>
            &#9;<p>The JDK should be installed and setup by default. For information on upgrading go to <link href="http://www.sun.com">Sun's Website</link> and browse through the Solaris documentation.</p>
            </section>
            <section>
            &#9;<title>MacOS</title>
            &#9;<p>Most newer versions of MacOS have the JDK installed and setup by default. For information on upgrading check out the MacOS documentation.</p>
            </section>
        </section>
        <section>
            <title>Compiling and Running Java Programs</title>
            <section>
                <title>Compiling Java Programs</title>
                <p>We will now test our installation by compiling and running a simple Java Program.</p>
                <section>
                    <title>Microsoft Windows</title>
                    <ol>
                        <li>
                            <p>Open the Notepad text editor <code>Start &gt; All Programs &gt; Accessories &gt; Notepad</code> and type the following program into it:</p>
                            <source xml:space="preserve">class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}</source>
                        </li>
                        <li>
                            <p>Save the program to the <code>C:\</code> drive in a file named <code>HelloWorld.java</code>. Make sure to select "All Files" in the Type field of the Save As dialog box.</p>
                        </li>
                        <li>
                            <p>To compile the program, open the Dos Prompt <code>Start &gt; All Programs &gt; Accessories &gt; Command Prompt</code> and type:</p>
                            <source xml:space="preserve">cd\
javac HelloWorld.java</source>
                            <p>If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program on the <code>C:\</code> drive and that it is named <code>HelloWorld.java</code>.</p>
                        </li>
                    </ol>
                </section>
                <section>
                    <title>Linux</title>                    
                    <ol>
                        <li>
                        <p>Start your favourite text editor and type the following program in it, then save it in a file named <code>HelloWorld.java</code> in your home directory.</p>
                        <source xml:space="preserve">class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}</source>
                        </li>
                        <li>
                            <p>To compile the program, start a shell and use the Java Compiler:</p>
                            <source xml:space="preserve">cd ~
javac HelloWorld.java</source>
                            <p>If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program in your home directory and that it is named <code>HelloWorld.java</code>.</p>
                        </li>
                    </ol>
                </section>
                <section>
                &#9;<title>Solaris</title>
                &#9;<ol>
                &#9;    <li>
                &#9;    &#9;<p>Start a text editor, either <code>vi</code> in the command line or Gedit. Type the following program in it then save it in a file name H<code>elloWorld.java</code> in your home directory.</p>
   &#9;                        <source xml:space="preserve">class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}</source>
                &#9;    </li>
                &#9;    <li>
                &#9;    &#9;<p>To compile the program, start a shell and use the Java Compiler:</p>
                            <source xml:space="preserve">cd ~
javac HelloWorld.java</source>
                            <p>If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program in your home directory and that it is named <code>HelloWorld.java</code>.</p>                &#9;    &#9;
                &#9;    </li>
                &#9;</ol>
                </section>
            </section>
            <section>
                <title>Running Java Programs</title>
                    <ol>
                        <li>
                            <p>To run the program, type:</p>
                            <source xml:space="preserve">java HelloWorld</source>
                            <p>you should get the following output:</p>
                            <source xml:space="preserve">Hello World!</source>
                        </li>
                    </ol>
            </section>
            <section>
                <title>Common Errors and Solutions</title>
                <ol>
                    <li>
                        <code>Exception in thread "main" java.lang.NoSuchMethodError: main</code>
                        <p>You must define a main method as: <code>public static void main(String[] args) {...} </code></p>
                    </li>
                    <li>
                        <code>HelloWorld.java:3: illegal character: \8220 System.out.println(öHelloWorld!ö); </code>
                        <p>Do not type your code in a word processor application that uses smart quotes!! </p>
                    </li>
                    <li>
                        <code>HelloWorld.class Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class</code>
                        <p>The correct way to call a program is <code>java HelloWorld</code> without the ".java" or ".class" </p>
                    </li>
                </ol>
            </section>
        </section>
        <section>
            <title>Valuable Resources</title>
            <section>
                <title>The Java Application Programmer Interface</title>
                <p>The Java API is an Application Programmer Interface that describes in great detail the core Java Foundation Classes that make up the Java Platform. It highlights which packages make up the Platform, which classes belong to which packages and what methods and fields are available in each class. It is an invaluable tool to any Java Programmer. </p>
                <p><img src="images/chapter01_01.jpg" alt="The Java API"/></p>
            </section>
            <section>
                <title>Sun's Java Page</title>
                <p>Sun Microsystems's Java page can be accessed via the Internet at <link href="http://java.sun.com">http://java.sun.com</link> and it provides a download page where you can download all of the Java Technology that you want. It includes documentation: API's, Tutorials, Short Courses and White Papers. It often has industry news and updates and is also an invaluable resource to any Java programmer. </p>
                <p><img src="images/chapter01_02.jpg" alt="Sun't Java Page"/></p>
            </section>
        </section>
        <section>
            <title>Summary</title>
            <p>In order to compile and run Java programs you need to install the J2SE SDK and set the PATH environment variable. Setting an environment variable is dependent on the underlying platform.</p>
            <p>Compiling java programs is done using the "javac" command and running them with the "java" command.</p>
            <p>The Java API and Sun's Java page are exceptional resources for any Java programmer.</p>
        </section>      
        <section>
            <title>Exercise Set</title>
            <section>
                <title>Multiple Choice</title>&#9;
&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>The JDK is available for which platforms?</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Windows</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Linux</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>MacOS</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Sun Solaris</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>All of the above</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>The JDK contains:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Tools to develop software for the Java Platform</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>A Java Runtime Environment</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>The core Java API</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>The Java Source Code</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>All of the above</li>&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Installing the JDK requires:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Extracting the JDK archive.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Depends on the platform.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Running the installation binary.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Setting the path and classpath variables.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>1 and 4.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>The Java API:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Explains which packages form the core of Java Programming Language</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Which classes are located in which package.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Which methods a class contains.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>The fields that the class contains.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>All of the above.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Sun's java page:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Contains the Java Tutorial.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Contains all the Java Software.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Is not worth visiting.</li>&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>1 and 2.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>2 and 3.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;</ol>&#9;&#9;
            </section>
            <section>
                <title>Exercises</title>
                <ol>
                    <li>Install the JDK on your own computer.</li>
                    <li>Compile and Run the Hello World program.</li>
                    <li>Browse through the Java API.</li>
                    <li>Browse the Java page at Sun Microsystems's site: <link href="http://java.sun.com">java.sun.com</link></li>
                    <li>Download or browse the Java Tutorial at: <link href="http://java.sun.com/docs/books/tutorial/index.html">http://java.sun.com/docs/books/tutorial/index.html</link> </li>
                </ol>&#9;&#9;&#9;&#9;&#9;
            </section>
            <section>
                <title>Programming Exercises</title>
                <ol>
                    <li>Go read through the Java Tutorial at Sun's Java page and then try the following programs:
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Change the Hello World program so that it prints out your name.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Write a program to display the first twenty powers of two.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Write a program that generates a temperature conversion chart between Fahrenheit and Celsius.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Write a program to display the first twenty Fibonacci numbers.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Write a program that reads a number and displays it's square root.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
                </ol>
            </section>
        </section>
    </section>
    <section class="page" id="chapter2.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>The Eclipse IDE</title>
        <section>
            <title>Jargon</title>
            <dl>
                <dt><strong>Command</strong></dt>
                <dd>An instruction given to the computer, by means of a keyboard, punch card, mouse, voice command, or other method.</dd>
                <dt><strong>Console</strong></dt>
                <dd>The command prompt window that rece    ves output from a <code>System.out.print</code> call.</dd>
                <dt><strong>Drive</strong></dt>
                <dd>A device that spins disks or tapes in order to read and write data; for example, a hard drive, floppy drive, CD-ROM drive, or tape drive.</dd>
                <dt><strong>Error</strong></dt>
                <dd>A mistake made by a software developer that introduces a defect in a computer program.</dd>
                <dt><strong>Generate</strong></dt>
                <dd>The automated creation of source code.</dd>
                <dt><strong>IDE</strong></dt>
                <dd><em>Integrated Development Environment</em>, an IDE combines the editor, compiler and other useful tools in the same software package. Its advantage is that when a program with syntax errors is compiled, the programmer sees the error messages and the original program at the same time -- this makes debugging much easier.</dd>
                <dt><strong>Refactor</strong></dt>
                <dd>Refactoring is the process of rewriting written material to improve its readability or structure, with the explicit purpose of keeping its meaning or behavior.</dd>
                <dt><strong>Syntax</strong></dt>
                <dd>The rules by which the words in a program are combined to form commands to a computer.</dd>
                <dt><strong>Syntax Highlight</strong></dt>
                <dd>Syntax highlighting is a feature of some text editors that displays text, especially source code, in different colors and fonts according to the category of terms. This feature eases writing in a structured language such as a programming language or a markup language as both structures and syntax errors are visually distinct.</dd>
                <dt><strong>Zip</strong></dt>
                <dd>To zip a file is to compress it into an archive so that it occupies less disk space.</dd>
            </dl>
        </section>
        <section>
            <title>Introduction</title>
            <p>Often newcomer's to programming will find editing source files in a text editor to be tedious. Seasoned developers hardly ever use a text editor either. An Integrated Development Environment (IDE) provides the functionality to edit source code, compile it and run the source code all from within a single application.</p>
&#9;&#9;&#9;<p>Eclipse is an excellent open source IDE for Java. It is developed by IBM and written in Java itself. Eclipse provides a wide range of capabilities and features; we will look at this useful IDE in this chapter.</p>
&#9;&#9;&#9;<p>You can get Eclipse @ <link href="http://www.eclipse.org">www.eclipse.org</link></p>
        </section>
&#9;&#9;<section>
            <title>Installing The Eclipse SDK</title>
            <p>The first thing we need to do is to install Eclipse.</p>
   &#9;        <note>Eclipse is a memory intensive application may take a while to load, depending on how much memory your system has.</note>&#9;&#9;&#9;
&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;<title>Installing on Windows</title>
&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Extract the eclipse archive to the <code>C:\</code> drive using a program like Winzip or ZipGenius. You should end up with a folder in the C: drive named <code>eclipse</code>.</p>
&#9;&#9;&#9;&#9;&#9;&#9;<img src="images/chapter02_01.jpg" alt="Extract the archive"/>
&#9;&#9;&#9;&#9;&#9;</li>&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>The eclipse program is in the <code>eclipse</code> folder and is a file named <code>eclipse.exe</code>. You can double click this file to run the program. You might want to create a shortcut to this file on your desktop or in your start menu.</p>
&#9;&#9;&#9;&#9;&#9;&#9;<img src="images/chapter02_02.jpg" alt="Extract the archive"/>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;</section>&#9;&#9;&#9;
&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;<title>Installing on Linux</title>
&#9;&#9;&#9;&#9;<note>You should be logged in as root to perform this installation.</note>
&#9;            <ol>
    &#9;            <li>
        &#9;            <p>Copy the Eclipse SDK archive to the <code>/usr/local</code> directory.</p>
            &#9;        <source xml:space="preserve">cp eclipse-SDK-3.0-linux-gtk.zip /usr/local/</source>
&#9;                </li>
    &#9;            <li>
        &#9;            <p>Change into the <code>/usr/local</code> directory and extract the archive.</p>
            &#9;        <source xml:space="preserve">cd /usr/local/
unzip eclipse-SDK-3.0-linux-gtk.zip</source>
&#9;                </li>
    &#9;            <li>
        &#9;            <p>Edit the file named <code>java.sh</code> in the <code>/etc/profile.d</code> directory and add the following to it.</p>
            &#9;        <note>If you installed java according to chapter 1 you should have a file named <code>java.sh</code> in the <code>/etc/profile.d</code> directory. If not, now would be an opportune time to create it.</note>
                &#9;    <source xml:space="preserve">export ECLIPSE_HOME=/usr/local/eclipse</source>
&#9;                </li>
    &#9;&#9;        <li>
            &#9;        <p>Now add <code>ECLIPSE_HOME</code> to the <code>PATH</code> variable, save the file and exit your editor.</p>
                &#9;    <source xml:space="preserve">PATH=${PATH}:${ECLIPSE_HOME}</source>
                    &#9;<p>Log out and then log in again for the changes to take effect.</p>
&#9;                </li>
    &#9;            <li>
        &#9;            <p>Run Eclipse: in a terminal type</p>
            &#9;        <source xml:space="preserve">eclipse</source>
&#9;                </li>
    &#9;            <li>
        &#9;            <p>In the dialog that asks you to select a workspace click the OK button. After eclipse has started, you will get a welcome screen.</p>
    &#9;            </li>
        &#9;    </ol>
&#9;&#9;&#9;</section>
        </section>
        <section>
            <title>Creating a Hello World Application</title>
            <p>The best way to learn about Eclipse and its features is to start using it; we will therefore create a simple Hello World application using it.</p>
            <section>
                <title>Create a New Java Project</title>
                <ol>
                    <li>
                        <p>Start eclipse with the command:</p>
                        <source xml:space="preserve">eclipse</source>
                    </li>
                    <li>
                        <p>Select a workspace from the dialog and ensure to check the box that makes it the default workspace.</p>
                    </li>
                    <li>
                        <p>In the welcome screen, click on the "Workbench" icon.</p>
                        <img src="images/howto_eclipse_lin_01.jpg" alt="01"/>
                    </li>
                    <li>
                        <p>From the File menu, select New and then Project.</p>
                        <source xml:space="preserve">File &gt; New &gt; Project</source>
                    </li>
                    <li>
                        <p>In the New Project Dialog, click Java Project and then click the Next button.</p>
                        <img src="images/howto_eclipse_lin_02.jpg" alt="02"/>
                    </li>
                    <li>
                        <p>In the New Java Project Dialog enter <code>Hello World</code> as the Project name and click the Finish button.</p>
                        <img src="images/howto_eclipse_lin_03.jpg" alt="03"/>
                    </li>
                    <li>
                        <p>A dialog will pop up asking you to confirm the switch to the Java Perspective. Check the checkbox that reads <code>Remember my decision</code> and then click the Yes button.</p>
                        <img src="images/howto_eclipse_lin_04.jpg" alt="04"/>
                    </li>
                    <li>
                        <p>In the Java Perspective, in the left side of the screen is the Package Explorer. In it you will see the Project named <code>Hello World</code>. Make Sure it is selected.</p>
                        <img src="images/howto_eclipse_lin_05.jpg" alt="05"/>
                    </li>
                </ol>
            <section>
                <title>Create a New Class</title>
            </section>
                <ol>
                    <li>
                        <p>Select File from the menu and click New. Select Class.</p>
                        <source xml:space="preserve">File &gt; New &gt; Class</source>
                    </li>
                    <li>
                        <p>In the New Java Class dialog enter <code>HelloWorld</code> as the name of the class, ensure that the <code>public static void main(String[] args)</code> checkbox is selected and then click the Finish button.</p>
                        <img src="images/howto_eclipse_lin_06.jpg" alt="06"/>
                    </li>
                    <li>
                        <p>You'll notice in the source code editor that the class has already been created for you.</p>
                        <img src="images/howto_eclipse_lin_07.jpg" alt="07"/>
                    </li>
                </ol>
            <section>
                <title>Add Source Code</title>
            </section>
                <ol>
                    <li>
                        <p>In the main method, type</p>
                        <source xml:space="preserve">System.</source>
                        <p>You'll notice a popup, prompting you to select a member of the <code>System</code> class. Select the <code>out</code> member.</p>
                    </li>
                    <li>
                        <p>Append the following to the line:</p>
                        <source xml:space="preserve">.println("Hello World!")</source>
                    </li>
                    <li>
                        <p>You'll notice a red squiggly line under the closing bracket. This indicates that there is an error in your code. Add a semi colon (<code>;</code>) and it will disappear.</p>
                        <img src="images/howto_eclipse_lin_08.jpg" alt="08"/>
                    </li>
                </ol>
            <section>
                <title>Save the Code</title>
            </section>
                <ol>                    
                    <li>
                        <p>Select Save from the File menu to save the changes to the source code. You'll notice that Eclipse compiles source code automatically, every time that you save it.</p>
                        <source xml:space="preserve">File &gt; Save</source>
                    </li>
                </ol>
            <section>
                <title>Run the Program</title>
            </section>
                <ol>
                    <li>
                        <p>Right Click on the <code>HelloWorld.java</code> file in the Package Explorer and select Run followed by Java Application from the pop up menu.</p>
                        <source xml:space="preserve">Run &gt; Java Application</source>
                    </li>
                    <li>
                        <p>You'll notice the output in the console.</p>
                        <img src="images/howto_eclipse_lin_09.jpg" alt="09"/>
                    </li>
                </ol>
            </section>
        </section>
        <section>
            <title>Some Advanced Features</title>
            <section>
                <title>Configuring Some Preferences</title>
                <p>We will now change a few of the default preferences.</p>
                <ol>
                    <li>
                        <p>Select Preferences from the Window menu.</p>
                        <source xml:space="preserve">Window &gt; Preferences</source>
                    </li>
                    <li>
                        <p>Click the arrow next to <code>Workbench</code> to expand the sub categories and select <code>Colors and Fonts</code>. In the right pane expand <code>Java</code> and then <code>Java Editor Text Font.</code> Click the Change button, and change the font according to your preferences.</p>
                        <img src="images/howto_eclipse_lin_10.jpg" alt="10"/>
                    </li>
                    <li>
                        <p>In the left pane, expand the <code>Java</code> category and then the <code>Code Style</code> sub category. Select <code>Code Templates</code>. In the right pane select <code>Comments</code> and then <code>Types</code>. Click the Edit button and change the comment to your preferences.</p>
                        <img src="images/howto_eclipse_lin_11.jpg" alt="11"/>
                    </li>
                    <li>
                        <p>Now select <code>Code</code> and then the <code>New Java files</code> sub category. Click the Edit button and change the comment according to your preferences.</p>
                        <img src="images/howto_eclipse_lin_12.jpg" alt="12"/>
                    </li>
                    <li>
                        <p>In the left pane select <code>Editor</code> and select the <code>Show line numbers</code> check box.</p>
                        <img src="images/howto_eclipse_lin_13.jpg" alt="13"/>
                    </li>
                    <li>
                        <p>Select the <code>Syntax</code> tab in the right pane and change the color of the keywords from mauve to blue. Click the Apply button.</p>
                        <img src="images/howto_eclipse_lin_14.jpg" alt="14"/>
                    </li>
                    <li>
                        <p>Click the Ok button. You'll notice that the changes have taken effect in the source code editor.</p>
                        <img src="images/howto_eclipse_lin_15.jpg" alt="15"/>
                    </li>
                </ol>
            </section>
            <section>
                <title>Create a New Project</title>
                <p>We will now create a project outside of eclipse and then import it into eclipse.</p>
                <ol>
                    <li>
                        <p>In your home directory, create some directories:</p>
                        <source xml:space="preserve">mkdir ~/test
mkdir ~/test/src
mkdir ~/test/classes</source>
                    </li>
                    <li>
                        <p>In Eclipse, create a new project by selecting New from the File menu and then select Project.</p>
                        <source xml:space="preserve">File &gt; New &gt; Project</source>
                    </li>
                    <li>
                        <p>In the dialog, ensure that <code>Java Project</code> is selected and click the Next button.</p>
                    </li>
                    <li>
                        <p>In the next dialog, use <code>Test</code> as the project name. Then click the radio button that reads <code>Create project at external location</code>. Click the browse button and select the <code>test</code> directory in your home directory. Be sure to click the Next button.</p>
                        <img src="images/howto_eclipse_lin_16.jpg" alt="16"/>
                    </li>
                    <li>
                        <p>In the source folders list, select <code>Test</code> and click the remove button. Click the Add Folder button and select the <code>src</code> directory. Click the OK button.</p>
                        <img src="images/howto_eclipse_lin_17.jpg" alt="17"/>
                    </li>
                    <li>
                        <p>Click the browse button to change the Default output folder and select the <code>classes</code> directory. Click the Ok button.</p>
                        <img src="images/howto_eclipse_lin_18.jpg" alt="18"/>
                    </li>
                    <li>
                        <p>The resulting changes should be as follows:</p>
                        <img src="images/howto_eclipse_lin_19.jpg" alt="19"/>
                    </li>
                    <li>
                        <p>Click the Finish button.</p>
                    </li>
                </ol>
            </section>
            <section>
                <title>Create Some Packages</title>
                <p>You'll notice the <code>Test</code> project in the Package Explorer. We will define a package for our project.</p>
                <ol>
                    <li>
                        <p>In the package explorer expand the <code>Test</code> project.</p>
                    </li>
                    <li>
                        <p>Right click on the <code>src</code> folder in the package explorer and select New and then Package. Add <code>test</code> as the package name and click the Finish button.</p>
                        <img src="images/howto_eclipse_lin_20.jpg" alt="20"/>
                    </li>
                    <li>
                        <p>You will now see the empty package in the Package Explorer.</p>
                    </li>
                </ol>
            </section>
            <section>
                <title>Create a New Class</title>
                <p>We will create a simple class in the package we have just created..</p>
                <ol>
                    <li>
                        <p>Right click on the <code>Test</code> package. Create a new class named <code>Cat</code> by selecting New and then Class from the pop up menu.</p>
                        <img src="images/howto_eclipse_lin_21.jpg" alt="21"/>
                    </li>
                    <li>
                        <p>Add two variables, one named <code>age</code> of type <code>int</code> and one named <code>name</code> of type <code>String</code>.</p>
                        <img src="images/howto_eclipse_lin_22.jpg" alt="22"/>
                    </li>
                    <li>
                        <p>Add a simple constructor to initialize the variables.</p>
                        <img src="images/howto_eclipse_lin_23.jpg" alt="23"/>
                    </li>
                </ol>
            </section>
            <section>
                <title>Generate Getters and Setters</title>
                <p>Now we will use eclipse to generate getter and setter methods for our class.</p>
                <ol>
                    <li>
                        <p>Select <code>Generate Getters and Setters</code> from the <code>Source</code> menu.</p>
                        <source xml:space="preserve">Source &gt; Generate Getters and Setters</source>
                    </li>
                    <li>
                        <p>In the dialog click the Select All button followed by the Ok button.</p>
                        <img src="images/howto_eclipse_lin_24.jpg" alt="24"/>
                    </li>
                    <li>
                        <p>You'll notice that the get and set methods were created.</p>
                        <img src="images/howto_eclipse_lin_25.jpg" alt="25"/>
                    </li>
                    <li>
                        <p>Don't forget to save the file.</p>
                    </li>
                </ol>
            </section>
            <section>
                <title>Refactoring</title>
                <p>We would like to change the name of the package from test and have all changes reflected. First we will create a main program that will use our class.</p>
                <ol>
                    <li>
                        <p>Create a new package named <code>com.acme.test.main</code></p>
                    </li>
                    <li>
                        <p>Create a program called <code>Main</code> in the new package.</p>
                        <img src="images/howto_eclipse_lin_26.jpg" alt="26"/>
                    </li>
                    <li>
                        <p>Add the following code to the main method.</p>
                        <source xml:space="preserve">Cat kitty = new Cat()</source>
                    </li>
                    <li>
                        <p>You will again notice some squiggly red lines. In the gutter next to the line numbers you will see a hint icon. Click on it.</p>
                        <img src="images/howto_eclipse_lin_27.jpg" alt="27"/>
                    </li>
                    <li>
                        <p>In the pop up hint you will be prompted to import the Cat class. Do so, by clicking on the suggestion. You will notice that an import statement has been added to your code, namely: <code>import test.Cat</code>. Save the class.</p>
                        <img src="images/howto_eclipse_lin_28.jpg" alt="28"/>
                    </li>
                    <li>
                        <p>Right click on the test package in the Package Explorer and select refactor from the menu. Select Rename from the sub menu.</p>
                        <source xml:space="preserve">Refactor &gt; Rename</source>
                    </li>
                    <li>
                        <p>Rename the package to <code>com.acme.test.pets</code> .</p>
                        <img src="images/howto_eclipse_lin_29.jpg" alt="29"/>
                    </li>
                    <li>
                        <p>If you look at the main class, you'll notice that the import statement has changed to match the new package name, ie: <code>import com.acme.test.pets.Cat</code>!</p>
                        <img src="images/howto_eclipse_lin_30.jpg" alt="30"/>
                    </li>
                </ol>
            </section>
        </section>   
        <section>
            <title>Installing a Plug-In</title>
            <p>Eclipse is designed in such a way that third party developers can create plug-ins for it. One such plug-in allows you to edit XML files: it provides syntax highlighting for XML and code completion.</p>
            <p>Installing a plug-in in Eclipse is a simple and painless process. All plug-ins are distributed in zip compressed archives, much like eclipse. All you have to do is extract the archive in the correct directory within Eclipse and it should work out of the box.</p>
            <p>For this installation, we're using the XML buddy plug-in form <link href="http://www.xmlbuddy.com">here</link>.</p>
            <ol>
                <li>
                    <p>If you open an XML file in Eclipse you will notice that Eclipse uses the default text editor for XML files. This allows you to edit the files but it doesn't provide features common to most IDE's. In this case, installing a plug-in will help.</p>
                    <img src="images/howto_eclipse_win_31.jpg" alt="31"/>
                </li>
                <li>Close Eclipse before proceeding.</li>
                <li>Extract the archive to location of your choice. This results in a folder named <code>com.objfac.xmleditor</code>_<em>version</em>.</li>
                <li>
                    <p>Move this folder into a folder named <code>plugins</code> within the <code>eclipse</code> folder.</p>
                    <img src="images/howto_eclipse_win_32.jpg" alt="32"/>
                </li>
                <li>
                    <p>Start Eclipse and open an XML document, you should see that it is now syntax highlighted.</p>
                    <img src="images/howto_eclipse_win_33.jpg" alt="33"/>
                </li>
            </ol>
            <note>Installing a plug-in that is not for your version of Eclipse will not work. You should make sure you get the plug-in that is specifically for your version of Eclipse.</note>
        </section>&#9;&#9;       
        <section>
            <title>Summary</title>
&#9;&#9;&#9;<p>Eclipse is an advanced and feature rich IDE for the Java language. It is simple to install and easy to learn to use. We will be using this valuable tool in the next few chapters in this book.</p>
        </section>
        <section>
            <title>Exercise Set</title>
            <section>
                <title>Multiple Choice</title>&#9;
&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Eclipse is written in which language?</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Pascal</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>C</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>C++</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Java</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Delphi</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Eclipse is:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Proprietary Software</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Commercial Software</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Open Source Software</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Shareware</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Freeware</li>&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Which is not a feature of Eclipse</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Eclipse allows easy refactoring of code.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Eclipse is available for many platforms.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Eclipse has Apache Ant integrated into it.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Eclipse requires you to compile source code after it is saved.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Eclipse has JUnit integrated into it.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Eclipse allows you to:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Generate new classes and interfaces quickly and easily.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Use third-party plug-ins.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Generate getters and setters.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Refactor code.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>All of the above.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Eclipse is available for:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Windows</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Linux</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Sun Solaris</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>1 and 2.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>2 and 3.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;</ol>&#9;&#9;
            </section>
            <section>
                <title>Exercises</title>
                <ol>
                    <li>Install the Eclipse on your own computer.</li>
                    <li>Create the Hello World program described in this chapter.</li>
                    <li>Import your existing projects into Eclipse.</li>
                    <li>Configure the Preferences of Eclipse according to your taste.</li>
                    <li>Install the plug-in as described in this chapter.</li>
                </ol>&#9;&#9;&#9;&#9;&#9;
            </section>
            <section>
                <title>Programming Exercises</title>
                <ol>
                    <li>Complete the following programs using Eclipse:
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>A program that calculates how much is left of a bank loan. Input parameters are initial loan amount, interest rate, payment per month and current month.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>A program to calculate the average of a list of numbers.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>A program that calculates a student's grade from grades, each counting an equal percentage.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
                </ol>
            </section>
        </section>&#9;&#9;        
    </section>
    <section class="page" id="chapter3.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Java Packages</title>
        <section>
            <title>Jargon</title>
            <dl>
                <dt><strong>Attribute</strong></dt>
                <dd>A single piece of information that represents a property present in all instances of a class. An attribute is often modeled as a variable in a class.</dd>
                <dt><strong>Byte</strong></dt>
                <dd>The amount of memory space used to store one ASCII character, which is usually 8 bits. A bit is the smallest unit of information a computer can hold; short for binary digit, the value can be either one or zero.</dd>
                <dt><strong>Component</strong></dt>
                <dd>A piece of software with a clear function that can be isolated and replaced by another component with equivalent functionality.</dd>
                <dt><strong>Function</strong></dt>
                <dd>A method that performs some form of processing in order to return a result. For example, a function to calculate the sum of two integers.</dd>
                <dt><strong>Input</strong></dt>
                <dd>Something put into a system or expended in its operation to achieve output or a result.</dd>
                <dt><strong>Library</strong></dt>
                <dd>A library is a collection of subprograms used to develop software. Libraries are distinguished from executables in that they are not independent programs.</dd>
                <dt><strong>Namespace</strong></dt>
                <dd>A scoping construct to subdivide the set of names and their visibility within a system. In many languages, this is tied to other computational constructs, eg, classes, procedures, modules, packages. A mechanism used to resolve naming conflicts.</dd>
                <dt><strong>Performance</strong></dt>
                <dd>A major factor in determining the overall productivity of a system, performance is primarily tied to availability, throughput and response time.</dd>
                <dt><strong>Statement</strong></dt>
                <dd>An entity in a programming language which is typically the smallest indivisible unit of execution.</dd>
                <dt><strong>Sub-class</strong></dt>
                <dd>A class that is an extension of another class and inherits public and protected variables and methods from the other class. Also known as a derived class.</dd>
            </dl>
        </section>
        <section>
            <title>Introduction</title>
            <p>In order to provide namespace management Java provides the mechanism of creating Java Packages. A Java Package can be thought of as a collection of Java source files, usually grouped by functionality. In order to utilize Java fully you should understand how packages work.</p>
        </section>
        <section>
            <title>Java Packages</title>
            <section>
                <title>What is a Package?</title>
                <p>One of the many concerns that programmers face today is trying to ensure that their source code does not conflict with the source code of other programmers. A typical example is the case when two programmers define two distinct classes that have the same name. Suppose you decide to write a <code>List</code> class that keeps a sorted list of objects. This would inherently conflict with the <code>List</code> class in the Java API that is used to display a list of items in a Graphical User Interface. Java has a simple solution to this problem that is known as namespace management. Each programmer defines their own namespace and place their code within that namespace, thus two classes that have the exact same name are now distinguishable since they occur in different name spaces. Namespaces are called packages in Java.</p>
                <p>Another important reason for using packages is that it provides programmers with greater control over their source code. It is typical to have a few thousand source files in medium to large scale applications, and trying to maintain them would be difficult at best, if not impossible. However, separating these source files into packages makes it much easier to manage the source code. What usually occurs is that related classes are grouped into a single package, for example, all the user interface classes of an application will be grouped into a package.</p>
                <p>Access protection is another benefit of using packages. Suppose a group of different applications utilize the same set of source code, it would make sense to separate this source code and maintain it as a separate library that each application uses. In such a library, there is a public interface and a private interface. The public interface is those classes and methods that are accessible to the application using the library, while the private interface is not accessible to the application. Using a package makes it easier to define which classes form part of the public interface and which are part of the private interface. This makes it easy to control access to certain code sections.</p>
                <p>Some of the benefits of using packages are:</p>
                <dl>
                    <dt>It shows that the classes and interfaces in the package are related.</dt>
                    <dd>Often a group of classes and interfaces are related according to functionality so naturally they should be grouped into a package. An excellent example is the <code>java.io</code> package which groups a set of classes that all perform input and output functions.</dd>
                    <dt>You know where to find the classes you want if they're in a specific package.</dt>
                    <dd>If you are looking for a specific class and you know what functionality it provides you will naturally be able to find it in the right package. If you are looking for an <code>InputStreamReader</code> you will find it in the input and output package, ie: <code>java.io</code></dd>
                    <dt>The names of your classes and interfaces won't be in conflict with those of other programmers.</dt>
                    <dd>If you decide to implement your own String class and you place it in a package it will be distinguishable from the <code>java.lang.String</code> class that comes with the Java API.</dd>
                    <dt>You can restrict the access to your classes.</dt>
                    <dd>When you only want your code or program to access certain code, for example in a library, then using packages makes access control to source code much easier.</dd>
                </dl>
            </section>
            <section>
                <title>Creating Packages</title>
                <p>Creating a Java Package is relatively simple but may seem a bit confusing for people who have not done it before. There are two fundamental requirements for a package to exist:</p>
                <ul>
                    <li>The package must contain one or more classes or interfaces. This implies that a package cannot be empty.</li>
                    <li>The classes or interfaces that are in the package must have their source files in the same directory structure as the name of the package.</li>
                </ul>
                <section>
                    <title>Naming Packages</title>
                    <p>Since packages are used to create namespaces that are used to prevent the problem of name conflicts, namespaces must be unique. This means that package names must be unique. Naming a package is therefore a very important aspect of creating a package.</p>
                    <p>Often organizations that are involved in software development will use their organi    ation's domain name, since domain names by definition are unique. The domain name is inverted to make it easier to read. Good examples can be found from looking at the source code of the Apache Software Foundation, whose domain name is <code>www.apache.org</code>. All their code is placed into packages that have names beginning with <code>org.apache</code>.</p>
                    <p>Since the Apache Software Foundation has a number of sub-projects, each with its own web address, the project name is also used in the package name. The Ant project can be found at <code>http://ant.apache.org</code>, and it should be no surprise that their code is in the packages with names beginning with <code>org.apache.ant</code>.</p>
                    <p>When naming your package you should take your inverted domain name, if you have one, and add the project name to it. This will ensure that you have a unique package name, since it is highly unlikely that your organization is working on two projects that have the exact same name. As an example: <code>com.mycompany.myproject</code></p>
                    <p>Some companies have decided to drop the top level domain (com, org, net, ...) from their package names for the sake of brevity, this is still perfectly acceptable: <code>mycompany.mypackage</code></p>
                </section>
                <section>
                    <title>Declaring Package Members</title>
                    <p>The first thing to do when creating a package is to decide which classes and interfaces should belong to that package. Once you have decided that, you need to specify this by adding a package declaration to the source file of each class and interface that is a part of the package.</p>
                    <p>The declaration is simple, you use the <code>package</code> keyword followed by the package name. This declaration comes right at the top of the source file, before any <code>import</code> statements.</p>
                    <source xml:space="preserve">/*
 * File comments...
 */
 
 package com.mycompany.myproject;
 
 import java.util.*;
 
 class MyClass {
 
 }</source>
                </section>
                <section>
                    <title>Source and Class File Organization</title>
                    <p>One of the requirements for a package is that the source file should be contained in a directory structure that resembles the name of the package. This is simply creating a set of directories with the names given in the package name.</p>
                    <p>Take the package name and split it up according to where the periods (<code>.</code>) occur, for example, <code>com.mycompany.myproject</code> can easily be split up into three components, namely: com, mycompany and myproject. These will be the three directories that you create. The first directory will be the <code>com</code> directory and within this directory you will create a sub directory namely the <code>mycompany</code> directory and within that directory a sub directory, namely the <code>myproject</code> directory.</p>
                    <p>Finally, all the source files that are part of the package will go into the <code>myproject</code> directory.</p>
                    <p>It is typical in many java project to have the source code go into a <code>src</code> directory and when it is compiled, the resulting byte code goes into a <code>classes</code> directory. The package directories will therefore go into the <code>src</code> directory. As an example, consider a class named <code>MyClass</code> in the package named <code>com.mycompany.myproject</code> and all source code in the <code>src</code> directory. The following picture depicts this situation clearly:</p>
                    <p><img src="images/chapter03_01.jpg" alt="Source Code Organization"/></p>
                </section>
                <section>
                    <title>Compiling The Package</title>
                    <p>At first it may seem like a nightmare trying to compile the package, especially having the resulting class files occur in the <code>classes</code> directory, but it can be achieved using a single command. You don't even need all the package directories under the <code>classes</code> directory since they will be created in the compilation.</p>
                    <p>To try this out, create a <code>test</code> directory and all the sub directories required:</p>
                    <source xml:space="preserve">mkdir test
mkdir test\src
mkdir test\classes
mkdir test\src\com
mkdir test\src\com\mycompany
mkdir test\src\com\mycompany\myproject</source>
                    <p>Now create the <code>MyClass</code> source file named <code>MyClass.java</code> in the <code>test\src\com\mycompany\myproject</code> directory.</p>
                    <source xml:space="preserve">
/* MyClass.java
 * Author: Trevor Miller
 */
package com.mycompany.myproject;
                                                                                
public class MyClass {
                                                                                
}</source>
                    <p>Change into the <code>test</code> directory and compile the package:</p>
                    <source xml:space="preserve">cd test
javac -d ./classes/ ./src/com/mycompany/myproject/*.java</source>
                    <p>If you take a look in the <code>classes</code> directory, you will find the exact same directory structure as in the <code>src</code> directory. You'll also find a <code>MyClass.class</code> file in the <code>test\classes\com\mycompany\mypackage</code> directory. This is good as it allows you to keep your source and class files separate and provides greater control over your files.</p>
                    <p><img src="images/chapter03_02.jpg" alt="Source and Class Organization"/></p>
                </section>
            </section>
            <section>
                <title>Using Packages</title>
                <p>Once you have created your package you may want to use it in your program or you may wish to use another programmer's package or the packages in the Java API. There are three ways of using the resources in a package; inline package member declarations, importing only the package member that you want and importing the entire package.</p>
                <section>
                    <title>Inline Member Declarations</title>
                    <p>In this approach you simply declare the package member you wish to use with its fully qualified package name. As an example, suppose you wish to use the <code>Vector</code> class in the <code>java.util</code> package. You can easily declare a vector using <code>java.util.Vector vector;</code></p>
                    <p>When you initialize the object by calling its constructor, you will again have to use the fully qualified package name.</p>
                    <source xml:space="preserve">class Test {
   java.util.Vector vector;
   
   Test() {
      vector = new java.util.Vector();
   }
}</source>
                </section>
                <section>
                    <title>Importing a Single Package Member</title>
                    <p>Using the inline declaration works well if you only use it a few times in your source code, but it can become a pain to type the fully qualified package name if you use it often. Instead you want to do this once and only once, and from then on, simply use the member's name wherever you need it.</p>
                    <p>This is easily achieved using an import statement in which the <code>import</code> keyword is followed by the fully qualified name of the member you wish to use. Consider the example given previously, but revised to use this method:</p>
                    <source xml:space="preserve">import java.util.Vector;
class Test {
   Vector vector;
   
   Test() {
      vector = new Vector();
   }
}</source>
                </section>
                <section>
                    <title>Importing an Entire Package</title>
                    <p>It may be that you use a number of members from a package and end up with a large number of import statements. As an example consider the following:</p>
                    <source xml:space="preserve">import java.util.Vector;
import java.util.LinkedList;
import java.util.Hashtable
import java.util.Stack
import java.util.Set

class Test {
   ...
}</source>
                    <p>This can become messy quite quickly, and you would like to get away from this. The answer is to simply import the entire package, again using the import statement but instead of declaring the member you use a wildcard symbol to indicate that everything should be imported. The wildcard symbol is an asterisk (<code>*</code>), using this method you can replace all the import statements of the previous example with simply one import statement.</p>
                    <source xml:space="preserve">import java.util.*;

class Test {
   ...
}</source>
                    <p>As you can see, this is much cleaner but it does have its limitations. If the package is very large and you import everything in the package, this will impact the performance of your program. You should consider carefully whether greater clarity in your code and ease of writing the code outweighs the addition of some overhead to the performance of your application.</p>
                </section>
            </section>
        </section>
        <section>
            <title>Summary</title>
&#9;&#9;&#9;<p>Packages are a great way to organize your source code and split source code from byte code (class files). Understanding how packages work is vital to writing quality software.</p>
        </section>
        <section>
            <title>Exercise Set</title>
            <section>
                <title>Multiple Choice</title>&#9;
&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Namespaces are used to:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Control access to classes.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Resolve naming conflicts among programmers.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li> Bundle a set of classes together.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>Which is not a benefit of using packages?</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Finding the classes you want is difficult.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Access protection.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Separation of source and class files.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>To create a package named "za.co.nephila.maculata" you would use which statement?</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>package maculata</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>package nephila.maculata</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>package za.co.nephila.maculata</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>To import the ChatServer member of the Maculata package (za.co.nephila.maculata) you would use:</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>import maculata.*;</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>import za.co.nepihla.maculata.*;</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>import za.co.nephila.maculata.ChatServer;</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;&#9;<li>
&#9;&#9;&#9;&#9;&#9;&#9;<p>The classes of the Maculata package (za.co.nephila.maculata) will be in which directory?</p>
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>/Maculata/classes</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>/Maculata/classes/za/co/nephila/maculata</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li><code>/Maculata/src/za/co/nephila/maculata</code></li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
&#9;&#9;&#9;&#9;</ol>&#9;&#9;
            </section>
            <section>
                <title>Exercises</title>
                <ol>
                    <li>Take a look at the Java API and see how the packages are structured.</li>
                </ol>&#9;&#9;&#9;&#9;&#9;
            </section>
            <section>
                <title>Programming Exercises</title>
                <ol>
                    <li>Complete the following:
&#9;&#9;&#9;&#9;&#9;&#9;<ol>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Create a package named <code>org.shapes</code>.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Create some classes in the package representing some common geometric shapes like Square, Triangle, Circle and so on.</li>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<li>Finally compile the package as discussed in this chapter.</li>
&#9;&#9;&#9;&#9;&#9;&#9;</ol>
&#9;&#9;&#9;&#9;&#9;</li>
                </ol>
            </section>
        </section>&#9;&#9;        
    </section>
    <section class="page" id="chapter4.html"><!--
    Copyright 2005 Trevor Charles Miller. All Rights Reserved.
    Licensed under the Academic Free License version 2.1
--><title>Javadoc Comments</title>
        <section>
            <title>Jargon</title>
            <dl>
                <dt><strong>Deprecated</strong></dt>
                <dd>An API item that is considered obsolete and on its way out, usually in favor of something better. Usually, though the item may have been originally included as part of an API, the use of it is no longer advised, and slowly support for the item is phased out.</dd>
                <dt><strong>Documentation</strong></dt>
                <dd>Instructions that come with a software program, which may include paper or electronic manuals, README files, and online help.</dd>
                <dt><strong>Fatal Error</strong></dt>
                <dd>An error that causes a program to stop executing. See Error and Application Failure.</dd>
                <dt><strong>HTML</strong></dt>
                <dd><em>Hypertext Markup Language</em>, The language used to create World Wide Web pages, with hyperlinks and markup for text formatting.</dd>
                <dt><strong>Internet</strong></dt>
                <dd>A network of computer networks which operates world-wide using a common set of communications protocols.</dd>
                <dt><strong>Member</strong></dt>
                <dd>Class members are items that belong to that class, usually methods and variables and also nested classes.</dd>
                <dt><strong>Options</strong></dt>
                <dd>Alternatives or choices, often refers to settings or preferences in a program that may be set according to the users preference or taste.</dd>
                <dt><strong>Tag</strong></dt>
                <dd>A tag is a marker embedded in a document that indicates the purpose or function of the element. Each element has a beginning tag and an end tag.</dd>
                <dt><strong>Throw</strong></dt>
                <dd>In Java terms, an exception is said to be thrown if the exception is raised. A method may throw an exception if an error occurs in its processing.</dd>
                <dt><strong>Visibility</strong></dt>
                <dd>The accessibility of methods and instance variables to other classes and packages, through the use of access modifiers: public, protected, package or private.</dd>
            </dl>&#9;&#9;&#9;
        </section>
        <section>
            <title>Introduction</title>
            <p>In this chapter we will look at the importance of commenting source code and discuss Java's own method of performing source code documentation using the Javadoc Tool that comes bundles with the Java Development Kit.</p>
            <p>The Javadoc Tool uses simple Java comments with a number of meta tags to provide meta information about the source code. It then parses these comments and uses this information to produce an API that can be used by developers to see the functionality of the source code. It is important to understand how to write these comments in order to produce a good API.</p>
            <p>We will also look at how to run the Javadoc Tool to produce the API and look at some of its more advanced options like sending output to a specific directory, showing private and protected class members and what text should occur in the Window Title of the browser.</p>
            <p>You can get the Javadoc Tool @ [bundled with your JDK, if you have the JDK installed you have the javadoc tool].</p>
        </section>
        <section>
            <title>Commenting In Java</title>
&#9;&#9;&#9;<p>Commenting in Java can take two forms, typical comments that can be found in numerous other programming languages like C/C++; namely single line comments and multiline comments. Then there are Javadoc comments that are unique to the Java language. In this section we will discuss why commenting is needed and look at how to provide the standard single line and multi-line comments in Java.</p>
            <section>
                <title>The Need for Comments</title>
&#9;&#9;&#9;&#9;<p>There are a number of reasons for including comments in source coe, even though many newer software development methodologies refrain from their use, comments do have their place in source code. Some of the reasons for using comments are:</p>
&#9;&#9;&#9;&#9;<ul>
&#9;&#9;&#9;&#9;&#9;<li>Often comments are added at the start of each source file to give a description of what source the file contains and copyright information.</li>
&#9;&#9;&#9;&#9;&#9;<li>The fields and methods of a class are often given brief comments that describe their purpose and what they do.</li>
&#9;&#9;&#9;&#9;&#9;<li>Complex code is often commented heavily to make it clearer and easier to understand.</li>
&#9;&#9;&#9;&#9;</ul>
&#9;&#9;&#9;&#9;<p>The goal in commenting code is to make it possible for the reader to understand what the code does and how it achieves that. There are generally two schools of thought on this, the first says that the more comments the better, however the other school of thought believes that more comments just clutter the code and make it difficult to read.</p>
&#9;&#9;&#9;&#9;<p>Commenting code is therefore a fine balance, you should only provide comments where absolutely necessary and keep them brief. If code is too complex to understand you should consider revising the code to make it clearer or simpler, unless it is impossible to do so or you have very good reasons not to do so.</p>
            </section>
            <section>
                <title>Comments in Java</title>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Single Line Comments</title>
&#9;&#9;&#9;&#9;&#9;<p>Single line comments are used to add a very brief comment within some code, often a long or complex method. They begin with a double forward slash (<code>//</code>) and end with the end of line or carriage return. As an example consider:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
private static String name = "Guys"; //The name to print
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Multi Line Comments</title>
&#9;&#9;&#9;&#9;&#9;<p>If a comment is going to span across more than one line then a multi-line comment should be used. These are often useful for providing more in-depth information. They start with a forward slash followed by an asterisk (<code>/*</code>) and end with an asterisk followed by a forward slash (<code>*/</code>). Consider:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
/* Getter method provides public access in read only fashion.
   This function returns the port number. */
int getPort() { ... }
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;</section>
            </section>
        </section>
        <section>
            <title>Javadoc Comments</title>
&#9;&#9;&#9;<p>Javadoc Comments are specific to the Java language and provide a means for a programmer to fully document his / her source code as well as providing a means to generate an Application Programmer Interface (API) for the code using the javadoc tool that is bundled with the JDK. These comments have a special format which we will discuss in this section and then in the following section we will look at how to use the javadoc tool to generate an API.</p>
            <section>
                <title>The Format of Javadoc Comments</title>
&#9;&#9;&#9;&#9;<p>A Javadoc comment precedes any class, interface, method or field declaration and is similar to a multi-line comment except that it starts with a forward slash followed by two atserisks (<code>/**</code>). The basic format is a description followed by any number of predefined tags. The entrie comment is indented to align with the source code directly beneath it and it may contain any valid HTML. Generally paragraphs should be separated or designated with the <code>&lt;p&gt;</code> tag. As an example consider:</p>
&#9;&#9;&#9;&#9;<source xml:space="preserve">
/**
 * A Container is an object that contains other objects.
 * @author Trevor Miller
 * @version 1.2
 * @since 0.3
 */
public abstract class Container {
    
    /**
     * Create an empty container.
     */
    protected Container() { }
    
    /**
     * Return the number of elements contained in this container.
     * @return The number of objects contained
     */
    public abstract int count();
    
    /**
     * Clear all elements from this container. 
     * This removes all contained objects.
     */
    public abstract void clear();
    
    /**
     * Accept the given visitor to visit all objects contained.
     * @param visitor The visitor to accept
     */
    public abstract void accept(final Visitor visitor);
    
    /**
     * Return an iterator over all objects conatined.
     * @return An iterator over all objects
     */
    public abstract Iterator iterator();
    
    /**
     * Determine whether this container is empty or not.
     * @return &lt;CODE&gt;true&lt;/CODE&gt; if the container is empty: 
     * &lt;CODE&gt;count == 0&lt;/CODE&gt;, &lt;CODE&gt;false&lt;/CODE&gt; 
     * otherwise
     */
    public boolean isEmpty() {
        return (this.count() == 0);
    }
    
    /**
     * Determine whether this container is full.
     * @return &lt;CODE&gt;true&lt;/CODE&gt; if conatiner is full, 
     * &lt;CODE&gt;false&lt;/CODE&gt; otherwise
     */
    public boolean isFull() {
        return false;
    }
    
}
&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;<p>We will now discuss the descriptions of a Javadoc comment first before looking at the different tags and their uses.</p>
            </section>
            <section>
                <title>Descriptions</title>
&#9;&#9;&#9;&#9;<p>The description should give a concise summary of the item being commented. It should be written in simple and clear English using correct spelling and grammar. Punctuation is required. There are some important style guidelines to bear in mind:</p>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>The first sentence</title>
&#9;&#9;&#9;&#9;&#9;<p>The first sentence of the description is the most important part of the entire description. It should be a short and concise summary of the item being commented. This is due to the fact that the Javadoc tool copies the first sentence to the appropriate class or package summary page, which implies that the first sentence should be compact and can stand on its own.</p>
&#9;&#9;&#9;&#9;&#9;<p>Take a look at the example above again and you'll see that the first sentence is a brief descriptive summary of each item.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>The use of the &lt;code&gt; tag</title>
&#9;&#9;&#9;&#9;&#9;<p>The use of the &lt;code&gt; tag is greatly encouraged and should be used for all Java keywords, names and code samples. you'll notice this in the comments of the last two methods of the class in the example above.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Omission of parenthesis</title>
&#9;&#9;&#9;&#9;&#9;<p>When referring to a method that has no parameters or a method which has multiple forms (method overloading) it is acceptable and even encouraged to simply omit the parenthesis. Consider the following example:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
The &lt;code&gt;add&lt;/code&gt; method inserts items into the vector.
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;&#9;<p>This is the correct way of doing it as opposed to the incorrect way in the next example:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
The &lt;code&gt;add()&lt;/code&gt; method inserts items into the vector.&#9;&#9;&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Method descriptions begin with a verb</title>
&#9;&#9;&#9;&#9;&#9;<p>A method usually defines a certain behaviour or operation; because of this it usually signals an action that is best described by a verb.</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
Determine whether this container is empty or not.
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;&#9;<p>As opposed to:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
This method is used to determine whether this container is empty or not.
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Avoid abbreviation</title>
&#9;&#9;&#9;&#9;&#9;<p>One final word on style guidelines is to avoid the use of abbreviation at all costs as this renders comments unclear. Instead of using an abbreviation you should use its expanded form. This applies to all abbreviations.</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
This is also known as...
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;&#9;<p>Instead of using:</p>
&#9;&#9;&#9;&#9;&#9;<source xml:space="preserve">
AKA ...
&#9;&#9;&#9;&#9;&#9;</source>
&#9;&#9;&#9;&#9;</section>&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;
            </section>
            <section>
                <title>Javadoc Tags</title>
&#9;&#9;&#9;&#9;<p>The Javadoc tags are used to provide important or essential meta information about the code. Consider the <code>@author</code> tag in the class comment for the example given above, it gives important information as to who the author of the code is. Each tag has a specific format which we will now look at.</p>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Author Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@author name</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Interface and Class comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Giving the names of the authors of the source code. You should use the full name of the author or "unascribed" when the author is unknown. Authors are listed in chronological order, with the creator of the class or interface being listed first.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Since Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@since version</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Interface and Class comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Indicates the version of the source code that this item was introduced. It is usually just a version umber but may also contain a specific date.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Version Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@version description</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Interface and Class comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Describes the current version number of the source code. This is often simply a version number including only the major and minor number and not build number. Some instances also include a date.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Deprecated tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@deprecated</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Interface, class and method comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Used to indicated that an item is a member of the deprecated API. Deprecated items should not be used and are merely included for backwards compatibility.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Parameter Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@param name description</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Method comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Describes a method parameter. The name should be the formal parameter name. the description should be a brief one line description of the parameter.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Return Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@return description</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Method comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Describe the return value from a method with the exception of void methods and con    tructors.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>Exception Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@throws exception description</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Method comments.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> Indicates any exceptions that the method might throw and the possible reasons for this exception occurring.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>See Class Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@see classname</code></p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used Where:</strong> Any item being commented.</p>
&#9;&#9;&#9;&#9;&#9;<p><strong>Used For:</strong> If another class may help provide clarity this tag may be used to provide a link to that class.</p>
&#9;&#9;&#9;&#9;</section>
&#9;&#9;&#9;&#9;<section>
&#9;&#9;&#9;&#9;&#9;<title>See Class Member Tag</title>
&#9;&#9;&#9;&#9;&#9;<p><strong>Form:</strong> <code>@see 