Reputation: 14953
In Java what is the syntax for commenting out multiple lines?
I want to do something like:
(comment)
LINES I WANT COMMENTED
LINES I WANT COMMENTED
LINES I WANT COMMENTED
(/comment)
Upvotes: 17
Views: 157422
Reputation: 10482
As @kgrad says, /* */ does not nest and can cause errors. A better answer is:
// LINE *of code* I WANT COMMENTED
// LINE *of code* I WANT COMMENTED
// LINE *of code* I WANT COMMENTED
Most IDEs have a single keyboard command for doing/undoing this, so there's really no reason to use the other style any more. For example: in eclipse, select the block of text and hit Ctrl+/
To undo that type of comment, use Ctrl+\
UPDATE: The Sun (now Oracle) coding convention says that this style should not be used for block text comments:
// Using the slash-slash
// style of comment as shown
// in this paragraph of non-code text is
// against the coding convention.
but // can be used 3 other ways:
Upvotes: 15
Reputation: 4792
/*
Lines to be commented
*/
NB: multiline comments like this DO NOT NEST. This can be the source of errors. It is generally better to just comment every line with //. Most IDEs allow you to do this quite simply.
Upvotes: 21
Reputation: 61771
The simple question to your answer is already answered a lot of times:
/*
LINES I WANT COMMENTED
LINES I WANT COMMENTED
LINES I WANT COMMENTED
*/
From your question it sounds like you want to comment out a lot of code?? I would advise to use a repository(git/github) to manage your files instead of commenting out lines.
Upvotes: 1
Reputation: 897
/*
*STUFF HERE
*/
or you can use //
on every line.
Below is what is called a JavaDoc comment which allows you to use certain tags (@return, @param, etc...) for documentation purposes.
/**
*COMMENTED OUT STUFF HERE
*AND HERE
*/
More information on comments and conventions can be found here.
Upvotes: 11
Reputation: 33143
You could use /* begin comment and end it with */
Or you can simply use // across each line (not recommended)
/*
Here is an article you could of read that tells you all about how to comment
on multiple lines too!:
[http://java.sun.com/docs/codeconv/html/CodeConventions.doc4.html][1]
*/
Upvotes: 4
Reputation: 60065
/*
LINES I WANT COMMENTED
LINES I WANT COMMENTED
LINES I WANT COMMENTED
*/
Upvotes: 57