Debugging of Classes in Java

Debugging of Classes in Java


Posted in : Core Java Posted on : October 12, 2010 at 6:45 PM Comments : [ 0 ]

This section contains the detail about the Debugging of Classes in Java

Debugging of Classes in Java

To debug Java program, we use 'jdb' which stands for Java debugger. The jdb is included in JDK 1.2 package. The Java Debugger API allows us to actually peek into the runtime and debug our code. The jdb is just one implementation of a debugger that uses the API.

Before debugging, you must include -g while compiling your class. This option tells the compiler to include debugging information in your class file.

The class which we are using for compiling is given below :

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.IOException;

public class OrderParser
{

   public  OrderParser()
	{
       File docFile = new File("order.xml");
       Document doc = null;
      
 try {
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       doc = db.parse(docFile);
	   visit(doc, 0);
	   System.out.print(" parsing the file");

      }
	catch (Exception e)
		  {
             System.out.print("Problem parsing the file: "+e.getMessage());
          }
	}
    public void visit(Node node,int level)
	{
		NodeList nlist = node.getChildNodes();
		
		for(int i=0, count=nlist.getLength(); i < count; i++)
		{
			System.out.println(nlist.item(i));
			
			visit(nlist.item(i), level+1);
		}
	}
	
	public static void main(String[] args)
	{
		new OrderParser();
	}

}

Debugging Procedure :

Step1 : Before debugging, you must include -g while compiling your class. This option tells the compiler to include debugging information in your class file.

Step2 : Set break point : You can set breakpoint using  : stop in <class id>.<method>[<argument_type,...>]  OR  stop at <class id>:<line>

Step 3: You can start debugging using run command . It debug code step by step, so if it haults , you can resume debugging by running cont command.

It gives result after executing each step and show you it's value to you and debugging stops after end of the code and will exit out of program.

Given below the figure of debugging, we only provides you first and last parts of debugging for shake of demonstration.

And last part of the debugging where it exits :

Download Complete Snaps of Debugging

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics