|
"Tutorial" A Cup of Java -- With Two Lumps of Linux | ||||||||||||||||
|
By Jeffery Cann
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. Java on LinuxJavasoft, 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. Java Development KitThe JDK is a comprehensive suite of tools that one can use to produce Java applications or applets. The JDK includes the following:
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
The
Another interesting tool is the
The following table contains a complete description of each component of the JDK:
Installing the JDKAlthough 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.]
Running Java ProgramsOne aspect of the JDK is its simple elegance. After the JDK
archive is installed, you need only to set the
The
In addition to the
Note:
If you have previously installed the jdk1.0.2,
you must unset your
Running a Java AppletApplets 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:
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
HelloWorld Applet
1 import java.applet.Applet;
2 import java.awt.Graphics;
3
4 public class HelloWorld extends Applet {
5 public void paint(Graphics g) {
6 g.drawString("Hello World!", 50, 25);
7 }
8 }
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
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
* @see #getPreferredSize
*
*/
public Dimension preferredSize(){
return getPreferredSize();
}
Note that the
When the
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
<HTML> <HEAD> <TITLE>TicTacToe (1.0.2) App let</TITLE> </HEAD> <BODY> <APPLET CODEBASE="1.0.2/" CODE="TicTacToe.class" WIDTH="120" HEIGHT="120"> A 120x120 Tic Tac Toe applet is here. <APPLET> <A HREF="1.0.2/TicTacToe.java">The source file</A> <A HREF="1.1/example1.html">The 1.1 Version</A> </BODY> </HTML> To use the Appletviewer to view (and play) a game of TicTacToe, you invoke the viewer in an xterm X Window System window. Note:
Be sure that the directory path to the
Appletviewer executable is in your shell's
appletviewer /usr/local/jdk1.1.1/demo/TicTacToe/example1.html Interestingly, the TicTacToe game has sound associated with the moves. Luckily, I had my speakers turned on! When I finally beat the applet, and won a game, it said ``Yahoo!''
At the top of the applet, there is one pulldown menu labeled applet, which has several options:
There are loads of interesting applets to demo. The source code for each class inside a demonstration applet is provided to peruse. These examples prove useful and interesting to see how Java is used. Demonstration applets in the
Animator ArcTest BarChart Blink CardTest Clock DitherTest DrawTest Fractal GraphLayout GraphicsTest ImageMap JumpingBox MoleculeViewer NervousText SimpleGraph SortDemo SpreadSheet TicTacToe WireFrame The
Running a Java ApplicationJava 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. HelloWorld Application
1 /**
2 * The HelloWorldApp class is the Java implementation of the famous
3 * "Hello World" C language application.
4 *
5 * HelloWorldApp will print "Hello World!" to the standard output.
6 */
7
8 class HelloWorldApp {
9 public static v
oid main(String args[]) {
10 // display the string
11 System.out.println("Hello World!");
12 }
13 }
There are three steps to writing an application:
Use your favorite editor to enter the code for the
HelloWorldApp class shown above. Save the file as
To compile the
javac HelloWorldApp.java To run the the HelloWorldApp, you invoke the
java HelloWorldApp ResourcesThe 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
Other Resources:
SummaryIn 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. Acronyms
Author BiographyJeffery 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. |
||||||||||||||||
Print This Page Send as e-mail |
Best of the Web
Data deduplication: Declawing the clones
Data deduplication is emerging as a critically important new arrow in the storage administrator's quiver to answer hard questions about the increasing problem in storage growth costs.
Compression, Encryption, Deduplication, and Replication: Strange Bedfellows
One of the great ironies of storage technology is the inverse relationship between efficiency and security: Adding performance or reducing storage requirements almost always results in reducing the confidentiality, integrity, or availability of a system.
WAN Optimization Whitelists and Blacklists
Optimization is a fantastic way of saving money and creating really happy customers at the same time, but it doesn't work flawlessly for all applications.
WAN Optimization as a Managed Service: It's Not About the Cost
This insight examines how organizations outsourcing their WAN optimization initiatives to a third-party go about achieving their goals for application performance, reducing operational costs, and streamlining enterprise infrastructure.









