aspose file tools*
The moose likes Beginning Java and the fly likes comments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "comments" Watch "comments" New topic
Author

comments

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hey people,
a small question on comments:
I found this on John Hunts mock questions.

I take it that everything from the first /* at the class decleration does not finish the comments until it finds the opposing comment tag of */ before the print statement that has the String "The end".???
Davy


How simple does it have to be???
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

The /* and */ are similar to brackets, braces, and parentisis (forgive my carpy spelling, two). Once you open one, you need to close it.
so, yes, if you have a /*, the comment does not end until it finds a matching */. EVERYTHING is a comment after that opener, until it finds the closer. even antoher open comment...
int x; /* x cooridinate of point */
int y; /* y coordinate of point
int z; /* z coordinate of point */
note that i "forgot" one of the closing comments. this is legal. the comment starts on the second line, and all of the third line is commented out. the fact that there is a second "open comment" is ignored - it's commented out!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

to clarify, what they have posted is the same as this:
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
thanks Fred,
so when I see comments like:
/* well this is a comment line
* this is another
* and this is another
*/
the extra stars just make it easier for programmers to read and do nothing!
Cheers Fred.
Davy
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

you got it!!! what you see here is one big, multi-line comment.
many of the fancier editors (Eclipse, Jbuilder, etc) make this even easier. they color-code the different kinds of things in your code. i have mine set up to put all comments in green, keywords in a light blue, object refs in white, etc.
it becomes quite obvious when you forget to close your comment - you have 30 lines of gree code!!! it's still better to learn java using notepad or something that makes you think about what you're doing first. THEN move to the tools that make the basics easier
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Davy Kelly:
so when I see comments like:
/* well this is a comment line
* this is another
* and this is another
*/
the extra stars just make it easier for programmers to read and do nothing!

If I recall correctly, in older versions of the JavaDoc tool, preformatted code examples needed to appear on lines that began with a *. I believe this requirement has been removed from the JavaDoc tool.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Thanks, it is just that the distance learning company I am learning from, uses this all the time.
I am doing the 1.2 exam, because they say I have to do it, but i will eventually move on to the next version once i have completed my studies.
thanks
Davy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comments