Java debugging

I've never had an IDE with interactive debugging and have had to rely on print statements to tell me where the program is executing and how variables values are changing.

For example: System.out.println("Here I am. x=" + x);

Often conditional using a boolean so I can turn the output on and off with a single statement change:
Java Code:
	boolean debug = true;			
		...
       if(debug){
          System.out.println("Here I am. x=" + x);
	 }
To find out how a method is being called, I add the following statement to print the call stack:
Java Code:
      try{throw new Exception("who called");}catch(Exception ex) {ex.printStackTrace();}
You'll need the -g option on the javac compile to have the statement numbers in the code.

If the method is called many times you may only want to see it once:
Java Code:
   boolean oneTime = true;
     ....
    if(oneTime) {
      oneTime = false;
      try{throw new Exception("who called");}catch(Exception ex) {ex.printStackTrace();}
   }

Finding NullPointerException in large program that doesn't have enough try{}catch blocks:
Copy the NullPointerException.java class from the source.zip file for your JDK and modify:
Java Code:
    // Insert our own special debugging version
    public String getMessage() {
      try{throw new Exception("Where am I");}catch(Exception ex){ex.printStackTrace();}
      return super.getMessage();
    }
Compile it and put the class file(s) in its own jar file. Prepend that jar file to the classpath for the java program using the -Xbootclasspath option:
Java Code:
java  -Xbootclasspath/p:D:\JavaDevelopment\MyJavaClasses.jar -classpath .... ...
When you get a NullPointerException, your code will be called with its printStackTrace() showing who called.