Java Rookie Quick Start guide

Source: Internet
Author: User
Tags parent directory

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

Development environment, as long as you install the Java SDK can be

Source Code Hello.java:

  hello{
Main (string[] args)
{
System.out.println (); }
}

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.