Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Mar 27, 2001



Application Security Testing: An Integral Part of DevOps

Conditional Compilation in Java

The C preprocessor provides for conditional compilation in instances where large areas of text are ignored and stripped out, regardless of whether a given preprocessor constant was defined. For example:
#if defined(XYZ)
    //code part 1
     //code part 2

Although this functionality is not directly available in Java, we can achieve the same as follows:

Step 1: Define an Interface:
interface ABC

    public static final boolean XYZ= true;

Step 2: Write the conditional statement as usual:
 if (ABC.XYZ)
     // Code part 1
     // Code part 2

The Java compiler is smart and completely strips the code of the appropriate conditional branch.
Sudip Bhattacharya
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date