?
Solved

condional compilation

Posted on 1998-02-20
1
Medium Priority
?
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Suggested Courses

770 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