Solved

condional compilation

Posted on 1998-02-20
1
145 Views
Last Modified: 2010-04-16
Is there a way to do conditional compilation in Java?  Like in C I when I compile I can define something like DEBUG so that various debug statements will be executed, ie using #IFDEF and #ENDIF statements.  How do I do this in Java
0
Comment
Question by:micah
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 1233174
There is no explicit conditional compilation included in Java. This was a feature intended to be used for platform dependencies. Java presupposes the platform to be irrelevant. (It hasn't quite succeeded yet, but that's another story).

You can achieve a similar result though, by using "constants", i.e. variables that are declared final. If you, for instance, had a variable defined:

public static final boolean debug=false;

and had code:

if(debug)
{ System.out.println("DEBUG STUFF");
}

then the debug statement will not be executed, and most Java compilers will not include the code in the class file at all.

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 97
micro services spring boot application error 3 199
how to add new optional parameter to JSP 1 42
MySqlDump not dumping triggers 1 32
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question