|
|
Comments
Fundamental Programming Standards
Comments
- Just as you could use the number sign
(#) to let the Perl interpreter know that a line in the code
was a comment, you can specify comments in Java.
- Actually, there are several ways to
denote comments in Java.
- For single line comments, you can use
the "//" notation. For example, consider the following code:
// Initialize variables...
int age = 28; // Declare and initialize age
- Single line comments
can be defined on the same line as your code or on their own
line
- To specify multiline comments, however,
you will use the "/*" and "*/" combination such as in the following
example:
/*
This is a sample class which is used to demonstrate
the use of multi-line comments. it was written by
Selena Sol for the Web Programming Tutorial
*/
// Define an Example class with a single
// main() method which will print out
// "Hello Cyberspace!" to standard output.
public class Example
{
public static void main(String[] args)
{
System.out.println("Hello Cyberspace!");
}
}
- As you can see, if you use the "//"
notation and your comment spans multiple lines, you must
begin each new line with a "//" combination.
- Finally, if you are writing comments
which should be included as part of a javadoc document, you
should use the "/**" "*/" combination such as in the following
example:
/*
This is a sample class which is used to demonstrate
the use of multi-line comments. it was written by
Selena Sol for the Web Programming Tutorial. This comment
does not appear in the java documentation
*/
/**
Define an Example class with a single
main() method which will print out
"Hello Cyberspace!" to standard output.
This comment appears in the javadoc.
*/
public class Example
{
public static void main(String[] args)
{
System.out.println("Hello Cyberspace!");
}
}
Additional Resources:
Setting Your Development Environment
Table of Contents
Printing to Standard Output
|
|