cd csci
mkdir 273.002
cd 273.002
mkdir labs
mkdir homework
cd labs
If necessary, get help from your instructor for these steps.
Later you may also want to consult our summary help page on
Linux
Terminal Commands.
But don't worry, you should not have to go through these
particular steps again
for the remainder of this semester...
When the smoke has cleared, note that you have just created a new directory (folder) named 273.002 in your prexisting csci directory. And in 273.002 itself, you now have two new folders: one to hold your lab projects, and one for your homework. The path from your login (home) directory to your lab directory is just csci/273.002/labs. From now on, be sure to create all your lab project folders in csci/273.002/labs.
cd csci/273.002/labs
You may also find it useful to know that the command
cd
returns you to directly back into your home directory (this works
with Unix/Linux systems, but unfortunately not with Windows command
prompts).
So now that you are in your labs directory, launch a simple text editor and use it to write your own version of a HelloWorld program in Java as described in your text. One available editor is called gedit, which you can launch with the command
gedit HelloWorld.java &
The little & at the end of the command is there so that you
can jump back and forth between the gedit window and the
terminal window as necessary (without it, your terminal window is
"locked up" until gedit terminates).
Note: several text editors are actually suitable to use for this step, including gedit, nano, and even vi. If you happen to have preferences here, just use your favorite editor. But please feel free to consult your lab instructor if you have any questions.
javac HelloWorld.java
If you get error messages, just jump back to your editor window,
fix the errors, save the file, jump back to the terminal window,
and repeat the javac command until all is well. At this stage
you should enter the ls (directory listing) terminal command
and look for two files, namely HelloWorld.java
and HelloWorld.class. The .class file is what the
compiler creates. It stores the sequence of bytecode
instructions representing your program, which can now be executed
by the Java Virtual Machine (JVM).
java HelloWorld
If all goes well, you should finally see the message that you specified in your program. If not, it's another good time to consult with your lab instructor...
In the Categories and Projects panes shown above, select Java and Java Application respectively and then click Next. This raises a second dialog with the title New Java Application, in which you are supposed to enter the name and location of your project. Enter Lab01 as the Project Name. and set the Project Location to csci/273.002/labs. Also, for this lab only, uncheck the Create Main Class checkbox:
Otherwise, accept the default settings and click Finish.
Now go to the NetBeans explorer window. Make sure that the Projects view is selected, open your Lab01 project, then open Source Packages, and look for <Default Package>. If you want to create a new Java class in the default package, just right-click on <Default Package> and select the type of class you want (for example, Java main class), and start editing. But first you should check out the next step...
Use your browser to access the Booksite, and download the java source files HelloWorld.java and UseArgument.java from Section 1.1 in your text. Be sure that both files end up in Lab01/src/.
Note that Lab01.jar contains only the bytecode (.class) files for the project classes, not the project source files. But you can still run any of the classes in your project from this JAR file, using only terminal commands such as the following:
cd ~/csci/273.002/labs/Lab01
java -cp dist/Lab01.jar HelloWorld
java -cp dist/Lab01.jar UseArgument Fred
It turns out to be convenient to use this approach when you want
to try any of the textbook demos that require command-line
arguments. In fact it is much more awkward to supply or change
these arguments through the NetBeans IDE. But by combining the
use of NetBeans with terminal commands, you have the benefit of
working with a powerful editor with many good debugging features,
plus a flexible way to supply and modify command-line arguments
to Java programs.
When your project is complete and working correctly, be sure to demonstrate it to your lab instructor. Then, before you exit NetBeans, clean your Lab01 project. This step removes all the .class files, but leaves all your project sources (.java files) intact. Finally, before you logout, open a terminal window and use the command
cd ~/csci/273.002/labs
to reset your default directory to csci/273.002/labs.
Then create a JAR file of your Lab01 project folder, using
the command
jar cf Lab01Project.jar Lab01Note that this JAR file differs from the Lab01.jar file that NetBeans creates when you build a project. Lab01Project.jar contains your entire Project "development" folder, including all your sources and NetBeans project management files. In fact you could upload this file to another system, extract its contents via the command
jar xf Lab01Project.jarand use NetBeans to continue working on it.
Please leave Lab01Project.jar in your csci/273.002/labs directory for the remainder of the semester.