How to write Debugging a Hello World program in the most humble development environment.
For novice programmers who don't know anything about Java syntax, or programmers who just want to write code but aren't interested in object-oriented
Compile:
>javac Hello.java
Or
>javac-g Hello.java.
-G indicates that the generated target file has a debug symbol (recommended, because these symbols are required for later use with JDB debugging code). The compiled target file is Hello.class
Run:
>JAVA-CP. Hello
Note that you do not need to bring the. class suffix name behind hello.
Debugging:
Enter the directory where Hello.class and Hello.java reside.
>jdb-classpath. Hello
Into the jdb of the interactive debugging environment
To set a breakpoint in function main:
>stop in Hello.main
JDB display prompts:
Deferring breakpoint Main.hello.
It'll be set after the ' class is loaded.
The hello above is the class name, which is hello in the Hello,hello.java in Hello.class. Main is the function name. If there is a "package Any_namespace" in the first line of Hello.java statement, the correct class name is Any_namespace.main, then the statement that sets the breakpoint in Jdb is:
>stop in Any_namespace.hello.main
Run the program after you set the breakpoint:
>run
You can see that JDB is running to the point where the breakpoint is parked. Set breakpoints to class Hello (in Java, the class name and file name are actually meaning) the statement on line 3rd is:
>stop at Hello:3
The statement that displays the expression is the print variable_name, which shows the statement of the current call stack as where, the single step-debug statement is next or steps (I think the difference between next and step does not have to be verbose), the statement that displays the current code is list. To see Jdb's online Help, enter help (nothing more than nothing).
The
Use command specifies the search path for the corresponding source code file for the debug symbol, and if we delete Hello.java and then restart Jdb, set a breakpoint, and run Hello,jdb will report "Source File not Found:hello.java". When you enter use, you can see that the current source search path is ".", if you copy Hello.java to the parent directory, and then enter the command Tell Jdb not only to the current directory search Hello.java, but also to the parent directory search Hello.java, and then enter the List command, you can now see Jdb correctly display the source code. <iframe frameborder= "0" src= "http://www.google.com/gn/static_files/blank.html" style= "Position:absolute"; Display:block; opacity:0.7; z-index:500; width:17px; height:21px; top:49px; right:129px; "id=" Gn_notemagic "></IFRAME>