Home CPSC 220

Using Netbeans

 

Overview

This lab gives directions on using Netbeans, the development environment that we will use for this course. Netbeans is installed on the computers in the B12 computer lab and can be found in the start menu.

Netbeans is free and works on multiple operating systems. If you'd like to install it on your own computer, please see directions here.


 

Making a Project

With Netbeans, to write a program, you need to create a "project".

  1. Choose "New Project" from the File menu.
  2. Choose "Java Application" as the type of project to create.
  3. Enter a name and location for your project. When working in the lab, I'd recommend storing the projects on a thumb drive if you want to continue working at home.
  4. Be sure that the checkbox "Create Main Class" is checked, but remove the text before the period, and the period itself. For instance, if you call the project "Lab1", change the class name from "lab1.Lab1" to just "Lab1".
  5. Click "Finish".

You should now see your program open. Netbeans fills in an empty class and main function. Feel free to delete the comments it gives you by default.


 

Editing Code

Netbeans includes highlighting of Java key words, and automatically indents for you. It will also prompt you in certain cases. For instance, if you type "System.", it will pull up a list of the options which are legal after that.

Write the following inside the main function:


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

 

Running

Now we can run our program. Click the "Run Project" option under the "Run" menu. This can also be done by hitting the "F6" key by default.

You should see the output window at the bottom say "Hello world!" in it.


 

When Things Go Wrong

Sometimes, of course, there will be errors in our programs and the run will fail. To see this, try deleting the "}" line at the end of the program.

If you try to run it now, it will give you an error message.

You will need to fix the error in order to run the program.


 

Assignment

To get credit for this lab, you should change the hello world program so that it prints "Hello" followed by your name.

Then email the .java file as an attachment to ifinlay@umw.edu. You will need to remember where on your computer you created the project to attach the file.

Copyright © 2024 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.