Sun Microsystem's Java language has shaken the computer industry.
Since March, 1997, over one million copies of the JDK 1.1 have
been downloaded from JavaSoft's Web site. Java found a niche as
a Web development tool, and now strives to be the development
language of the 21st century. One great aspect of the Java
language is that sophist
icated development tools are available
for anyone to download and use. Fortunately, for Linux users,
the Java Development Kit (JDK), Version 1.1 is ready to roll.

Questions regarding this article should be directed to the
author at
jc_cann@ix.netcom.com

This is a tutorial article about locating, installing, and
using the Java Development Kit (JDK) on Linux. It is intended
for Linux developers; however, many aspects discussed are
directly applicable to other Unix operating systems. You should
have experience using development tools and some Linux system
administra
tion.

Javasoft, the spin-off company of Sun Microsystems, Inc., has
produced the JDK to run only on Solaris, Microsoft Windows (32-bit
release), and Macintosh operating systems. Javasoft has left the
porting work up to licensees who obtain the JDK specifications
from Javasoft. The Blackdown Organization is responsible for the
JDK port to Linux.

The
Blackdown Organization
started as an Internet service provider that currently houses the
java-linux mailing lists and JDK/Linux archives. They provide the
``official'' port of Javasoft's JDK for Linux. The initial
porting work was performed by Karl Asha, founder of the Blackdown
organization. He continues to provide support and bug fixes for
the JDK, in addition to maintenance of the Blackdown Web
site. There have been many contributors to the JDK Linux port,
most recently Randy Chapman and now Steve Byrne.

