Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Java Developer's Reference

Chapter 2 -- Installing Java

Chapter 2

Installing Java


CONTENTS




Before writing a single line of code, the software application developer must first make sure that the best tools for the job are at his or her disposal. This universal truth also applies to Java programming. As discussed in Chapter 1, "Introduction to Java," Java was designed from the ground up as a cross-platform, object-oriented programming language. These two features (cross-platform and object-oriented) combined with the power of the Java language enable the developer to build flexible, powerful applications that were previously difficult or impossible to build with conventional toolsets.

Because of the huge amount of interest generated by the introduction of Java, new tools are being introduced daily that will provide the developer with greater flexibility and ease of use. However, the very availability of these tools can be extremely confusing to a new Java developer. Common questions include:

This chapter attempts to answer all of these questions and provide the reader with all of the tools necessary to build Java applications. By the end of this chapter, you should be able to answer these questions with ease.

Getting Started with the Java Developer's Kit

We will assume that you, the reader, have nothing on your local computer available for Java development. Where should you start? In terms of getting started, becoming a Java programmer is easy. Sun Microsystems decided some time ago to make Java an open standard. This means that it would release its language specification for public view and take comments and suggestions on how to improve that language. In addition to the language specification, Sun also provided implementations of the Java Virtual Machine for 32-bit Windows (Windows 95 and Windows NT) and Sun's Solaris operating system. Now, instead of simply professing that Java was cross-platform and vendor-neutral (as many other unnamed technologies have professed for years), Sun can back up what it was saying. Soon, hundreds of applets and applications across the Internet will be able to run unaltered on the most popular operating platforms available.

All of this is fine for compiler writers, but how does all of this help you, the developer? Here's the good news. Sun also decided to give away (give, as in free) a Java Developer's Kit (JDK) that would provide the basic tools needed for Java programming. The JDK provides the beginning developer with all the tools needed to begin writing powerful Java applications or applets. It contains a compiler, an interpreter, a debugger, sample applications, and an applet viewer that you can use to test your code.

A quick visit to Sun's JavaSoft Web site (http://java.sun.com) will allow you to download the JDK to your local machine. (See Figure 2.1.)

Figure 2.1 : The JavaSoft products page on the World Wide Web.

Figure 2.1 shows the type of information and tools that can be retrieved from the JavaSoft Web site as of June 1996. This site will undoubtedly have changed by the time this book is published. Therefore, make sure to check the JavaSoft Web site to download the latest version of the JDK! Clicking on the JDK link will take you to a screen that will enable you to download the JDK directly to your local machine. (At the time of this writing, the latest version of the JDK was Version 1.0.2.) Three operating system choices are then presented for your selection:

  1. Sun Solaris 2.3, 2.4, or 2.5 on SPARC-based machines or Solaris 2.5 on x86-based machines
  2. Microsoft Windows NT and Windows 95
  3. Apple Macintosh System 7.5



The JDK is also available by FTP from ftp.javasoft.com. All of the operating system choices are available, and the JDK can be found in the \pub directory.

Remember that the availability of the JDK for these platforms simply means that Sun has implemented the Java Virtual Machine and development tools for these platforms. This does not mean that any Web browser on these platforms will now run Java applets! Each browser vendor still must supply the "hooks" to display Java applets within their individual windows.

Note
Although it appears that Java may soon be running on everything from mainframes to cellular telephones, at the current time the Java Virtual Machine is available from Sun only on these three platforms. To determine whether a Java Virtual Machine is available for the platform of your choice, contact the operating system vendor directly.

You may wonder why Sun chose to develop only 32-bit Windows versions of the Java Developer's Kit. Although there are several technical reasons for the omission of 16-bit support, the primary reason appears to be Java's reliance on a multitasking OS. Although Windows 3.1 originally was marketed as a multitasking operating system, it quickly became apparent that it was not "industrial-strength." Java enables the programmer to break off pieces of applications and run them as separate threads. This is handled best at runtime by a multitasking OS. At this time, IBM has expressed support for the development of a Java Virtual Machine (JVM) for Windows 3.1 and OS/2.

JDK Installation Notes

Although you may be extremely eager to display your head spinning on your World Wide Web home page, there is still a little more setup work to be done. Because the installation instructions vary depending on which platform the JDK is being installed on, this section breaks these instructions up into three groups: Solaris, Windows, and Macintosh.

I have downloaded the Windows NT version, and the resulting file is named JDK-1_0_2-win32-x86.exe. (And to think that only a short time ago, we were limited to eight characters for the filename!) After you run this file to decompress it, the Java Developer's Kit will be installed on your system. See the installation notes following to determine the necessary steps you must undertake before actually using the JDK. After the JDK is properly installed on your system, we will take a look at what tools are now at your disposal.

