Multi-line comments start with /* and ends with */ . Any text between /* and */ will be ignored by Java.
The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .
The first is called a single line comment and, as implied, only applies to a single line in the "source code" (the program). The second is called a Block comment and refers usually refers to a paragraph of text. A block comment has a start symbol and an end symbol and everything between is ignored by the computer.
Ctrl-/ to toggle "//" comments and Ctrl-Shift-/ to toggle "/* */" comments. At least for Java, anyway - other tooling may have different shortcuts.
Ctrl-\ will remove a block of either comment, but won't add comments.
Note: As for Eclipse CDT 4.4.2, Ctrl-Shift-/ will not uncomment a "/* */" block comment. Use Ctrl-Shift-\ in that case.
EDIT: It's Ctrl on a PC, but on a Mac the shortcuts may all be Cmd instead. I don't have a Mac myself, so can't easily check.
There are two possibilities:
ctrl + / to comment
ctrl + \ to uncomment
Note: on recent eclipse cdt, ctrl + / is used to toggle comments (and ctrl + \ has no more effect)
ctrl + shift + / to comment
ctrl + shift + \ to remove
For Eclipse Editor
For Single Line (Toggle Effect)
Comment : Ctrl+Shift+c
Uncomment: Ctrl+Shift+c
For Multiple Lines (Toggle Effect) (Select the lines you want to comment)
comment : Ctrl+Shift+c
Uncomment: Ctrl+Shift+c
It is for all html , css , jsp , java . It gives toggle effect.
I came here looking for an answer and ended up finding it myself, thanks to the previous responses.
In my particular case, while editing PHP code on Eclipse Juno, I have found that the previous commands won't work for me. Instead of them, I should press Ctrl+ 7 (on the superior number key) to obtain the double bar comment ("//"). There's no way I can comment them with the previous mentioned key combinations.
As other answers pointed out, the following shortcuts are defined by default (I'm referring to editing java source - shortcut bindings can be found in eclipse Window>Preferences, under 'General'/'Keys', search for 'comment'):
Unfortunately, these shortcuts did not work for me (on Eclipse Java EE IDE for Web Developers, version: Juno Service Release 2).
The reason, I think, is my keyboard layout (QWERTZ keyboard layout used in Germany - see here for further information), where '/' actually has to be written via 'Shift + 7'.
I therefore had to change the shortcut bindings for comments (just did it for editing java source) in the eclipse preferences (under 'General'/'Keys') as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With