With java for a long time, it is said that the debug statement used in most cases is: system.out.println ("Value:" value); this form (no wonder you are Earth
Girl), I have seen something about Java debugging skills these two days, summed up, I will actively use:
One: A simple method is to use a Boolean as: DebugMode, you need to look at the output of the program: if (debugmode) system.out.println ("..");
Set the DebugMode variable to false after the project is completed.
The shortcomings of this method are: in order to start or prohibit Debug, you must change the code.
two:
A slightly better than the above method is: use Java -d: such as: java -ddebug = true myclass,
When using this method, you must add System.GetProperty ("Debug") to all your Class to get the debug logo, so the first method is changed to:
Public Static Final Boolean Debug;
STATIC {
String sdebug = system.getproperty ("debug");
IF (sdebug! = null && sdebug.equalsingnorecase ("true"))
Debug = True;
Else
Debug = false;
}
This can directly modify the debug logo without changing the Source Code, but it is not flexible enough, such as which part you can't specify using the debug function, but just
To use the debug function, you must use all of the code, thus leading to the third debugging method, which can define a class for debugging.
three:
Public class debugmanager {
public static final String SYSTEM_DEBUG_KEY = "system.Debug"; public static final boolean debug; static {debug = toBoolean (SYSTEM_DEBUG_KEY);} private static boolean toBoolean (String key) {boolean debug; String sDebug = System.getProperty (key); if (sDebug = null && sDebug.equalsIgnoreCase ( "true")!) debug = true; else debug = false; return debug;} public static boolean getSystemDebug () {return debug;} public static boolean getSystemDebug (String applicationKey) {if (Debug || Toboolean (ApplicationKey)) Return True; Else Return False;}}