How to debug a Java program from command prompt?



Ms. Neelam Shah

To debug a java program first you need to create a java source code.

1. Create a Java program file

Step1

                                                       [Suppose your filename is Sample.java save your file]

2. Compile that file using java compiler i.e. javac compiler

Step-2.1

That will create Sample.class file Step-2.2

3. Now your debugging process begins.
Using Java Debugger start your debugging process.

Step-3.1

[You will get the following message] Step-3.1

4. Now set the breakpoint using stop at command on the command prompt

Step-4

[If you are trying to set breakpoint at blank line or curly braces line then you will get breakpoint error while debugging so make sure that you set breakpoint at line containing some programming statements]

5. If you want to set multiple breakpoints then you have to use multiple stop at command

Step-5

6. Now your breakpoints are set, and you are able to start your debugging process using run command

Step-6.1

[After executing run command you will get message that your breakpoint are set at given line number] Step-6.2

7. To continue executing you code ,use cont command

Step-7.1

[To hit next breakpoint you should use cont command again and again] Step-7.2

8. You can also set breakpoint at debugging time and if you are trying to set breakpoint at line on which there is no programming statement then you will get message no code at given line number. For example:

Step-8

[Your breakpoint is not going to set]

9. Use cont command again and again till you want or till it reaches end of the program. If you want to break your debugging process then you can use ctrl + z.

Step-9