Without editing the source to remove the debugging codes, you can rely on the simple optimization that the JAVA compiler always do. If a if expression is always false, the code in the if statement will not be included in the compilation. Not only the resulting class will be smaller, but the execution time will be a little faster too by not making unnecessary test.
The technique is simple. In the development environment, you have a class called Debug.
public class Debug {
public static final boolean RELEASE = true;
}
if (Debug.RELEASE) {
System.out.println("The value of i is " + i);
}
public class Debug {
public static final boolean RELEASE = false;
}Another way is to simply close the out stream.
(System.out.println() will be present in your class but
the output is disabled).
public class TestOut {
public TestOut() { }
public static void main(String s[]) {
System.out.close(); // may want System.err.close() too
for (int i=0; i < 100000; i++){ System.out.print(".");}
}
}
Written and compiled by Réal Gagnon ©1998-2005
[ home ]