This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Does java supports  conditional compilation ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does java supports  conditional compilation ?" Watch "Does java supports  conditional compilation ?" New topic
Author

Does java supports conditional compilation ?

Ant Swa
Greenhorn

Joined: May 28, 2002
Posts: 13
Hi,
C++ has this powerfull feature of conditional compilation. It enables choosing between different code segments to compile depending on a flag. Does Java has a similar feature. ?
Say, for example, for a paricular program we can compile a debug version with System.out messages. and a production version without the messages if that kind of feature is avalable.
Please enlighten me..
:roll:


Anton
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
There are two answers to this, really.
The first second answer is that, no, java does not have a built-in preprocessor like C and C++ do, so it has not got conditional compilation. There's nothing stopping you running any external preprocessor you like over your code before you compile it, though. Checkout freely available preprocessors such as "m4".
The second answer is that, no, Java does not have a preprocessor, but it does have a pretty smart compiler, and if you do something like:

It probably won't bother generating the code for the print. The compiler knows at compile time that the code can never be executed, because the "if" condition is "final".
Has this helped ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ant Swa
Greenhorn

Joined: May 28, 2002
Posts: 13
thanks, I got the point.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does java supports conditional compilation ?