devxlogo

Eliminate the Need to Comment/Remove Debug Statements

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.

See also  5 Ways to Improve Customer Experience
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist