Solved

condional compilation

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 38
triangle challenge 4 77
changeXy challenge 13 57
starter POM and spring-boot-starter,  spring-boot-web 2 14
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

705 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