Java is very flexible in this case, plus there are many custom libraries enable you to do this(log4j).
As you dont want to use any of them, but still allow you to do it flexibly with out recompiling the code,
- Define a properties file (say custom.properties)
enabledebug=true
Define a global property
class Global { public static boolean DEBUGFLAG=false; }
Define a method to read the property and the the flag value to global variable
public void load() { Properties props = new Properties(); FileInputStream fis = new FileInputStream("....custom.properties") props.load(fis); Global.DEBUGFLAG= Boolean.valueOf(props.get("enabledebug")); }
Invoke
load
method from main methoduse the flag when ever you need to print verbose
if(Global.DEBUGFLAG) { //print some thing }