Wednesday, 5 December 2012

Commenting Your Code

              Comments are used to document your code.You can use comments to explain code that is difficult to understand as well as the inner workings of any algorithms that are used.Comments provide an important communication tool between you and the programmer who will update and maintain the code at a later date.

  1. <html>
  2. <head>
  3. <title> Simple JSP page </title>
  4. </head>
  5. <body>
  6. <h3>Including Comments in your code</h3>
  7. <p>
  8. <!-- An HTML Comment -->
  9. <%--A JSP Comment --%>
  10. <%
  11. // A Single line comment
  12. for(int i=1;i<7;i++)
  13. {
  14. /* A multi line comments
  15. spans many lines */
  16. out.println("No of times this code has been repeated:"+i);
  17. out.println("<br>");
  18. }
  19. %>
  20. </body>
  21. </html>

Description:


  •  An HTML comment is enclosed within the <!-- and --> delimiters.HTML comments aren't displayed in a Web page, but they are included in the generated HTML source code.This can easily be accessed by anyone who views the source code in a Web browser.You should not  place any sensitive information in HTML comments.
                      <!-- An HTML Comment -->
  •  JSP comments are enclosed within the <%-- and --%> delimiters. JSP comments are not sent to the Web browser.
                   <%--A JSP Comment --%>
  • The // delimiter can be used to create a single comment line in a Scriplet tag.                                                                   
                  // A Single line comment        
  • A multi-line comment can be placed within the /*  and */ delimiters.
                          /* A multi line comments
                             spans many lines */

************************************OUTPUT***********************************

Including Comments in your code

No of times this code has been repeated:1
No of times this code has been repeated:2
No of times this code has been repeated:3
No of times this code has been repeated:4
No of times this code has been repeated:5
No of times this code has been repeated:6
*******************************************************************************

No comments:

Post a Comment