Solved

condional compilation

Posted on 1998-02-20
1
144 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse Neon and jdk 1.8.0 11 138
DO we need Java installed on a Windows PC and WHY ? 13 98
MySQL  on Tomcat 8 30
expectj telnet failing 5 26
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now