• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

comments

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to clarify, what they have posted is the same as this:
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic