Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Dec 11, 2001

Eliminate the Need to Comment/Remove Debug Statements


Often, while developing a system, you need to put a lot of debug statements in the code, all which have to be commented/removed before delivering the application. There's a class with a static method that can be used to turn on/off debug statements without having to comment them or remove them. Here it is:
 
class MyDebug{

    private static boolean bDEBUG = true;
    public static void printDebug(String s){

        if(bDEBUG){
            System.out.println(s);
        }
    }

To print a debug statement, a call to MyDebug.printDebug(s) is all that is needed. To turn off debug statements, just change the bDEBUG static variable to false and recompile the application.
Santhosh Ananthakrishnan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap