Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
Java Language EssentialsDownload tutorial zip fileEmail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
Course Notes
  


Run-time environments and class path settings page 26 of 37


The Java(TM) interpreter (runtime environment) dynamically loads classes upon the first reference to the class. It searches for classes based on the directories listed in the environment variable CLASSPATH. If you use an IDE, it may automatically handle CLASSPATH internally, or write a classpath setting to the appropriate system file during installation.

If you do not use an IDE, for example, if you're using the Java Development Kit (JDK) from Sun, you may have to set a classpath before running the Java compiler and interpreter, javac and java, respectively. Also, note that in most situations the installation procedure will automatically update the PATH environment variable, but if you're unable to run javac or java, you should be aware that this setting could be wrong.

PATH environment variable settings vary across operating systems and vendors. In a Windows environment, the following setting augments the old/existing PATH setting (%PATH%) with c:\java\bin:


set PATH=%PATH%;c:\java\bin

For this example, when attempting to run a Java IDE, or the JDK's compiler or interpreter, Windows includes the directory c:\java\bin in the search for the executable program. Of course, this setting (c:\java\bin) will vary from one Java environment to the next. Note that the path separator character is ";" for Windows environments and ":" for UNIX environments.

If you find it necessary to set the CLASSPATH environment variable, for example, if you're using the JDK from Sun, it should include all directories on your computer system where you have Java class files that you want the Java compiler and interpreter to locate. As you add new class-file directories, you will typically augment this classpath setting. In a Windows environment, the following statement sets CLASSPATH to include three components/sites:


set CLASSPATH=c:\java\lib\classes.zip;c:\myjava\classes;.

Note that this setting includes a zipped class file archive classes.zip in the lib directory of a particular Java environment's distribution directory, represented generically here as c:\java\. That is, most Java environments can read class files stored in archive files of type .zip and .jar, as well as unarchived class files in any specified directory. During installation, many Java environments "remember" the location of their class files; thus, setting the Java environment's class file location is not necessary.

In this example, CLASSPATH's semicolon-separated entries also include c:\myjava\classes\, a personal/user collection of class files, and ".", which represents the current directory. The latter setting is convenient for working with Java files in an arbitrary directory that's not listed in the classpath setting.

Windows 9x and NT users can set classpaths manually with a text editor in the file autoexec.bat, plus Windows NT users can set a classpath via the control panel's System dialog. UNIX users can set a classpath manually in the appropriate shell script's configuration file. Please refer to the appropriate system reference books and documentation that describe how to set an environment variable.

If you're using the JDK from Sun, you can (1) install one of several freeware, or cheapware, tools that automate the process of presenting a text editor window for writing Java programs and then invoking javac or java from a graphical IDE button or (2) invoke these programs directly from a command window.

It's impractical to attempt a demonstration of the many IDEs, however, compiling and running a Java application with the JDK is quite straightforward. The following commands demonstrate the appropriate commands:


D:\>javac SimpleProgram.java
D:\>java SimpleProgram
This is a simple program.

Your Java environment will almost certainly vary in several ways from what we've described here.


copyright 1996-2000 Magelang Institute dba jGuru


Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
PrivacyLegalContact