GETTING STARTED WITH JAVA (DOS)
Mtht 420
This is the unix version (for use when connected to icarus by telnet
or ssh from a lab computer or from home.)
Before sitting down to type in, compile, and test a program you
should have:
- A written copy of the program you wish to type in,
- Your userid and password on icarus,
- A computer connected to the internet (a UIC lab machine, a home
computer with a modem and UIC's network services kit, or a home
computer and an account with some other internet service provider), and
- A working copy of the Telnet program.
When you are ready to enter your program into the computer, telnet to icarus and do the
following:
- Log on using your userid and password.
- Decide where you want the files you create to reside and change
to that directory using the cd command. If you do nothing,
all files will be created in the top level of your home directory,
which is OK.
- Type pico Welcome.java to create a file named
Welcome.java containing your code. Type in your program or applet --
the sample applet in section 1.16 of Deitel
and Deitel is a good applet to start with. (There are many ways to
create and edit a file. If you prefer another editor which can create
compilable plain text files, feel free to use it. Be warned that you
may not be able to get help in class if it fails to work.) Save your
work and quit the editor when you are done.
- Type /usr/local/java/jdk1.1.4/bin/javac Welcome.java to
compile your program or applet. If the compilation is successful (no
error messages), typing ls should show you two files:
Welcome.java and Welcome.class.
- At this point, you have typed in some Java code and compiled it.
The next step is to try running it. Running a Java program is
different from running an applet.
- You can run a compiled program by
typing, for example, /usr/local/java/jdk1.1.4/bin/java Hello.
Most examples provided by Dr. Burgiel or Professor Larson will be
programs.
- Most examples given by Deitel and Deitel are applets. Applets
run on web pages, and generally have fancier user interfaces. To run
an applet, you first first create an HTML document inside which your
applet will run. You can do this by typing pico Welcome.html
and entering code similar to that in Figure
1.3 of Deitel an Deitel. Save your work and quit the editor when
you are done. Then run your applet by loading the web page into a
java capable browser. For example, type
/usr/local/java/jdk1.1.4/bin/appletviewer Welcome.html.
(Note: if your web page and Java files are inside the public_html
directory on your icarus account, the web page running the applet will
be publically available. We will go over this in class later.)
- Test your applet or program to see if it does what you want it to
do. Edit your code (pico Welcome.java), save, compile, and
run (you do not need to create a new html file unless you change the
name of your program) until it does what it's supposed to.
- Back up your work by printing it out, ftp'ing it to your home
computer, ftp'ing it to a lab computer and saving it to diskette, or
emailing it to a non-UIC account of yours.
- Type "logout" to close your connection to icarus.
For experts: you can avoid always having to type
/usr/local/java/jdk1.1.4/bin if you add it to your
path -- your path is the list of locations the computer looks
through when interpreting the commands you give at the prompt. (Type
echo $PATH to find out what your path is.) To add
/usr/local/java/jdk1.1.4/bin to your path, edit your .profile file
(pico .profile) and add /usr/local/java/jdk1.1.4/bin
to the list of things in your path. Your .profile file should end up
containing a line like:
export PATH=$HOME:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/opt/SUNWspro/bin:/usr/ucb:/usr/bin/X11:/sbin:/usr/openwin/bin:/usr/local/java/jdk1.1.4/bin:.
Once you have done this, you can simply type javac Hello.java
to compile a program.
Mtht 420