Packages provide a grouping for
In
Java For Artists
I will show you how to work with packages. A package structure is simply a directory hierarchy. Related class and interface source-code files are placed in related directories. The ability to create your own package structures will
I will use several package naming conventions to organize the code in this book. For starters, I will place short, simple programs in the default package. By this I mean that the classes
I use the following package naming convention for the code presented in chapters 1 and 2:
com.pulpfreepress.jfa.chapter1
An example of this package structure appeared earlier in examples 1.1 and 1.2. For complex projects presented in later chapters I slacked off a bit and
com.pulpfreepress. package_name
Both of these package-naming conventions follow Sun s package-naming recommendations. I recommend that you use the following package naming convention for your projects:
lastname.firstname . project_name
So, for example, if you created a project named RobotRat and your
miller.rick.RobotRat
The Java programming language provides three different ways to add comments to your source code. Using comments is a great way to add documentation directly to your code, and you can place them
You can add single-line comments to Java programs using the
// This is an example of a single-line comment
The compiler ignores everything appearing to the right of the double back
Add multi-line comments to Java programs using a combination of /* and */ character sequences as shown here:
1 /* This is an example of a multi-line comment. The compiler ignores 2 * everything appearing between the first slash-asterisk combination 3 * and the next asterisk-slash combination. It is often helpful to end 4 * the multi-line comment with the asterisk-slash sequence aligned to 5 * the left as shown on thenext line. 6 */
Javadoc comments are special multi-line comments that are
Javadoc comments begin with the characters
/**
and end with the characters
**/
. Javadoc comments can contain descriptive paragraphs, doc-comment tags, and HTML markup. Example 1.3 shows a file named
TestClass.java
that contains embedded javadoc comments.
Example 1.3: TestClass.java
|
|
1 /********************************************************** 2 TestClassdemonstrates the use of <b>javadoc</b> comments. 3 @author Rick Miller 4 @version 1.0, 09/20/03 5 **********************************************************/ 6 public class TestClass { 7 8 private int its_value; 9 10 /** 11 * TestClass constructor 12 * @param value An integer value used to set its_value 13 **/ 14 public TestClass(int value){ 15 its_value = value; 16 } 17 18 /** 19 *getValue method 20 * @return integer value of its_value 21 **/ 22 public int getValue(){ 23 return its_value; 24 } 25 26 /** 27 * setValue method 28 * @param value Used to set its_value 29 **/ 30 public void setValue(int value){ 31 its_value = value; 32 } 33 }
|
|
Figure 1-2 shows the javadoc tool being used in the UNIX environment to create API documentation for the
TestClass.java
file:
Figure 1-3 shows the results of using the javadoc tool to process the
TestClass.java
file:
Figure 1-3:
javadoc Tool Being Used to Generate TestClass API Documentation
For a complete reference to the javadoc tool and the different doc-comment tags available for use,