Information about the JDK for Lin
ux may be found at
Blackdown's
Java Linux Page
(<URL:http://www.blackdown.org/java-linux.html>).
You cannot download the JDK from this server, but you can obtain
a list of Ftp mirror sites that contain the JDK. In addition,
this site contains recent news on the Linux JDK, including latest
release notes and bug fixes.

The JDK is a comprehensive suite of tools that one can use to produce
Java applications or applets. The JDK includes the following:

Java run-time support

Java source files

Java tools

Demonstration applets

Installation notes for Solaris and Windows

Using Appletviewer

Using Java debugger

Java Tools is an impressive suite of development tools.
The extensive HTML documentation is thorough, well-written, and
useful. Overall, you have literally everything you need to
produce sof
tware written in Java.

Like all development tools, the JDK tools are designed to
allow the developer to minimize time spent peforming routine
tasks. Unlike many development tools, the JDK tools take this
time-saving premise one step further. For example, the
javadoc
tool will generate HTML pages of
documentation from notes in your Java source code. It will
document the public and protected classes, interfaces,
constructors, methods, and fields. In addition, you can denote
documentation in your Java source by using the
/**
delimiter.
Javadoc
will look for this delimiter and
include your comments. In a production environment, this tool
alone could save many programmers hours of code research.

The
javap
tool will disassemble class files.
Command-line options direct the verbosity of the output. For
example, you can choose to output only the public members of the
class. Included are command-line options for private, data-type
signature, an
d even the disassembled Java byte code for the class
methods.

Another interesting tool is the
javah
, a C-header
and stub-file generator. It will allow C code and Java code to
interact directly by building C header files based on Java
source. This can be used to implement native methods. The C
structure definition in the header (
.h
) file
contains the corresponding layout of the Java class. The
structure fields correspond to the Java class instance variables.

The following table contains a complete description of each
component of the JDK:

Although the JDK is contained in one archive file, there are
two other files that you should consider downloading to round out
the development system. Again, refer to the
Blackdown
Organization Java Linux Page
to find the nearest Ftp site for
downloading these archives.

[
Editor's note:
Of course, newer releases become
available as Java evolves. At the time this article is written,
Linux 1.1.3 J
DK is just becoming available, with 1.1.4 coming
soon.]

jdk1_1_1_linux-v3_tar.gz
,
The JDK, version 1.1.1.

To install the JDK, I GNU unzipped and untarred this file
into
/usr/local
. This will create a directory tree
under
/usr/local/jdk1.1.1
. You are not required to
install into this path; however, if you do, you need not set the
CLASSPATH
environment variable (see ``
Running Java Programs
'' below).

Note:
There is NO documentation in this archive!
For documentation, you must download doc+demo archive (see
next).

To install the documentation and demonstration programs, the
archive was gunzipped and untarred in
/usr/local
. This
will fill the directory structures
/usr/local/jdk1.1.1/doc
and
/usr/loc
al/jdk1.1.1/demo
. Be sure to check out the
new features of the jdk1.1.1 at
/usr/local/jdk1.1.1/docs/relnotes/features.html
.

This is the minimum Java standard platform for running Java
classes. Intended for vendors who want to bundle the JRE with
their software, it will support run-time only systems.

There are future improvements slated for the JRE. Currently,
bundling a Java software distribution is not automated. In
addition, for each Java software distribution loaded on a
workstation, you must have a corresponding JRE. Thus, if I have
two Java applications from different vendors, I must have two
JREs.

One aspect of the JDK is its simple elegance. After the JDK
archive is installed, you need only to set the
CLASSPATH
environmental variable and then you are
ready to use the Java tools. One enhancement in the JDK release
1.1 over the JDK release 1.0 is that if you install the JDK into
/usr/local/jdk.1.1.1
, then you do not even need to
set the
CLASSPATH
variable.

The
CLASSPATH
environmental variable sets the
path to the
classes.zip
file. On other Unix
operating systems, such as Solaris, this file is
classes.so
. If you installed t
he jdk into
/usr/local/jdk1.1.1
, then the
classes.zip
file
resides in the
/usr/local/jdk1.1.1/lib
.

In addition to the
CLASSPATH
variable, you may
wish to place the path to the Java binaries:
/usr/local/jdk1.1.1/bin
in your
PATH
environmental variable.

Note:
If you have previously installed the jdk1.0.2,
you must unset your
CLASSPATH
variable.

Running a Java Applet

Applets are Java programs that follow a set of conventions so
they can be run by a Web browser.

There are three steps to writing an applet:

Write the Java class code.

Successfully compile the Java code into byte code.

Call the applet from an HTML page, using the
<APPLET>
tag.

Applets are distinguished from application
programs in the
class definition. All applets must be a subclass of the Applet
class. This allows custom applets to inherit methods from the
Applet superclass. In the ``Hello World!'' applet below, the
import of the
java.applet.Applet
class file in line
1 will allow the applet code to inherit and reference the Applet
class methods.

HelloWorld Applet

Writing and compiling Java code is discussed in the next
section
Running a Java Application
. The
demonstration applets provided with the JDK will be used to
illustrate how to run an applet.

When attempting to run the demonstration HTML pages in a
Netscape 3.0 browser, Netscape reported an error depicted in
this image:

The
java_301
is a zipped file that contains Java
classes. After installing it into the correct location, Netscape
still showed the same error.

Netscape 3.0 only supports JDK 1.0.2. Thus, if you want to
develop, test, and distribute Java applets that will run in
Netscape 3.0, you should either compile your Java applets to be
compatible with the JDK 1.0.2 (using the JDK 1.1.1) or retrieve
the JDK 1.0.2. However, programmers should note the presence of the
@deprecated
comment in classes, fields, or methods.
This is designed to signal which JDK 1.1.1 methods have superceded
those in JDK 1.0. In the following code fragment the public
method
preferredSize
is replaced by
getPreferredSize
.

Note that the
@deprecated
flag is found in the comment
section of a class.
In addition, note the
@see
flag.
This instructs the programmer to use the noted method as
a replacement.

When the
javac
compiler finds the
@deprecated
flag in the comment section of a class, it will place a
"Deprecated" flag in the output classfile. When a deprecated feature
is used, the compiler will issue a warning.

Netscape's upgrade of Navigator has been rolled into the
Communicator application suite. In a
press release
dated 10 Oct 1997, Communicator beta release 2
supports 95% of the JDK 1.1.1 features. When Communicator is in
production, the JDK 1.1.1 is to be fully supported.

Javasoft provides the Appletviewer in lieu of a Web browser.
The Appletviewer accepts an HTML page as input and will process
the applet denoted by the
<APPLET>
HTML tag:

The
awt-1.1
examples are also Included in the
/usr/local/jdk1.1.1/demos
directory. AWT (Abstract
Window Toolkit) is part of the Java API that provides methods
common to GUI interfaces. For example, the java.awt.Button class
creates a labeled button in your applet. T
he AWT is documented
in the
/usr/local/jdk1.1.1/docs/api/packages.html
file.

Running a Java Application

Java applications differ from Java applets in that they do not
require a Web browser to execute. Also, they need not inherit
the Applet class. Java applications are more flexible because
they are stand alone. All you need to run a Java application are
the application class files and the Java Run-time Environment
(JRE).

If you have worked with C or C++ tools, compiling a Java
application will be familiar. The code listing below is the
application equivalent of the "Hello World!" applet. This
program will print "Hello World!" to the standard output.

Use your favorite editor to enter the code for the
HelloWorldApp class shown above. Save the file as
HelloWorldApp.java
. A public class, here
HelloWorldApp, must be defined in a file named after that class,
as in
HelloWorldApp.java
. The
.java
file-name extension is similar to a
.c
used in C or
.cpp
in C++.

To compile the
HelloWorldApp.java
file, execute
the
javac
compiler at a shell prompt. (Be sure
that the location of the
jdk1.1.1/bin
directory is
in your shell's command search path.) The out
put is an
executable file, named
HelloWorldApp.class
.

javac HelloWorldApp.java

To run the the HelloWorldApp, you invoke the
java
command at a command prompt, omitting the
.class
extension.

The documentation included with the demonstration applets is
an excellent source of information. There are HTML manual pages
to describe usage of the Java tools included in the JDK. If you
installed the doc+demo archive into
/usr/local/jdk1.1.1
, the JDK 1.1.1 documentation
HTML index page will be located at:
/usr/local/jdk/docs/index.html
. This is a great
resource page that has links to other local documentation. In
addition, links to Javasoft and the Java tutorial are
included.

Other Resources:

JavaSoft
home page. This has the latest news and in
formation about the
JDK and Java.

On-line version of
The
Java Tutorial
by Mary Campione and Kathy Walrath is an
830-page tutorial with 27 lessons that cover application and
applet development. Lessons range from beginner to advanced
levels.

In total, the JDK 1.1.1 is a solid development environment.
The example code is well written, documented, and illustrative.
The suite of development tools are extensive and sophisticated.
To fully appreciate all the efforts of the Javasoft development
team, you could spent many hours learning about Java.

Some developers who have used GUI Integrated Development
Environments (IDEs), may find the character-based tools
primitive. It is interesting that given that most GUI
development environments are written as IDE interfac
es, Javasoft
does not showcase the JDK development environment.

Abstract Window Toolkit
-- A set of Java
classes that execute common GUI interface attributes, such as a
scroll bar or window border.

GUI

Graphical User Interface
-- An interface in
which the program is rendered graphically, allowing the user to
see its components while it executes. Typically, it implies
support for a pointer device, such as a mouse.

IDE

Integrated Development Environment
-- A
development environment where all the development tools -- code
editor, compiler, debugger, optimizer, etc. are contained within
a single GUI environment.

JDK

Java Development Kit
-- The suite of 14
development tools that is freely available to use to develop Java
applications.

JRE

Java Run-Time Environment
-- The minimum
software necessary to run a Java application.

Jeffery Cann is an IVR (Interactive Voice Response) programmer
in Denver, Colorado. He works on Unix in C and Oracle PL-SQL.
Looking to bolster his knowledge of object-oriented languages, he
has turned to Java to determine if it is applicable to
asynchronous telephony applications.