Espresso: A Concentrated Introduction to Java
Summary: We describe how to compile and use Java in the Grinnell College Mathematics Local Area Network (MathLAN).
Prerequisites: Unix basics. Java basics. Java packages.
Disclaimer: Although I use the term Unix
throughout this document, the ideas apply equally well to Linux
, the variant of Unix we use in MathLAN.
Contents:
For the purposes of these exercises, you will find it most convenient
to have one class per file. (As we will soon see, if you make changes
to one class, this limits the amount of extra work the computer must
do to incorporate changes.) The name of the file must match the name
of the class. It must also end with the suffix .java.
For example, if I created a class named First, it would
go in the file First.java.
Java requires a two-step process for you to run your programs. First,
you must convert all of your .java files to .class
files. (The term for this conversion is compilation.) Next,
you must tell Java which class is your main class. (It turns out that
it is sometimes convenient to have more than one main class.)
Compilation is fairly straightforward. Make sure your present working
directory is the one that contains your .java files. Then,
for each file, execute the command
/opt/jdk1.5.0/bin/javac File.java
Given that the command is overly long, you may want to add an alias
to your .bashrc file.
alias jc='/opt/jdk1.5.0/bin/javac'
You tell Java to run the program by using the java command.
/opt/jdk1.5.0/bin/java MainClass
You must use the fully qualified name for the class. For example, if
First is in package rebelsky.sample, we
would refer to it as rebelsky.sample.First.
Note that you do not use the .class suffix for this
command.
Again, you will find it convenient to create an alias for this command.
Sunday, 30 January 2005 [Samuel A. Rebelsky]
Tuesday, 30 August 2005 [Samuel A. Rebelsky]
This page was generated by
Siteweaver on Thu Mar 30 15:24:27 2006.
The source to the page was last modified on Tue Aug 30 10:51:49 2005.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Espresso/Readings/mathlan.html.
You may wish to
validate this page's HTML
;
;
Check with Bobby