How to debug a Java program from command prompt?
To debug a java program first you need to create a java source code.
1. Create a Java program file
[Suppose your filename is Sample.java save your file]
2. Compile that file using java compiler i.e. javac compiler
That will create Sample.class file
3. Now your debugging process begins.
Using Java Debugger start your debugging process.
[You will get the following message]
4. Now set the breakpoint using stop at command on the command prompt
[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
6. Now your breakpoints are set, and you are able to start your debugging process using run command
[After executing run command you will get message that your breakpoint are set at given line number]
7. To continue executing you code ,use cont command
[To hit next breakpoint you should use cont command again and again]
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:
[Your breakpoint is not going to set]