站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题NetBeans IDE 5.5 Quick Start Guide

NetBeans IDE 5.5 Quick Start Guide

摘要: This tutorial provides a very simple and quick introduction to the NetBeans IDE workflow by walking you through the creation of a simple "Hello World" Java console application. Once you are done with this tutorial, you will have a general knowledge of how to create, build, and run applications in the IDE

Before You Begin

To write your first program, you'll need to have the following software installed on your system:

Setting Up the Project

To create an IDE project:

  1. Start NetBeans IDE.
  2. In the IDE, choose File > New Project, as shown in the figure below.

    NetBeans IDE with the File > New Project menu item selected.

  3. In the New Project wizard, expand the General category and select Java Application as shown in the figure below. Then click Next.

    NetBeans IDE, New Project wizard, Choose Project page.

  4. In the Name and Location page of the wizard, do the following (as shown in the figure below):
    • In the Project Name field, type Hello World App.
    • In the Create Main Class field, type helloworldapp.HelloWorldApp.
    • Leave the Set as Main Project checkbox selected.

    NetBeans IDE, New Project wizard, Name and Location page.

  5. Click Finish.

The project is created and opened in the IDE. You should see the following components:

NetBeans IDE with the HelloWorldApp project open.

Adding Code to the Generated Source File

Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has created a skeleton class for you. You can add the "Hello World!" message to the skeleton code by replacing the line:

            // TODO code application logic here
    
with the line:
            System.out.println("Hello World!");
    

Save the change by choosing File > Save.

The file should look something like the following:

 /*
 * HelloWorldApp.java
 *
 * Created on September 15, 2006, 5:27 PM
 *
 * To change this template, choose Tools > Template Manager
 * and open the template in the editor.
 */

 package helloworldapp;

 /**
 * The HelloWorldApp class implements an application that
 * simply displays "Hello World!" to the standard output.
 */
 public class HelloWorldApp {

     /** Creates a new instance of HelloWorldApp */
     public HelloWorldApp() {
     }

     /**
     * @param args the command line arguments
     */
     public static void main(String[] args) {
         //Display "Hello World!"
         System.out.println("Hello World!");
     }

 }
    

Compiling the Source File

To compile your source file, choose Build > Build Main Project from the IDE's main menu.

The Output window opens and displays output similar to what you see in the following figure.

Output window showing results of building the HelloWorld project.

If the build output concludes with the statement BUILD SUCCESSFUL, congratulations! You have successfully compiled your program!

If the build output concludes with the statement BUILD FAILED, you probably have a syntax error in your code. Errors are reported in the Output window as hyper-linked text. You double-click such a hyper-link to navigate to the source of an error. You can then fix the error and once again choose Build > Build Main Project.

When you build the project, the bytecode file HelloWorldApp.class is generated. You can see where the new file is generated by opening the Files window and expanding the Hello World App/build/classes/helloworldapp node as shown in the following figure.

Files window, showing the generated .class file.

Now that you have built the project, you can run your program.

Running the Program

From the IDE's menu bar, choose Run > Run Main Project.

The next figure shows what you should now see.

The program prints Hello World! to the Output window (along with other output from the build script).

Congratulations! Your program works!

You now know how to accomplish some of the most common programming tasks in the IDE.



Next Steps

For a broader introduction to useful IDE features that are generally applicable to all kinds of application development, see Introduction to Developing General Java Applications.

To find information specific to the kind of applications your are developing, use the NetBeans IDE learning trail for that type of application. Each learning trail contains a series of tutorials and guides that range in scope from basic to advanced. The following learning trails are available:


↑返回目录
前一篇: Performing Inserts, Updates, and Deletes
后一篇: Meet a NetBeans Module Writer: Tonny Kohar