There is no preprocessor in Java. Depending on your build system, you can use a third-party preprocessor (you can find many of them by searching for “Java preprocessor”). Some examples
Depending on the area you want to comment out, you can use block comments and sometimes something like
if (false) { . . . }
If all else fails, just comment out each line using // . Most IDEs have a way to do this (and undo it) efficiently.
PS If you can use block comments (this is not always possible, since block comments cannot be embedded in Java), there is a good trick to minimize the amount of work that needs to be done to disable and leave the commented part out. Start your block comment on a separate line, but end it with another isolated line starting with a line comment, for example:
Then, if you want to re-enable the commented section, just add a second / at the beginning of the block:
//* <block of code now active> //*/
To disable the code again, simply delete the first / .
Ted hopp
source share