Solved

condional compilation

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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 how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 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