From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03
04 /**
05 * All about my application.
06 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
07 */
08 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 GenericExample<S,T extendsextends means to customize or extend the functionality of a class Number>
09 {open braces start code blocks and must be matched with a close brace
10 privateprivate is used to restrict access to the current class only T t;
11 privateprivate is used to restrict access to the current class only S s;
12
13 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setValue(T t)
14 {open braces start code blocks and must be matched with a close brace
15 thisthis means the current object (the implicit parameter).t=this assignment operator makes the left side equal to the right sidet;
16 }close braces end code blocks and must match an earlier open brace
17
18 publicpublic is used to indicate unrestricted access (any other class can have access) T getValue()
19 {open braces start code blocks and must be matched with a close brace
20 returnreturn means to provide the result of the method and/or cease execution of the method immediately t;
21 }close braces end code blocks and must match an earlier open brace
22
23 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setKey(S s)
24 {open braces start code blocks and must be matched with a close brace
25 thisthis means the current object (the implicit parameter).s=this assignment operator makes the left side equal to the right sides;
26 }close braces end code blocks and must match an earlier open brace
27
28 publicpublic is used to indicate unrestricted access (any other class can have access) S getKey()
29 {open braces start code blocks and must be matched with a close brace
30 returnreturn means to provide the result of the method and/or cease execution of the method immediately s;
31 }close braces end code blocks and must match an earlier open brace
32
33 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
34 {open braces start code blocks and must be matched with a close brace
35 returnreturn means to provide the result of the method and/or cease execution of the method immediately "key="+adds two numbers together or concatenates Strings togethers+adds two numbers together or concatenates Strings together", value="+adds two numbers together or concatenates Strings togethert;
36 }close braces end code blocks and must match an earlier open brace
37
38 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)
39 {open braces start code blocks and must be matched with a close brace
40 GenericExample<String, Double> example=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor GenericExample<String, Double>();
41 example.setKey("Howdy!");
42 example.setValue(4.5);
43 System.out.println(example);
44 }close braces end code blocks and must match an earlier open brace
45 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/GenericExample.java