In this lab, we're going to look at the problems of file transfer. Pay attention. This information will be helpful in verifying that you have your files in the right places.
The most common reason that file transfer fails is procrastination. If you begin writing your program two days before it is due, you probably will not transfer, or even complete, the assignment on time.
When assignments are given, you will explicitly be given
(1), the name of a NetBeans project,
(2), the name of a Java package,
and (3) the name of a class (or classes) for your program.
For example,
Homework #1 of the Fall 2007 semester specifies
Homework1
as the project name,
homework1
as the package name,
and Main
as the class name.
In general, the names for the project, package, and classes will be
chosen so that
if you create the project with the right name
and then choose the
defaults for the package and class names, all three names will be correct.
The package and class names are usually set when you go
through NetBeans' New Project...
or New File... "wizards".
In the New Java Application window,
the class and package are both set in a single text field labeled
Create
Main class as packagename.ClassName
.
For example, the following picture
shows the default
package name homeworkx
and default class name Main
for a Java Application in
the HomeworkX
project.
The Java convention is that package names contain only lower-case
letters and class names start with an upper-case letter.
NetBeans follows this convention.
The best test for verifying that you have the right package and class name is to look at your program code. The package name should be specified by a line, similar to the following, at the beginning of your program.
package packagename ;
The class name should quickly follow.
public class ClassName {
Always look at these two lines to verify you have the correct package and class names.
If you are going to to write your program on your "home" computer, you are going to need to transfer the file containing your program to the UNCA Computer Science server. Before you do that, you're going to have to find the file. We're going to show you how to do this by using NetBeans.
We're going to assume that Main
is the expected Java class name
for the assignment. This means that a file name
Main.java will contain your code.
We also going to assume that
HomeworkX
is the assigned project name and
that homeworkx
(HomeworkX
in lower-case) is the assigned package name.
If you are using a Windows XP system at home, your project is probably in the directory C:\Documents and Setting\yourid\HomeworkX. In Windows Vista, it's probably C:\Users\yourid\HomeworkX; and in Mac OS X, /Users/yourid/HomeworkX.
In NetBeans, your program files are not stored directly in your project folder. Rather they are within a subfolder named after your package which is in turn stored in a subfolder named src of your project folder. In Vista this would be C:\Users\yourid\HomeworkX\src\homeworkx.
But, yes, there is an easier way.
To find where your program is stored,
start up NetBeans,
open your project,
and right-click on the name of your program within the
Projects tab.
This will bring up a properties window for your program.
The All Files field
gives the name of the file where your project is stored.
In the case below, this is
C:\Users\yourid\HomeworkX\src\homeworkx\Main.java.
We have determined the name of our file. In our example, it is Main.java within the C:\Users\yourid\HomeworkX\src\homeworkx folder. Admittedly there's a bit of a chicken-and-egg problem here. How can you open a project if you don't know the name of the project folder? You will be given a list of recently opened NetBeans projects when you start NetBeans. Hopefully your project will be one of these.
You can also significantly reduce the probability of "losing" a project by storing all your projects in one directory, like csci/201 in Linux.
Start up NetBeans, open any project, and then show your instructor the properties window for a Java file within that project.
We have an on-line tutorial Copying your code with WinSCP for students who want to copy their programs from their home Windows computer to the UNCA CSCI Linux system.