Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

commenting out

how was is that you were able to comment out that set of code. . . I donst think we were told the short cut for that. . . even though you told us how to copy and paste

2 Answers

Ok, try highlighting a block of code and try whichever of these options applies to your situation:

I think on Windows its:

Line Comment: hold both: Ctrl + /

Block Comment: hold all three: Ctrl + Shift + /

Same way to remove the comment block.

Mac With Numeric pad:

Line Comment hold both: Cmd + /

Block Comment hold all three: Cmd + Alt + /

Same way to remove the comment block.

Let me know if this works for you.

In the Java programming language there are 2 ways to comment out specific blocks of code:

The first way is a single-line comment and is used, as you can probably guess by now, to comment out a single line of code at a time.

public class CommentExamples {
    public static void main(String[] args) {
        //the line of code in front of these 2 forward slashes is commented out
    }
}

The second way is a multi-line comment, and all of the code between the "/* */" is commented out, and ignored by the compiler.

public class CommentExamples {
    public static void main(String[] args) {
        /*all of 
        this 
        is 
        commented 
        out*/
    }
}

Be careful when commenting out certain parts of code, if you comment out an important piece of code it could cause your entire project to not compile.

I hope this helps, let me know if you have any other questions.

the thing I was looking for tho is the block of text was higlighted and then a hotkey was used to comment it out what was that hot key