ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software

Netbeans Introduction: Create your first Java Program Using NetBeans

Updated on August 28, 2011

NetBeans is an Integrated Development Environment, or IDE, provided free of charge by Sun Microsystems. It's primarily intended for developing software applications in Java, but its' capabilities extend well beyond coding and well beyond Java. It provides design tools, support for other languages, and even a CVS client.

You can get Netbeans (it's free) here: http://www.netbeans.org/downloads/index.html

This tutorial explains how to use NetBeans to create your first Java program.

Step 1 - Create a New Project in NetBeans
Step 1 - Create a New Project in NetBeans

Step 1

Start NetBeans.
Click File / New Project.

The New Project Dialog will appear

Step 2

From Categories, select Java.
From Projects, select Java Application.
Click Next.


Step 2 - Select the Project Type
Step 2 - Select the Project Type

Step 3

Give the project a descriptive name. Don't fall into the nasty habit of accepting the default name.
Note where it is stored so you can retrieve it later.
Change the case-ing of the class name if you like. Camel-humped naming is preferable.

Click Finish.

Step 3 - Name the Project, click Finish
Step 3 - Name the Project, click Finish

Step 4

Your project will look something like the Step 4 screen shot, below.
Note the TODO; replace it with this code:

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

Be careful; Java is case sensitive. Any variable name, class name, method name, keyword and almost everything else that's not in quotes is case sensitive.

If anything you type appears with a sqiggle beneath it, you may have made a typing error.

Step 4 - Add some code in place of the TODO
Step 4 - Add some code in place of the TODO

Step 5

Click the Green Arrow on the Tool Bar at the top of the window.
Unless you made a typing error, Your project will build and execute.
Note the output in the Output Window at the bottom of the window.

Step 5 - Run the project and note the text in the Output Window
Step 5 - Run the project and note the text in the Output Window

Step 6

Now you will add a class to your project.
Look for the Projects Window at the upper left of the IDE.

Right-Click on the HelloWorld project and select New / Java Class.

Step 6 - Add an empty class to the project
Step 6 - Add an empty class to the project

Step 7

Fill in the name of the new class. In this example it’s called myNewClass.
Select the HelloWorld package from the package drop-down.
Click Finish.

Step 7 - Name the new class
Step 7 - Name the new class

Step 8

Your IDE should look something like this.
Create a method in the class; add the following code.

public void Hello() { 
     System.out.print("Hello from myNewClass");
}

Be careful; Java is case sensitive. Also be sure the method is contained in the class.

Step 8 - Add code to the new class
Step 8 - Add code to the new class

Step 9

Add an instance of the new class to the main( ) and call the method in the new class;
Type the following code:

      
myNewClass myNew = new myNewClass();
myNew.Hello();

Your code should look something like this.

Step 9 - Modify the main() to use the new class
Step 9 - Modify the main() to use the new class

Step Last

Click the Green Arrow on the Tool Bar at the top of the window.

Your project will build and execute.

Note the output in the Output Window at the bottom of the window.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      buvi 5 years ago

      Thanks a lot.This is very useful to me.

    • profile image

      @gavin 6 years ago

      thanx all clean,

      and free,

      nice topic for a start ;-)

    • nicomp profile image
      Author

      nicomp really 6 years ago from Ohio, USA

      @Shefali Lachhar : Thanks!

    • profile image

      Shefali Lachhar 6 years ago

      thanks for sharing d topic...it gave me a gud start :)

    • profile image

      chikkku 6 years ago

      Superb

    • profile image

      vinya 6 years ago

      thanx for the useful tips.........

    • profile image

      Sherry Ann Marie  6 years ago

      I really appreciate the documentation regarding on how to use Netbeans in doing java applications..thanks a lot!

    • profile image

      vijay 8 years ago

      good but how can i create tools in netbeans

    • nicomp profile image
      Author

      nicomp really 8 years ago from Ohio, USA

      Thanks, I agree. And it's free!

    • brad4l profile image

      brad4l 8 years ago from USA

      I think Netbeans is overall a great IDE. After working with it awhile, I do find some of the interface to be a little clumsy, but it is really easy to use and best of all, cross platform :)