Lost Password?

  #1 (permalink)  
Old 01-19-2007, 05:48 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,352
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default Java:Reference - Proper Comments

What is a comment? How do you use comments in Java? When should they be used? If you are wondering you should read on

Prerequisites
None.

The Idea
Probably the most important piece of code you can write is a comment. Comments not only make your code more clear to others, it will also help you to remember what you were thinking for future development.

The Solution
A comment is a piece of code that is ignored by the compiler that allows others to understand what is going on. In java there are two ways you can comment your code. You can use the traditional double forward slash like this
Code:
//This is a comment
which comments everything to the left of the double forward slashes and ends with a new line. Or the other commonly used comment for commenting multiple is the forward slash asterisk like this:
Code:
/**
using this
You can
Comment multiple
Lines 
*/
It is a common standard to comment every method in a class and include the parameters and return values. The java docs make specific use of this. Lets say we are giving a simple class like the one below:
Code:
package helloworld;
public class Hello {
	private String name;
	public hello(String aName) {
		name = aName;
	}

	public String sayHello(){
		Return "Hello, " + name + "!";
	}
}
If this code were well commented it would look like this:

Code:
package helloworld;
public class Hello {
	private String name;
/**
Constructs a Hello object that can greet a person.
@param aName the name of the person who should be addressed.
*/
	
public hello(String aName) {
		name = aName;
	}
/**
Greet with a "Hello" message.
@return a message containing “Hello” and the 
name of the person.
*/
	public String sayHello(){
		Return "Hello, " + name + "!";
	}
}
The first line of a comment should be well formed to give the holistic idea of what that method does. In comments parameters are commented using the @param and return values are commented using @return. If you properly comment your documents, you can use Java's javadoc utility to create a series of HTML files that document your classes and methods, but javadocs use your comments!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-25-2007, 10:59 AM
AfTriX AfTriX is offline
Programming God
 
Join Date: Jan 2007
Location: Sri Lanka
Posts: 596
Rep Power: 0
AfTriX is on a distinguished road
Default

I heard that there is a special comment type in Java that to include the comment into Java Documentation. Can you explain me about that a bit.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-25-2007, 02:09 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,352
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

If you use the
Code:
/**

*/
comments, the first line is used by the java docs as the general description, @return and @param are used by the java docs to include the return and parameters of methods.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-25-2007, 11:20 PM
AfTriX AfTriX is offline
Programming God
 
Join Date: Jan 2007
Location: Sri Lanka
Posts: 596
Rep Power: 0
AfTriX is on a distinguished road
Default

Thanks a Bunch!
And I think

Code:
/*
------
------
------
*/
Can be used to multiple line comments and

Code:
/**
-------
-------
-------
*/
Can be used to Java Doc Comments.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-03-2007, 12:42 AM
pankaj2007 pankaj2007 is offline
Newbie
 
Join Date: Feb 2007
Posts: 7
Rep Power: 0
pankaj2007 is on a distinguished road
Default java editor

can anyone tell the name of JAVA editor for developing different JAVA based applications.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 02-04-2007, 09:53 PM
AfTriX AfTriX is offline
Programming God
 
Join Date: Jan 2007
Location: Sri Lanka
Posts: 596
Rep Power: 0
AfTriX is on a distinguished road
Default

Quote:
Originally Posted by pankaj2007 View Post
can anyone tell the name of JAVA editor for developing different JAVA based applications.
Try to go through this thread, hope this would help you out with your problem.

http://forum.codecall.net/java/2182-best-java-ide.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comments? dirkfirst JavaScript and CSS 3 01-19-2007 09:29 AM
Java:Reference - Operators John Java Tutorials 0 12-09-2006 10:05 AM
Why are comments important? Sionofdarkness Java Help 10 07-29-2006 11:32 AM
Proper way to store and retrieve colors from registry NeedHelp C# Programming 5 05-28-2006 10:28 PM


All times are GMT -5. The time now is 11:11 PM.

Contest Stats

dargueta ........ 93.00000
John ........ 87.50000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads