Developers: Learn a New Programming Language or App Development with Deitel LiveLessons Videos!
s
menu
menu
Login  |  Register  |  Media Kit  |  Press  |  Contact Us  |   Twitter Become a Deitel Fan on Facebook  
Custom Search



 
AddThis Social Bookmark Button

FAQ: Java How to Program, 5/e

Table of Contents

  1. The 60-day trial version of the Cloudscape 5.0 database on my Java How to Program, Fifth Edition CD says that the licence has expired even though I just installed it
  2. 5th Edition, Servlets Chapter: How do I compile my servlets properly?
  3. Why do I get the error "Exception in thread "main" java.lang.NoClassDefFoundError" when I run my program?
  4. In the Fourth Edition of Java How to Program, how do I execute the Elevator Simulator?
  5. I am using Sun's J2SDK version 1.3.x with the Second or Third Edition of Java How to Program and I cannot get programs with packages to work correctly. What am I doing wrong?
  6. How do I prevent Notepad from adding a .txt extension to my file names?
  7. The RMI example in chapter 20 (3rd Edition) will not work. How to I fix it?
  8. Why won't my Java 2 applets execute in Netscape and Internet Explorer?
  9. How do I install the software from the CD-ROM included with Java How to Program, Third Edition?
  10. What features are supported by JBuilder3 University Edition?
  11. Why won't my Java 1.1 applets execute in Netscape 4.02 or lower?
  12. Why won't my Java 1.1 applets execute in Internet Explorer 3.x?
  13. Why won't Java 1.1 programs compile properly in Microsoft Visual J++ 1.1?
  14. Why can't Visual J++ 1.1 find the Java packages/Why doesn't Visual J++ 1.1 work on Windows 98/Why doesn't Visual J++ 1.1 work on any Windows machine with IE 4?

The 60-day trial version of the Cloudscape 5.0 database on my Java How to Program, Fifth Edition CD says that the licence has expired even though I just installed it

The software packaged with Java How to Program, Fifth Edition includes a 60 day trial edition of IBM Cloudscape® 5.0 database software. It has come to our attention that this trial edition software prematurely expires (even if you just installed it), rendering it unusable. A new and complete 60 day trial version of Cloudscape 5.0 is now available.

Download the new and complete 60 day trial version IBM Cloudscape® 5.0. The size of the downloaded 'cloudscape504-eval.jar' file should be 15,449,158 bytes.

Alternate Download Site


5th Edition, Servlets Chapter: How do I compile my servlets properly?

In the 5th Edition of Java How to Program, we inadvertently did not explain how to compile your servlets properly. The servlet classes are not part of Java 1.4.1. They are however included with Tomcat. Compile each servlet as follows:

      javac -classpath $TOMCAT/common/libs/servlet.jar YourServlet.java

where $TOMCAT is the Tomcat installation directory and YourServlet.java is the source code for the servlet you would like to compile.


Why do I get the error "Exception in thread "main" java.lang.NoClassDefFoundError" when I run my program?

The Java Virtual Machine refers to the CLASSPATH environment variable to locate Java classes. Some programs modify the CLASSPATH in a way that causes the Java command-line tools to fail with the error message

          Exception in thread "main" java.lang.NoClassDefFoundError: className

where className is the name of the Java program (e.g., Welcome1). To correct this problem, use the -classpath command-line argument when compiling and running your programs. For example, to compile Welcome1.java, type

          javac -classpath . Welcome1.java

To execute the program, type

          java -classpath . Welcome1

The "." tells the compiler and virtual machine to look in the current directory for classes. Alternatively, you can permanently remove the CLASSPATH environment variable on Windows 2000 and Windows XP by going into the System control panel, selecting the Advanced tab, clicking the Environment Variables button and removing the CLASSPATH entry from the User variables and System variables boxes.


In the Fourth Edition of Java How to Program, how do I execute the Elevator Simulator?

The java files used to run the elevator case study are in the directory:

D:\examples\elevator\com\deitel\jhtp4\elevator\
D:\examples\elevator\com\deitel\jhtp4\elevator\controller\
D:\examples\elevator\com\deitel\jhtp4\elevator\event\
D:\examples\elevator\com\deitel\jhtp4\elevator\model\
D:\examples\elevator\com\deitel\jhtp4\elevator\view\

where D: is the CD-ROM drive that you use to run the book's accompanying CD. The file

D:\examples\elevator\com\deitel\jhtp4\elevator\
   ElevatorSimulation.java

contains the main method used to run the case study.

To run the case study, do the following:

  1. In a command shell, you must run the program from the directory that contains the com directory. For example, if the temp directory contains the structure com/deitel/jhtp4/elevator which contains ElevatorSimulation.class, you must run the program from the temp directory.
  2. Run the Book's software on the companion CD.
  3. When you see the Welcome screen, click the Examples button. (You should then see 24 folders, each corresponding to a specific chapter.)
  4. Open the contents of (double-click) the elevator folder. (You should see the com folder.)
  5. Drag-and-Drop the com folder into some folder on your hard drive (I moved the elevator folder into my temp directory.)
  6. Open a command shell (i.e., Dos prompt)
  7. Change to the directory that contains the com folder (e.g., cd\temp)
  8. To run the program, type:
    java com.deitel.jhtp4.elevator.ElevatorSimulation
    and press Enter

Back to Top


I am using Sun's J2SDK version 1.3.x with the Second or Third Edition of Java How to Program and I cannot get programs with packages to work correctly. What am I doing wrong?

Well, nothing really. It is just that the instructions have changed with new versions of the JDK/J2SDK. The following PDF files should help you fix these problems.

creatingPackages.pdf (171 KB)

AppletWithPackages.pdf (94 KB)

Back to Top


How do I prevent Notepad from adding a .txt extension to my file names?

A reader recently sent an email indicating that you can simply place the file name in double quotes when you type the name to prevent Notepad from adding a .txt extension to your Java file name.

If this does not work for you, do the following:

To prevent Notepad from adding a .txt extension to your Java files, you must associate Java files with Notepad, so Windows knows that Notepad is the editor for .java files.

  1. Open Windows Explorer.
  2. In the View menu select Folder Options...
  3. On the View tab in the dialog box, make sure the checkbox for Hide file extensions for known types is unchecked and click OK at the bottom of the dialog.
  4. In Windows Explorer, locate one of the files that Notepad added the .txt extension to. Select the file.
  5. From the File menu, select Rename and remove the .txt extension from the file.
  6. Double-click the file. If .java files are not currently associated with an editor program, the Open With dialog box will appear.
  7. Scroll down in the list to Notepad and click it once. Make sure the Always use this program to open this file checkbox is checked. Click OK.

You should now be able to double-click the .java file to open it. And, because Notepad now knows it is to be used to edit .java files, it will not add the .txt extension any more.

Back to Top


The RMI example in chapter 20 will not work. How to I fix it?

The National Weather Service changed the format of their Traveler's Forecast web page slightly. Make the following changes to the file TemperatureServerImpl.java to fix the problem:

Line 35 should be changed from

String separator = "</PRE><HR><BR><PRE>";

to

String separator = "TAV12";

Line 58 should be changed from

while ( !inputLine.equals( "" ) ) {

to

while ( inputLine.length() > 28 ) {

Recompile the file and regenerate your stub file before running the server.

Back to Top


Why won't my Java 2 applets execute in Netscape and Internet Explorer?

As we state in Software Engineering Observation 3.1 (p. 90) of Java How to Program, Third Edition,  Netscape Navigator 4.x and below and Microsoft Internet Explorer 5 and below do not support Java 2 directly. To allow most applets written in Java 2 to execute in Netscape or Internet Explorer, you must use the Java Plug-in. The Plug-in bypasses the Java Virtual Machine built into the browser in favor of the Java 2 Runtime Environment (J2RE) installed on the local computer. If the J2RE is not installed, the user can be prompted to download it. In Chapter 16, of Java How to Program, Third Edition we discuss the Java Plug-in HTML Converter that allows you to convert your standard HTML documents containing applets, so that those applets can run in the J2RE. For more information on the Plug-in, visit the site

http://java.sun.com/products/plugin/

To download the Java Plug-in HTML converter, visit the site

http://java.sun.com/products/plugin/1.2/features.html

Netscape 5 is supposed to include the Java 2 Runtime Environment (on at least the Windows and Solaris platforms) so it will be able to execute Java 2 applets natively.

Back to Top


What features are supported by JBuilder3 University Edition?

Unfortunately, Borland has removed the following page from their site.

http://www.borland.com/education/jbuilder/jbmatrix.html

If you intend to use JBuilder, we now recommend that you DO NOT use the one on our CD in Java How to Program, 3/e. Rather, download the latest JBuilder Foundation Edition from www.borland.com. It is much better than the version on our CD and contains many more features, including a proper GUI editor.

Back to Top


Why won't my Java 1.1 applets execute in Netscape 4.02 or lower?

Your browser must be updated to Netscape 4.03 or higher AND you must download the JDK 1.1 patch from

http://developer.netscape.com

Java 1.1 applets will not execute in Netscape 4.02 or below.

Alternatively, you can obtain the Java Plug-In and the Java Plug-In HTML Converter from

http://java.sun.com

These allow you to execute Java applets using Java 1.1 in Netscape 3.x and higher and Internet Explorer 3.02 and higher.

Back to Top


Why won't my Java 1.1 applets execute in Internet 3.x?

Your browser must be updated to Internet Explorer 4.0 or higher. You can use Internet Explorer 3.02 if you download and install the SDK for Java 2.01 from

http://www.microsoft.com/visualj

Click on the Free Downloads hyperlink.

Alternatively, you can obtain the Java Plug-In and the Java Plug-In HTML Converter from

http://java.sun.com

These allow you to execute Java applets using Java 1.1 in Netscape 3.x and higher and Internet Explorer 3.02 and higher.

Back to Top


Why won't Java 1.1 programs compile properly in Microsoft Visual J++ 1.1?

Visual J++ 1.1 is not Java 1.1. To get most of the features of Java 1.1 in J++, you can download and install the SDK for Java 2.01 from

http://www.microsoft.com/visualj

Click on the Free Downloads hyperlink. Please note that this does not completely update J++ to Java 1.1. Most programs in Java How to Program will compile properly once the software updated, but we have had trouble with BorderLayout in Chapters 10 and beyond.

Back to Top


Why can't Visual J++ 1.1 find the Java packages?

The problem is, most likely, related to the use of the package manager and IE4. VJ1.1 doesn't know about the package manager and so is looking for class packages in zip files. You can request the package manager create these files using the following command line:

clspack -auto

Do this from the C:\windows\java (or C:\WINNT\java) subdirectory.

 

Deitel Dive-Into(R) Series Corporate Training

Discounts on SafariBooksOnline.com subscriptions

 
Java How to Program, 5/e Cover


ISBN: 0131016210
© 2003

Order now at
Amazon.com
Informit.com

Download Code
Examples and
Other Premium
Content for
Registered Users

Login or Register to download this book's code examples and other premium content.

foot
Update :: December 21, 2014