Technology
http://www.bratandblekning.com Top Blogs Netbeans ~ JAVA TUTORIAL

Netbeans

Software or ResourceVersion Required
NetBeans IDEversion 7.2 or 7.3
Java Development Kit (JDK)version 6 or version 7

Setting Up the Project


To create an IDE project:

Start NetBeans IDE.

In the IDE, choose File > New Project (Ctrl-Shift-N), as shown in the figure below.


  1. NetBeans IDE with the File > New Project menu item selected.
  2. In the New Project wizard, expand the Java category and select Java Application as shown in the figure. Now click Next.
    New Project wizard: Choose Project
  3. In the Name and Location page of the wizard, do the following (as shown in the figure below):
  4. Type HelloWorldApp in the Project Name field.
  5. You should leave the Use Dedicated Folder for Storing Libraries checkbox unselected.
  6. In the Create Main Class field, type helloworldapp.HelloWorldApp.
    New Project wizard: Name and Location
  7. Click Finish.                                                                                                                                                         The project is created and opened in the IDE. Now you should see the following components:                                                                                                                          See, 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. Now open the Source Editor window with a file called HelloWorldApp.
NetBeans IDE with the HelloWorldApp project open.

Add Code to the Source File


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

            

with the line:

            System.out.println("Hello World!");

        

Save the change by choosing File > Save.

This file can be look something like the following code sample.

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */


package helloworldapp;


/**

 *

 * @author <your name>

 */

public class HelloWorldApp {


    /**

     * @param args the command line args

     */

    public static void main(String[] args) {

            System.out.println("Hello World!");

    }


}


        


Compiling and Running the Program


Because of the IDE's Compile on Save feature, so you dont have to manually compile your project in order to run it in the IDE. When you save a source file, the IDE automatically compiles it.

The Compile on Save feature can be turned off in the Project Properties window. Now Right-click your project, select Properties.

Now In the Properties window, choose the Compiling tab. And the Compile on Save checkbox is right at the top. See  in the Project Properties window you can configure numerous settings for your project: project libraries, packaging and building, running, etc.

To run the program:

Choose Run > Run Project (F6).

 you should now see as shown next.

The program prints Hello World! to the Output window (along with other output from the build script).
Congratulations! Your program works!
If there are compilation errors, then they are marked with red glyphs in the left and right margins of the Source Editor. And the glyphs in the left margin indicate errors for the corresponding lines. Now the glyphs in the right margin show all of the areas of the file that consists of  errors, including errors in invisible lines . You can mouse over(hover) an error mark to get a description of the error. 

Building and Deploying the Application

Once you have written and test run your application, then you can use the Clean and Build command to build your application for deployment. So when you use the Clean and Build command, then the IDE runs a build script that performs the following tasks:
Deletes any of the previously compiled files and other build outputs.
Recompiles the app and builds a JAR file containing the compiled files.
To build your application:
Choose Run > Clean and Build Project (Shift-F11)
You can view the build outputs by opening the Files window and expanding the HelloWorldApp node. The compiled bytecode file HelloWorldApp.class is within the build/classes/helloworldapp subnode. A deployable JAR file that contains the HelloWorldApp.class is within the dist node.
Image showing the Files window with the nodes for the HelloWorldApp expanded to show the contents of the build and dist subnodes.




1 comment:

  1. Thanks for sharing a really needed post that i am looking for , if anyone looking for best java institute in delhi so join with us visit our website : https://www.htsindia.com/java-training-courses or contact us : +91-9311002620

    ReplyDelete