If Java is truly a cross-platform language, why are there separate files to download for each platform? Actual Java source code, when compiled, does result in bytecode that can be run on any platform with a Java Virtual Machine installed. Keep in mind, however, that the Java Developer's Kit contains a number of executable files (the compiler, the interpreter, the debugger, and so on) that are compiled for your specific platform. If the resources are available to you, download another version of the JDK (for Macintosh, for instance) and look through the example code. You will notice that the .java files are identical to those in the Windows and Solaris JDKs.

Note
No matter what platform you are on, it is advised that you remove all older versions of the JDK before installing the latest version.

Sun Solaris Installation Notes

  1. After you acquire the tarred version of the JDK, you must unpack it before use. The following command will unpack the file:
    /usr/bin/zcat JDK-1_0_2-solaris2-sparc.tar.Z | tar xf -
    (Keep in mind that the current filename at the time of this writing was JDK-1_0_2-solaris2-sparc.tar.Z. Substitute the correct filename at the time you download this file.)
  2. A directory will be created named /java. Add the java/bin directory to your path. This directory contains the compiler and other tools needed to build your
    applications.

Windows 95 and Windows NT Installation Notes

  1. Run the self-extracting file JDK-1_0_2-win32-x86.exe. It will create a main directory \java in whichever directory you have the downloaded file stored. (Running the file from C:\ will result in the C:\java directory being created.)
  2. Add the \java\bin directory to your path.
    Windows 95: This can be done by editing the PATH variable in your AUTOEXEC.BAT file (stored in the C:\ root directory). You must reboot the system for this change to take effect.
    Windows NT: You can change the path by editing the environment variable PATH in the Control Panel "System" application.

Apple Macintosh System 7.5 Installation Notes

  1. The file downloaded (JDK-1.0.2-MacOS.sea.bin or JDK-1.0.2-MacOS.sea.hqx) must first be unpacked. Depending on which file you downloaded, this can be done using different tools. If the file is in MacBinary format, use Stuffit to decompress the file. If the file is in hqx format, use DeHQX or BinHex4 to decompress the file.
  2. Run the installation program to create a folder named JDK-1.0.2-mac.

Note
Although environment variables are not required to be set at this point, you should be aware that there are a number of environment variables that the JDK uses to compile classes. Here's a list of them:
  • PATH-The preceding install instructions should have led you to set the PATH variable correctly.
  • JAVA_HOME-This variable is used to store the Java root directory.
  • CLASSPATH-Used to store the directory location of additional class files that will be needed to compile your project. On UNIX, this list is colon-separated; on the pc, this list is semicolon-separated.

After installing, do not unzip the classes.zip file without updating the CLASSPATH environment variable. Notice that none of the .class files actually appear (outside of the classes.zip file) on your local drive. One neat feature of Java is that classes can be read from within a ZIP file. Because of the huge amount of potential classes on each local machine, this cuts down on local file system usage without causing much of a performance penalty.

Testing the Installation

The applet viewer application can be used to run the sample applications included with the JDK. This application will be located in the \bin directory of your installation. It is at this time that you will start to appreciate your GUI-based development tools for languages such as C++, Visual Basic, and Delphi. All of the tools included with the JDK are command-line only. To run the applet viewer from within Windows 95/Windows NT, go to your MS-DOS prompt, and then follow these steps:

  1. Change to the \demo\fractal directory. If you installed the JDK into the C:\java directory, type the following command:
    cd demo\fractal
  2. The applet viewer can take as its input an .HTML source file that "contains" a Java applet (more information on HTML and Java can be found in Chapter 12, "HTML for Java Programmers"). Enter the following command to run the Fractal example:
    appletviewer example1.html

You should see output to the applet viewer that looks something like Figure 2.2.

Figure 2.2 : The applet viewer running the JDK Fractal example.

If you still aren't convinced your installation is set up correctly, try loading any of the sample .htmL files containing applets into a Web browser that supports Java applets. At the time of this writing, this includes Netscape's Navigator 2.0 (see Figure 2.3) and Sun's HotJava Web browsers.

Figure 2.3 : Netscape 2.0 running the JDK Fractal example.

Exploring the Java Developer's Kit

What exactly did the JDK just put onto your local drive? Let's explore the contents of the Java Developer's Kit more fully. Here are the main directories that contain the JDK files:

bin\  This directory (like most development kits) contains all of the applications to compile, link, and run Java applications and applets. The most widely used applications within the bin directory include the following:

demo\  The demo directory contains a large group of sample java applets that can provide an excellent starting point for many typical java applets. Included in this set are the following applets:

Animator
GraphLayout
ArcTestImageMap
BarChartJumpingBox
BlinkMoleculeViewer
CardTestNervousText
ClockSimpleGraph
DitherTestSortDemo
DrawTestSpreadSheet
FractalTicTacToe
GraphicsTestWireFrame

