Comments

Submitted by: 
Language: 

Introduction:
Welcome to a tutorial on the use of comments within Java.

What are comments?
Comments are just like the standard definition of comments anywhere in the world, they are used to explain something within the midst of the code. Comments are not read by Java and as such do not affect the program running.

When are comments used?
Comments are normally used to either make a note for the developer their self so they know where they need to go back to, or bookmark a specific location within a Java file. Comments are also very handy for large scripts, or for sending a block of sample code as you are able to annotate what each line does.

What is the format for a comment?
To submit a comment within Java, there are two ways to do this, the first one is a simple, one line comment which begins with two forward slashes ("//"). The second way allows multiple comment lines in a row which start with an asterix ("*") and is initialised by "/**" and terminated with "*/". Examples below.

Examples:
Here is an example of both types of comment...

  1. //System.out.println("1 This line is a comment and so is not ran by Java.");
  2. System.out.println("2 This line is not a comment and so is ran by Java.");
  3.  
  4. /**
  5.  * System.out.println("3 This line is a comment and so is not ran by Java.");
  6.  * System.out.println("3.5 This line is a comment and so is not ran by Java.");
  7.  */
  8. System.out.println("4 This line is not a comment and so is ran by Java.");
2 This line is not a comment and so is ran by Java.
4 This line is not a comment and so is ran by Java.

As you can see, the three lines in the comment types are not ran by Java.

Finished!


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.