Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:10:25+00:00 2026-05-24T20:10:25+00:00

While writing experimental code, I find it very useful to comment out entire blocks

  • 0

While writing experimental code, I find it very useful to comment out entire blocks of code at a time. However, i can’t find a reasonable way to do this in Java, because I frequently end up with nested blocks being commented out.

In C or C#, this is easily achieved using #if 0 or #if false

I can’t seem to find any such equivalent in Java — any help would be appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:10:27+00:00Added an answer on May 24, 2026 at 8:10 pm

    I’m presuming you are wanting to comment out nested code for debugging or testing purposes, right? Because leaving huge blocks of commented out code in production code is generally considered very bad style.

    Nested comments is not natively a feature of java. So what can you do? Here are some different options:

    Slash Slash comment nesting The best I’ve been able to come up with is to use an editor that has a hotkey to slashslash comment out an entire block of code as //’s can be nested. Eclipse and Netbeans both have this support, though there are minor differences in how it works between IDEs, as far as when it decides to toggle the comments vs nest them. Usually nesting // comments can be done so long as the selections are not identical.

    third party preprocessor That said, J2ME uses a pre-processor in eclipse, but I don’t think that would help with desktop java. There do appear to be other preprocessors written for or compatible with eclipse if you search for them. However, that definitely would hinder portability as that’s not a standard java feature.

    modify comment Another thing I’ve often done for a quick nested comment need (moreso in css which doesn’t do // comments than java though) is to add a space between the final two characters ending the inner comment */ so that java will not end the outer comment at the inner comment’s end. Not too difficult (but slightly manual) to restore the original comment. The nested /* is usually ignored by the parser based on how it does its pattern matching. Eg /* code /* nested comment * / more code */`

    use version control You could also easily use most any version control system to save a copy of your code with the code to remove. And then later use the version control restore/diff/merge to get your removed code back. Generally this solution is considered the best style. Especially if this commented out code will be needed to be left that way for long amounts of time.

    if (false) If your code that you want to mass prevent from running both compiles and is within a single function, you can easily disable it by adding an if statement around it that the condition will never be true such as if (false) { ... } Obviously, this would never pass any sort of lint type code inspection tool, but its quick and easy 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing some C code, I decided to compile it to assembly and read
While writing code in a file that would comprise of PHP, HTML, CSS &
While writing code, it is pretty common to request a page with an appended
Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
I got this doubt while writing some code. Is 'bool' a basic datatype defined
While writing JavaScript code, I Separate each code block with <script> tags <script type=text/javascript>
While writing javascript, one can define a method in 3 different ways. 1] A
While writing Scala RemoteActor code, I noticed some pitfalls: RemoteActor.classLoader = getClass().getClassLoader() has to
While writing some code i came across this issue: #include <iostream> class random {
Accidentally I pressed some keys while writing C# code in VS2008 and space characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.