How to run an application on NetBeans IDE.
To write your first program, you'll need:
- The Java SE Development Kit 6 (JDK 6)
- For Microsoft Windows, Solaris OS, and Linux: http://java.sun.com/javase/6/download.jsp
- For Mac OS X: http://connect.apple.com
- The NetBeans IDE
- For all platforms: http://www.netbeans.info/downloads/index.php
Create an IDE Project
To create an IDE project:- Launch the NetBeans IDE.
- On Microsoft Windows systems, you can use the NetBeans IDE item in the Start menu.
- On Solaris OS and Linux systems, you execute the IDE launcher script by navigating to the IDE's
bin
directory and typing./netbeans.
- On Mac OS X systems, click the NetBeans IDE application icon.
- In the NetBeans IDE, choose File | New Project.
- In the New Project wizard, expand the General category and select Java Application.
- In the Name and Location page of the wizard, do the following:
- 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.
- Click Finish.
- The Projects window, which contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on.
- The Source Editor window with a file called
HelloWorldApp
open. - The Navigator window, which you can use to quickly navigate between elements within the selected class.
Add Code to the Generated Source File
When you created this project, you left the Create Main Class checkbox selected in the New Project wizard. The IDE has therefore 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!"); // Display the string.
Optionally, you can replace these four lines of generated code:
/**
*
* @author
*/
With these lines:
/**
* The HelloWorldApp class implements an application that
* Simply prints "Hello World!" to standard output.
*/
These four lines are a code comment and do not affect how the program runs
Save your changes by choosing File | Save.
/*
* HelloWorldApp.java
*
* Created on February 5, 2011, 6:43 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 prints "Hello World!" to 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) {
System.out.println("Hello World!"); // Display the string.
}
}
Compile the Source File into a .class File
To compile your source file, choose Build | Build Main Project from the IDE's main menu.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
nodeNow that you have built the project, you can run your program.
Run the Program
From the IDE's menu bar, choose Run | Run Main Project.
No comments:
Post a Comment