include\  The include directory contains a set of C and C++ header files. These can be used to interface java classes to the C and C++ languages.

lib\  The primary file contained in this directory is the classes.zip file. This file contains all of the classes that together make up the JDK. Here are the primary packages (more on packages can be found in Chapter 3, "The Java Language"):

rc\  The rc directory contains the source files for the JDK classes. Windows 95/NT users will not see this directory, but the directory can be restored by unzipping the src.zip file found in the root directory of the JDK.

Distributing the Java Virtual Machine

Although most users think of Java applets when they think of Java, the JDK also can be used to develop stand-alone Java applications. All that is required on the user's machine is the Java Virtual Machine. The following list details the minimum required files for Windows 95/NT setup:

java.exe
javaw.exe
javai.dll
net.dll
awt.dll
mmedia
mfc30.dll
jpeg.dll dll
msvcrt20.dll
classes.zip

Other Development Environments

Software developers have become accustomed to fully graphical development environments. Rapid application development (RAD) tools such as Powersoft Powerbuilder, Microsoft Visual Basic, and Borland Delphi have drastically increased programmer productivity and ease of use. Then along came Java! The JDK was designed to be a "basic" development toolkit that could be used on virtually any platform on which the Java Virtual Machine existed. For some developers, the toolset that comes prepackaged with the JDK will be perfectly fine. However, the industry as a whole is currently clamoring for more powerful Java tools, and where there is money, there will be products. Although many forthcoming Java products were still in development at the time of this writing, several will be discussed here. Web site addresses will be given, where possible, so you can acquire the most up-to-date information.

Not surprisingly, the most eagerly anticipated tools come from established software development tool manufacturers Sun, Borland, Symantec, and Microsoft. Although it remains to be seen which kits will be more successful than others, it is important to remember that Java development can occur on virtually every popular operating system platform available today. This in itself is a feat that must not be taken for granted. A developer using Sun Solaris can instantly test his application on Windows, Macintosh, and UNIX machines running side by side. Quite exciting! Now let's take a look at some popular tools.

SunSoft Java Workshop for Sun Solaris and Microsoft Windows 95/NT

Perhaps the most novel development platform comes from the creator of Java, Sun Microsystems. An evaluation copy can be downloaded from Javasoft's Web site at

http://www.sun.com/sunsoft/Developer-products/java/Workshop/

The Java Workshop is interesting because it is entirely written in Java. The Workshop enables the developer to organize work into projects and compile and run Java applications using a set of visual tools. At the current time, it has no capability to manage database-oriented projects, and it does not allow the user to visually edit class properties and methods. Because it was written in Java, however, the Workshop runs almost identically across the platforms it is available for. An example of its interface is shown in Figure 2.4.

Figure 2.4 : SunSoft Java Workshop.

Symantec Café for Microsoft Windows 95/NT and Apple Macintosh

Symantec Café (http://café.symantec.com) was the first GUI-based development environment for Java on the Windows platform. The development environment is based on the popular Symantec C++ compiler but has been customized for Java applet/application development. Features include the following:

Borland Latte for Microsoft Windows 95/NT

Borland Latte is the long-awaited, GUI-based development environment for Java. Much of the look-and-feel of Latte (see Figure 2.5) is based on the award-winning Windows IDE Borland Delphi. Like Symantec's Café, Latte will include a GUI debugger (available as of February 1996) and a complete GUI-based IDE. Also included with Latte will be the Borland InterBase InterClient. This software, written entirely in Java, will allow InterBase databases to be connected using Java applets. Borland plans to continue to roll out Java-based development tools to meet corporate demands in areas such as database access and GUI development.

Figure 2.5 : Prerelease screen shot of Borland Latte.

Microsoft Visual J++ for Microsoft Windows 95/NT

Microsoft Visual J++ is the name for Microsoft's Java development platform. This includes a GUI-based development environment in addition to a Java Virtual Machine implementation for the Windows platform. Microsoft plans to augment standard Java functionality with its ActiveX component object technology. Although the ActiveX framework is outside of the scope of this book, it appears that Microsoft plans to wrap Java applets with ActiveX. This will allow applets to be scripted using languages such as JavaScript and VBScript, but all of these features will obviously affect the cross-platform viability of these Java applets. Microsoft is currently readying copies of its ActiveX-enabled browser, Internet Explorer, for the Macintosh and UNIX platforms.

Summary

The Java Developer's Kit contains all of the tools necessary to begin any Java software development project. Of course, the World Wide Web contains a vast amount of information and tools not mentioned here, so any Java development project would be incomplete without constant monitoring of the Java newsgroup (comp.lang.java) and the JavaSoft home page (http:\\java.sun.com). In addition to the JDK, a wide variety of Java development platforms is available, each of which has features worth exploring further. Upcoming chapters will explore the Java language as well as the individual tools included with the Java Developer's Kit.