Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

E-mail This Page
Add to Favorites


Web Games++

Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials



How To Remove Debugging Code

Java How To: Source Code

Unlike a C/C++ compiler, there is no JAVA compiler directive to exclude certain source code parts from compilation. By making the release version of a class smaller, the loading process will faster.

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;                             

In your source, when you need some debugging codes, you included them in a if statement like

if (Debug.RELEASE) 
   System.out.println("The value of i is " + i);

During compilation, since Debug.RELEASE is always true, the code will be present. In the production environment, the Debug class looks like this:

public class Debug 
   public static final boolean RELEASE = false;

When compiling in that environment, the debugging code will be absent from the class file since Debug.release is always 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++)

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy