[Homepage] |
[Next: How to Create Output] |
[Up: Editing, Compiling, & Running] |
[Prev: Compiling a Program]
Running a Program
After you have "compiled" your program, you run it using the Java Virtual
Machine which is called simply, "java".
For example, if I compiled my ``Hello.java'' program using the command
``javac Hello.java'', I would type ``java Hello'' at the UNIX prompt to run my
program. Notice that it is not "java Hello.java" or "java Hello.class".
Sometimes it is important to have a copy of your program or its output
on paper. Either because it's easier to take your program home this
way, or simply because the TA or Instructor want you to do so. In a
UNIX environment, you'll need to use the ``lpr'' command for that. But
you need to ask the lab consultant what is the printer closest to the
lab you're working at.
If you want to print a program called ``MyProgram.java'', the command
to be used is ``lpr -h -P <printer_name> MyProgram.java'' where
- ``-h'' supresses the printing of a header page (saves paper).
- ``-P <printer_name>'' is the name of the closest printer.
- ``myProgram.c'' is the file you wish to print.
Your file is placed in a queue of files to be printed. Please,
bring your printer card... The university charges you a small
amount for each page printed.
Ewerton L. Madruga
Modified by Kevin Klenk