LAB 1 (Comp 170)
Getting Started
1. If you do not already have an account on the departmental network,
then Mr. Miao Ye, our network technician,
has created a logon id and password for you as follows: logon
id: first initial + first 6 letters of your last name. (So
Alanis
Morissette would be amoriss, and Fiona
Apple would be fapple, since apple has
only 5 characters. However, Jack Smith may be jsmith99,
since perhaps many J. Smith's attend Loyola. If your name requires
a numerical suffix, then Miao has posted this information on the
lab bulletin board.) Your initial password is nabcdef
where
"abcdef" are the last six characters in your PID, which appears
on your schedule. (Thus if your PID were P000456789, then your initial
password is n456789.) When you first
logon, you will be asked to change your password. Choose a password
which you will easily remember. (The password is case-sensitive, so, for
example, "Lassie" is different from "laSSie")
If your account does not exist today, you may logon as "Guest",
with empty password.
2. Logon to Windows NT and briefly navigate Windows files and
menus. The drives (E:, F:, and H:) on the machine named "Turing"
should be automatically mapped, so you need not worry about this.
Your directory will reside in Turing (H:) /home/students/.
Create a subdirectory (folder) called myJavaProjects.
Ask your TA (Kevin Sindelar, Yevgeniya
Shteynberg) for help if you need it!
3. Launch Symantec Visual Café 3.0: From the Start
menu select Programs, then Programming tools, and then VCafe3.0.
4. Start a new project: The first time that you start VCafe,
a default project is already started. We would like to create our
own New Project. So, close the default new project (by clicking on
the X in the blue project pane title bar). There are several steps
necessary to create a new project. Each is important.
-
Create a subdirectory, helloWorld, of myJavaProjects. In
general, each new project should be saved in a separate directory.
-
In the File menu select New Project. Select an Empty
Project. A project window opens with a name starting with Untitled.
Change this name to HelloWorld as follows:
-
In the File menu, choose Save As. In the pop-up window, navigate
to your helloWorld folder and save as HelloWorld after the
"File Name:". The extension (i.e., suffix) ".vep" is
added automatically. After a brief wait, the project name will change.
-
We must be aware of the following "naming convention."
The project name, main source file name, and class with the main method
have the same name with the first character capitalized.
In our example, the directory name is helloWorld, but the project,
main source file and class are each named HelloWorld. If the
three names (project, main source file, class with main method) are not
the same, you will usually get an error message (except in special cases).
-
In the file menu, choose New File if you want to start with a blank
file or Open if you want to modify an existing file. Particularly
in the latter case, do not omit the next step:
-
In the file menu choose Save As, and enter the class name (HelloWorld).
This time the extension ".java" is added automatically. At this
point, the file will be added to the project if the Add to project
box in the lower left-hand corner of the SAVE AS window is checked.
-
In case the file was not added to the project in the previous step, you
can add the file to the project as follows: In the Project
menu, choose Add <HelloWorld.java>. Now the project "knows"
that your file is in it. Merely having the file open at the same
time the project is open is not enough. If you forget to add
the project, then you cannot compile your program.
-
Now you may start to edit. Remember that the class name should match
the file name and project.
5. Editing: In your HelloWorld.java file, type the following
program:
class HelloWorld{
//This is my very first Java program!
//Author: Jacob Dylan
//Date: May 24, 1999
public static void main (String[] args){
System.out.println("Bonjour");
// Here we print Bonjour.
System.out.println("Press enter to terminate program");
String junk = SavitchIn.readLine();
}
}
-
If there is a message pane on the screen, you do not need it while editing.
You can close it by clicking on its close button, an X. This provides
more space to see your program.
-
Basic word processing editing keys and mouse clicks work. Unlike
a word processor, however, the lines do not wrap around if they get long.
You need to press "enter" to break long lines where you want. The
editor also offers you assistance in maintaining appropriate indentation
in your program.
-
In a program, matching delimiters, " ", { }, ( ), [ ], /* */ are
very important. The editor assists you in a clever way: when
you type the second of any of these pairs, the cursor jumps briefly to
the matching delimiter, so you can check that the match is correct.
You can manually check the match by placing the cursor before a paired
delimiter and pressing Ctrl-] to make the cursor jump to the corresponding
delimiter. You can get back by pressing Ctrl-] again.
-
Braces { } are particularly important. The line after an opening
brace is automatically indented as you type. If you insert a closing
brace at the start of a line, the editor automatically makes it line up
under the beginning of the line containing the matching opening brace.
6. Saving:
-
You can save the active window in the usual Windows ways: in the
file menu or with the floppy disk icon in the toolbar under the menus.
Your file is automatically saved before you compile or run your program.
-
The default options also save your altered files every 10 minutes automatically
in case of a crash (which can happen). To recover your saved
files from the directory c:\temp, see the VCafe Help topic with
index entry: "saving, backup files for recovery".
7. Adding SavitchIn.java to the project:
In this program (and most future programs in this course) we use a pre-written
class called SavitchIn which is saved in a file called SavitchIn.java.
This file is on your CD (accompanying your text) and is also stored on
the E drive at: E:\java\classes\savitch\ch01\SavitchIn.java.
Please open this file and add it to your project. If you forget
to add this file to your project then you will see an error message at
the time that your program in compiled indicating that SavitchIn cannot
be found.
8. Compiling:
-
In the Project menu, choose Build Application.
You will see in the status line at the bottom left of the screen what happened:
"Build Successful" or "Build Failed" along with warnings and error messages.
Examine your message window for a complete listing of errors.
-
See the bottom of the Search menu for ways to jump to the location
of errors in the source code, and note the keyboard shortcuts, such as
Alt-s,x
to take you to the next error. Then the offending source line is
highlighted in red, the cursor moves to the line, and the current error
description appears at the bottom of the source frame. Correct the
error and press Alt-s,x to go on to the next error.
Alternatively,
you may double click on the error in the message pane and the cursor will
move to the offending source line.
8. Running:
-
Choose Execute from the Project menu.
-
Running glitch: If you execute a console text application
(one that prints using System.out), you are unlikely to see your last output,
because the console window disappears. This would be true if your
main
method were:
public
static void main (String[] args){
System.out.println("Bonjour");
}
One fix is to change it as
follows:
public static void main (String[] args){
System.out.println("Bonjour");
System.out.println("Press enter to terminate program");
String junk = SavitchIn.readLine();
}
Then when the program is run, it waits at the end, until
you enter a carriage return.
9. Opening an old project:
-
Open the File menu. It is easiest to select from the recent files
or recent projects in the bottom of the menu. Otherwise, you can
select Open project, and select the project in the file opening dialog
window.
10. Opening an existing source file in an open project:
-
Sometimes a source file is in the project but does not pop up when you
want it. Select the last tab in the Project window pane, which looks
like a page of text. This refers to the source files. You should
see the list of files in the project. Click on the desired file,
and it should become visible.
11. Consult the Help menu inside Visual Café for much broader
and more detailed information.
EXERCISES:
(A) Create a project, which prints a message such as "I
think that I am really going to love Comp 170".
What is an appropriate name for this project? Compile and run
it.
(B) Create a project, VirusWarning, which prints the following
message:
----------------------------------
|
|
|
W A R N I N G
|
| Possible virus detected!
|
| Reboot and run virus
|
| remover
software.
|
|
|
----------------------------------
(C) Re-examine your helloWorld project. What
happens if you:
-
replace the first occurrence of println
with printline?
-
remove the semi-colon after ("Bonjour") ?
-
remove the first brace, { ?
-
omit public
?
-
omit static
?
-
omit void
?
-
remove the line String
junk = SavitchIn.readLine();
?
-
remove //
from any one of the comments ?
-
remove the quotation marks surrounding Bonjour
?
(D) Run Program 1 of chapter 1: First create a new project
(in a new folder); then add FirstProgram.java
(found at E:\java\classes\savitch\ch01\FirstProgram.java
and SavitchIn.java to your project.
(E) Create a new project, HelloWorld2
(saved in a new folder, helloWorld2). Open
the HelloWorld.java file which you worked
on earlier, and save it under the new name HelloWorld2.java
in
the folder helloWorld2. Modify
this file so that it also announces today's weather in Chicago. Change
the class name to HelloWorld2, and add this
file to your new project, HelloWorld2.
Run this project. (What happens if you forget to change the class
name?)
(F) Try saving your file HelloWorld.java
file to a floppy. Then make sure that this .java
file is actually on your floppy by reading the directory of .java
files on the A: drive.
Course
Home Page
Department
Home Page
Loyola
Home Page