Java Reference
In-Depth Information
/*
*Asimple application.
*/
public class SimpleApp1
{
Begin with comments describing
the class.
The class signature .
public static void main (String[] args)
{
Application processing always
begins in this method.
// Print a string to the console.
Single line comment
System.out.println ( " An application " );
Print to console.
}
Braces span the code for a class
and the code for each method.
}
The code includes the keywords public , class , static , void , and main .
The brace symbols {} enclose the contents of a class, which in this case has the
name (i.e. the identifier) SimpleApp1 . Similarly, matching braces enclose the
contents of the method named main .Parentheses enclose a method's parameter
list, which in this case consists of an array of strings named args . (Programmers
in C/C
++
will note the resemblance to the main method in those languages,
though its argument is not a string array.)
Methods, like subroutines and functions in other languages, carry out specific
tasks. This program has only the single method main() . This method is required
for all application programs and is the first method invoked when the program
starts. This main() method only holds a single statement, which invokes another
method to print a string literal to the console. The println() method comes
with the core language.
2.4 Comments
Java denotes comments in three ways. Double slashes precede a single line com-
ment as in
// Print a string to the console.
As seen in some of the examples above, double slashes can also be used at the
end of a statement, after the semicolon, to add a comment on the rest of the line.
Alternatively, you can bracket one- or multiple-line comments with matching
slash-asterisk and asterisk-slash, as in
/*
Print a string
to the console.
*/
 
Search WWH ::




Custom Search