Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

Comments

Computer programs are read by both computes and humans. You write Java instructions to tell the computer what to do. You must also write comments to explain to humans what the program does. Of course, Java can't understand them because they are written in English, or Spanish, or Thai, or ... .

Java ignores all comments. There is, however, a program called javadoc which reads certain kinds of comments and produces HTML documentation (see below).

Spaces and blank lines

One of the most effective ways to make a program readable is to put spaces in at key points. There are several styles for doing this. Even more important is to put blank lines in your program. These should separate sections of code. There should be a blank line between each "paragraph" of code. By paragraph, I mean a group of statements that belong together logically; there is no Java concept of paragraph.

Java comments

// comments -- one line
After the two // characters, Java ignores everything to the end of the line. This is the most common type of comment.
      //--- local variables ---
      int nquest;  // number of questions.
      int score;   // count of number correct minus number wrong.
      
/* ... */ comments -- multiple lines
After the /* characters, Java will ignore everything until it finds a */. This kind of comment can cross many lines, and is commonly used to "comment out" sections of code -- making Java code into a comment while debugging a program. For example,
   /* Use comments to describe variables or sections of the program.
      They are very helpful to everyone who reads your programs:
      your teacher, your boss, but especially yourself!
   */
javadoc comments
Comments that start with /** are used by the javadoc program to produce HTML documentation for the program. The Java documentation from Sun Microsystems is produced using javadoc. It is essential to use this kind of comment for large programs.

Best Practices

  • Don't write comments to document obvious statements. Assume the reader knows Java.
  • Every comment has the potential to create an inconsistency between what the comment says, and what the code does. One cause of "software rot" is that code is changed over time, but comments are not updated. To avoid this, keep comments next to the code that is documented so that they may be more easily synchonized.

Interesting comments

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.