NetBeans IDE Java Quick Start Tutorial
NetBeans IDE Java Quick Start Tutorial
Welcome to NetBeans IDE! 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 and run applications in the IDE. This tutorial takes less than 10 minutes to comple te. After you finish this tutorial, you can move on to the learning trails, which are linked from the Documentation, Training & Support page. The learning trails provide comprehensive tutorials that highlight a wider range of IDE features and programming techniques for a variety of application types. If you do not want to do a "Hello World" application, you can skip this tutorial and jump straight to the learning trails. Contents
Setting Up the Project Adding C ode to the Generated Source File C ompiling and Running the Application Building and Deploying the Application Next Steps To complete this tutorial, you need the following software and resources. Software or Resource Version Required
NetBeans IDE
3.
In the New Project wizard, expand the Java category and select Java Application as shown in the figure below. Then click Next.
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 HelloWorldApp . Leave the Use Dedicated Folder for Storing Libraries checkbox unselected. In the C reate Main C lass field, type helloworldapp.HelloWorldApp . Leave the Set as Main Project checkbox selected.
o o o o
5.
C lick Finish.
The project is created and opened in the IDE. You should see the following components:
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. The Tasks window, which lists compila tion errors as well other tasks that are marked with keywords such as XXX and TODO.
Save the change by choosing File > Save. The file should 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 arguments */ public static void main(String[] args) { System.out.println("Hello World!"); } }
C hoose Run > Run Main Project (F6). The next figure shows what you should now see.
C ongratulations! Your program works! If there are compilation errors, they are marked with red glyphs in the left and right margins of the Source Editor. The glyphs in the lef t margin indicate errors for the correspondin g lines. The glyphs in the right margin show all of the areas of the file that have errors, including errors in lines that are not visible. You can mouse over an error mark to get a description of the error. You can click a glyph in the right margin to jum p to the line with the error.
Once you have written and test run your application, you can use the C lean and Build command to build your application for deployment. When you use the C lean and Build command, the IDE ru ns a build script that performs the following tasks:
Deletes any previously compiled files and other build outputs. Recompiles the application and builds a JAR file containing the compiled files. To build your application: C hoose Run > C lean and Build Main 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.
For information on how to run the application from the command line for your operating system, see the "The "Hello World" Applica tion" lesson of the Java Tutorials. Send Feedback on This Tutorial
Next Steps
You now know how to accomplish some of the most common programming tasks in the I DE. To learn more about the IDE workflow for developing Java applications, including classpath management, see Developing General Java Applications. For more information on deploying Java desktop applications, see Packaging and Distributing Java Desktop Applications.