From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch14.core;
02
03 importimport means to make the classes and/or packages available in this program scg.ch14.io.SansCommentFilterReader;
04
05 importimport means to make the classes and/or packages available in this program java.io.File;
06 importimport means to make the classes and/or packages available in this program java.io.FileNotFoundException;
07 importimport means to make the classes and/or packages available in this program java.io.FileReader;
08 importimport means to make the classes and/or packages available in this program java.util.Scanner;
09
10 importimport means to make the classes and/or packages available in this program scg.ch14.dictionary.Dictionary;
11
12 /**
13 * Test the alias dictionary by reading in a file and printing out the
14 * contents of the dictionary.
15 */
16 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects TestDictionary {open braces start code blocks and must be matched with a close brace
17 /**
18 * @paramthis is the Javadoc tag for documenting the purpose of parameters args
19 */
20 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args) {open braces start code blocks and must be matched with a close brace
21 ifif executes the next statement only if the condition in parenthesis evaluates to true (args.length > 0) {open braces start code blocks and must be matched with a close brace
22 Scanner aliases =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
23 trytry is for executing a code block that may experience exceptions (errors) {open braces start code blocks and must be matched with a close brace
24 aliases =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(newnew is used to create objects by calling the constructor SansCommentFilterReader(
25 newnew is used to create objects by calling the constructor FileReader(newnew is used to create objects by calling the constructor File(args[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays))));
26 Dictionary dictionary =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Dictionary(aliases);
27 System.out.println("=====================");
28 System.out.println("dictionary = \n" +adds two numbers together or concatenates Strings together dictionary);
29 System.out.println("=====================");
30 }close braces end code blocks and must match an earlier open brace catchcatch means to handle an exception that may occur (FileNotFoundException e) {open braces start code blocks and must be matched with a close brace
31 System.err.println("Unable to open " +adds two numbers together or concatenates Strings together args[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays +adds two numbers together or concatenates Strings together " for input.");
32 }close braces end code blocks and must match an earlier open brace finallyfinally is what always executes at the end of a try block {open braces start code blocks and must be matched with a close brace
33 ifif executes the next statement only if the condition in parenthesis evaluates to true (aliases !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace
34 aliases.close();
35 }close braces end code blocks and must match an earlier open brace
36 }close braces end code blocks and must match an earlier open brace
37 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
38 System.err.println("usage: java TestDictionary dictionaryFName");
39 System.err.println(" where dictanaryFName is a file");
40 }close braces end code blocks and must match an earlier open brace
41 }close braces end code blocks and must match an earlier open brace
42 }close braces end code blocks and must match an earlier open brace
43
44 //Uploaded on Mon Mar 29 21:40:54 EDT 2010
|
Download/View scg/ch14/core/TestDictionary.java