This lab will tell you how to ship NetBeans and Java files between computers. This information will be useful when you need to turn in a program.

The goals of this lab are to:

  1. Export a NetBeans project to a single file
  2. Import a NetBeans project stored within a single file
  3. Download and open a project for a lab
  4. Transfer a single file with FTP

Exporting NetBeans

Information regarding your project is contained in special XML, Extensible Markup Language, files stored within your project directory. These XML files really aren't intended to be read or written by human beings, but they do follow a well known standard called Ant for automating the tasks of managing large collections of classes. The development of Ant is guided by the folks at the Apache Software Foundation, who also steer the development of the popular Apache web server.

By conforming to the Ant standard, NetBeans enables its projects to be deployed on a wide range of platforms. But the interesting question from you might be: Can I take my project home for Christmas?

The answer is: Yes, but you must be careful. About the only universal tool for transmitting a collection of files between Linux and Windows (and between Windows and Windows) is ZIP, a tool invented in 1986.

In spite of its widespread usage, ZIP enjoys one-way acceptance in the Windows world. Out-of-the-box Windows XP can extract a collection of files from a single ZIP archive, but it cannot archive a collection of files into an archive. However, you can download many Windows programs, such as WinZip, PKZIP, and 7-Zip, that will archive for you.

Exporting on Linux

Take a quick look at all the files that compose a NetBeans project by pressing on the Files tab. Now press on those little turnstiles on the left side of the Files panel to expand the directories. At this point there are about ten files stored in eight different directories for a Java program that prints a single line.
NetBeans files

How do you get all these files into a single archive? We're going to start by cleaning the project to remove the build and distribution files.  Cleaning is easy, just return to the Projects panel and right-click on the name of your project. This will bring up a menu from which you can select Clean Project. Job is done. By the way, all of the projects you download from the CSCI 201 web pages have been cleaned.
cleaning a project

Creating an archive ZIP file on Linux requires the use of a command line utility, so return to your command line processor (possibly for the last time in a CSCI 201 lab).

Remember that your project folder is under your csci/201 directory. So you must first connect there. Then type the command ls -R lincoln. You should see many files.

[yourid@yourmach currentdir] cd ~/csci/201
[yourid@yourmach 201] ls -R lincoln

There are a few files of interest here. For you the more important is lincoln/src/lincoln.java which contains your Java code. If you were submitting this file for an assignment, you'd submit the file lincoln.java contained within your csci/201/lincoln/src directory.

Let's get back to the task of creating a ZIP file containing your NetBeans project. That's easy. It can be done with one command:

[yourid@yourmach 201] zip -r lincoln.zip lincoln

This command will place your entire project into a single file lincoln.zip which can be transferred to almost any another computer.

Go ahead and ZIP your project. Show your instructor your success by executing the following command to list the files within your ZIP archive.

[yourid@yourmach currentdir] unzip -l ~/csci/201/lincoln.zip

Downloading a project

Retrieving starter projects

There is a Linux program called the file-roller that can expand all sorts of archived files. It is very easy to use. In CSCI 201 labs incomplete or buggy projects will be distributed in ZIPed archives. You'll use file-roller to store these projects in your csci/201 directory.

Unrolling a project

The starter project for your next task is archived in fixit.zip. Press the link to start the download.

Soon you should see a window entitled Opening fixit.zip. If its asks you if you wish to use file-roller, agree. However, it will probably inform you that it "does not know how to handle this file type." You must correct this problem. Tell Mozilla that it is supposed to use the program /usr/bin/file-roller to open ZIP files!
Use file-roller!

After you press OK, the file-roller starts with a simple window that shows you that the ZIP archive contains a single folder called fixit. All CSCI 201 archives will contain only one folder.
Initial file-roller window

You need to press the Extract icon to bring up the Extract window. Within the Extract  window you must navigate to your csci/201 directory before your press the OK button.
 

When you return to the Extract window, it is very important that you check the box Recreate folders before proceeding. Also, verify that you have your csci/201 directory selected as the Destination folder.
final file-roller extract dialog

Call your lab instructor over to see the state of your Extract window. If the instructor approves, you can then press the OK button of the Extract window. The files are extracted without fanfare. You return to the fixit.zip - File Roller window which can now be closed.

Opening the Project

Home at last

At this point the downloaded project is stored on your computer and you should be able to view it with NetBeans.

NetBeans Open Project dialog

Use the menu sequence File → Open Project... to bring up a Open Project dialog window. From there navigate to your csci/201 directory where you should find an entry for the fixit project. Click once on fixit and then select Open Project Folder.
Open Project dialog

Cleaning up the project panel

At this point, you probably have at least two projects displayed in your project panel. We really don't want old CSCI 201 projects cluttering our view as we move on to new projects; so, for every project other than fixit, right-click on the project's name and then close it. You should end up with only fixit in your list of projects.

Opening the Java file

Click on the expanders (turnstiles) next to fixit then Source Packages and finally <default package>. Now you should see an entry for fixit.java. Click on that entry to bring up a window displaying the Java code for the fixit class.
Panels with fixit.java

Show the lab instructor that you have downloaded the fixit project and opened the fixit.java file.

Checkpoint

Answer the questions below. You have to answer all questions correctly to see the rest of the lab.

What is NetBeans?
an editor
a compiler
a debugger
all of the above and more, an Integrated Development Environment

What is the purpose of creating a GNOME launcher for NetBeans?
to compile your programs
to quickly and easily start NetBeans
to logon to Linux
to exit Linux

Errors in your program

Syntatic and semantic errors

Not everything that looks like a Java program is a Java program. Java programs must follow some rules. Some rules are syntatic. They are concerned with braces and semicolons. They are similar to English rules regarding the placement of punctuation. Here are a couple of important Java syntatic rules.

  1. All statements in java must end in a semicolon.
  2. Brackets, such as "{}", are used to break a program into functional units which may be nested. Each opening bracket, "{", must have a matching closing bracket, "}".

Java programs must also follow some semantic rules. These are a little harder to explain. The semantic rules govern the meaning of "names" in Java. Java can be very picky about its semantic rules. For example, Java names are case-sensitive: System is the name of an important Java package; system,  and SYSTEM are not.

Finding and correcting errors with NetBeans

If you look at the window containing fixit.java, you'll see two little red boxes containing cross marks. Each of these boxes mark a Java programming error. If you place your mouse on a box, you'll be rewarded with a message displaying the cause of the error.

For example, the first error occurs because this Java statement does not end with an semicolon.
';' expected
The second error occurs because there is a missing right curly brace. '}' expected
Go ahead and fix these two syntatic errors.

Yes, as soon as you fix those two errors a third one shows up. This is a semantic error. System is misspelled.
package system does not exist
Correct this error and the boxes go away.

Build your fixit class and show the instructor your successful compile.