hide random home http://www.javasoft.com/raq.html (PC Press Internet CD, 03/1996)

HomeAboutNewDownloadingDocumentation The HotJava BrowserAppletsDeveloper's CornerLicensingIn Touch

Recently Asked Questions (RAQ) - java@java.sun.com

This page is an experiment in evolving free technical support for Java(tm) technology, via our java@java.sun.com email address. The daily load of messages to this address continues to grow beyond our ability to answer each message personally. To get answers out quickly, both to the original asker and to others who may have the same or similar questions, we are initiating this page as a frequently updated posting space for answers. Note that the primary goal is to post answers here quickly, even if that means less-than-complete or less-than-eloquent answers. More fully digested questions and answers will migrate to one of our Frequently Asked Questions (FAQ) pages.

Topics:



Downloading and Installing


I have downloaded jdk for windows NT. My question is how do I unpack it ? If I need a special UnPack pogram, where can I download it from ?

The JDK package for Window NT/95 comes in a self-extracting format (.exe). The standard installation procedure is to cd to the directory in which you want to do the installation (c:\ is the usual choice) and then type the file name (minus the ".exe"). The package will then extract and install itself.


I am on a windows95 system. I have renamed your file jv.zip, and put it in a directory called c:\Java. When I try to run pkunzip [pkunzip -d jv.zip] from the MS-DOS prompt it mostly unzips, but I get a great many warnings that some of the directories could not be created [... and things generally don't work ...]

First, if you got a .exe file from us, all you need to do is run it as a command at a DOS prompt (probably best done at c:\) -- it is a self-extracting archive and will install all the necessary files on your system.

On the other hand, if you downloaded one of our .zip files, you definitely need is another zip/unzip program -- pkunzip truncates the file names to the old 8.3 DOS file name limits, which won't work in Java. Try this version, which should correctly handle the longer file names and capitalization.

We've also heard that WinZip95 will work with long file names, and that is available from http://cwsapps.texas.net.


I have a problem trying to run HotJava on Windows 95. When I run HotJava in the command line nothing happens. And when I run Java in the command line, the following message comes up: Unable to initialize threads.

The "Unable to initialize threads" message most commonly arises when the Java interpreter cannot find the basic class files it needs in order to run. The Thread.class file is one of these files, and the Java interpreter looks for it in a specific place:

Note that the normal installation procedure should put all these necessary files in the right place so that Java/HotJava can find them.

The simplest fix is usually to start from scratch and install a fresh copy.


(Win95 question asked and answered on comp.lang.java) I have a dial-up internet connection and the appletviewer does in fact require me to connect to my access provider before it will run the applet.

I solved the problem for me. Here is what I think I did.

  1. In the Control Panel double click the Network icon.
  2. Select the TCP/IP Adapter and choose Properties.
  3. Click the DNS Configuration tab
  4. Click the Disable DNS option.
  5. Now go to the Dial-Up Networking folder under My Computer and select the icon for you Internet connection.
  6. Click it with the right mouse button and choose Properties.
  7. Click on Server Type in the Properties window.
  8. Click the TCP/IP Setting button.
  9. Add the Primary and Secondary DNS server there.
For some reason this seems to work. I didn't figure this out myself. Someone posted this solution previously.



Documentation


When trying to print the Java white paper (from the javabook.ps file) I get PostScript error messages. What can I do?

We've had some trouble with the PostScript generated by tools we use. The documents work for most printers, but a few have trouble with it. Unfortunately, there's no easy workaround for now (a friend's printer, perhaps?).

Two clumsy alternatives exist if you prefer not the read the whole paper by browsing our site: (1) download the complete html package for the paper, install it locally, and browse it at your leisure from your own machine; or (2) browse each section at our web site and print it out from your browser. You can get at the version of your choice from our documentation overviews page.

We're working towards providing our documentation in a more universally accessible format. We'll post more news about this on our web site as it becomes available.



Java Programming and Applets


I downloaded and compiled your animator applet with the JDK. I don't know what version, all I know is I downloaded it yesterday. I tried to use the applet on my page and I get an error message saying "Applet can't start:class Animator got a security violation:method verification error" What is up with that. I would really like to start using applets

The method verification error in Netscape could be caused by Netscape caching previous information about the Animator.class and trying to perform the verification with this information, rather than actually loading the Animator.class from the file. Try clearing both the disk and memory cache in the Netscape network options screen and then press the reload button while holding the Shift key on your keyboard to reload your page with the applet in it. This will insure Netscape loads a 'fresh' copy of the class from you local disk.

For more detail on the class and method verification that takes place in applet security please see: http://www.javasoft.com/sfaq/verifier.html


What is the story with the "Untrusted Java Applet Window" Message in GUI2.java when running within Netscape?

This message appears on stand-alone windows that an applet inside of Netscape creates. This is to flag to the user that the window does not belong to a native application and that the application has several security restrictions (Applets have security restrictions as compared to stand-alone Java applications).


It appears that only Frames have a setCursor() method. How can I change the cursor in my applet?

Cursors can be changed in applets. The trick is to loop up from your panel with a getParent() until you encounter an instance of a Frame, and then do a setCursor() on that frame. Here is a code example:

   Object frame = getParent ();
   while (! (frame instanceof Frame))
      frame = ((Component) frame).getParent ();
   ((Frame) frame).setCursor (Frame.HAND_CURSOR);


My applet works fine when the HTML page is accessed using the file: mechanism. But when I access the same page using an http server, I get the following error:
   #Applet exception: error: java.lang.ClassFormatError
   java.lang.ClassFormatError
     at netscape.applet.AppletClassLoader.loadClass(AppletClassLoader.java.87)
What is going on here?

The ClassFormatError exception is thrown if the data in the class file is not valid. This could happen for any number of reasons:


How can I pop up a dialog that is modal? I have set the modal flag to be true, but it does not appear to work.

Modal dialogs currently do not work in JDK 1.0 -- it is a known bug that is being worked on.

As a workaround, if you do not want the parent frame to receive any input while the 'modal' dialog is up, call the disable() method of the parent frame while bringing up the dialog. When the dialog is dismissed, call the parent frame's enable() method. That should effectively give you a modal dialog.


How can I set the background of my applet to match with the background of the page?

This question may be answered in two parts:

When the background of the HTML page is a plain color
This is easier to deal with than the other case. You can write an applet that takes the background color of the page as one of the parameters and uses that color to set the background color of applet panel.
When the background of the HTML page is a GIF pattern
The same approach can be taken as for color (passing the background GIF filename as a parameter) and using it to paint the background of the applet panel. However, unless the applet is at the extreme top left of the page, the pattern is not going to line-up with the rest of the page, and therefore you are likely to see the "seams" between the applet's background and the page background. (If the applet is not at the top-left corner, you would have to experiment with the positioning to prevent the seams).
Our suggestion for preventing (actually, minimizing) the offsets problem is to have a texture pattern that is small and blends easily. If you are more ambitious and do not want to place the burden of specifying the parameter on the applet user, you can from the applet code read the HTML page containing the applet (using URL classes), parse it for the background color/pattern and use it as above.


How do I convert audio files from the .wav format to .au format to be able to use them in applets?

There are freeware/shareware programs to convert .wav files to .au files that can be played in applets. One such tool is SoX, which can be accessed from http://www.spies.com/Sox


How do you instruct an applet to release audio control after it runs?

Netscape appears to keep hold of the sound driver during its life.

Netscape can probably give you the complete picture but probably the reasoning behind this is that since every html page could in theory have a java applet that might use audio it makes the control of the audio port much simplier if it just takes control of it at the begining so that any error recovery that netscape has to do is located at the start and not deep inside the application.


What's the status of XYZ bug? When will it be fixed?

We are working hard to fix the bugs on our Known Bugs list but we can't promise any specific dates.


I want to place some of my own classes in a separate subdirectory of the root of the drive, and I want them to be accessed just like the standard java classes are. As of yet, I haven't been able to do this. I've been told multiple times to use the html CODEBASE parameter in the APPLET tag, but to no avail as of yet. It appears this only works if my custom classes are in the same or a subdirectory of my applet.

All your extra class files need to be located in the same directory as the applet class file itself. (You can also put class files in subdirectories of that directory in the unusual case that your applet has its own packages, subpackages, etc.) By default, the directory for class files is taken to be the same as the one containing the html page. The CODEBASE attribute is needed only if your class files are located in a different directory from the default.


I have been readed the news postings and have realized that many people are getting a nasty flickering in their animations. I also have this problem. What is going wrong?

You may be using an obsolete version of Animator. The latest version (1.5) has noticeable improvements in animation performance. You can get it at:

	http://www.javasoft.com/applets/applets/Animator/


I am trying to write an Applet that can take our screen definition and lay it out using AWT buttons and TextFields. My first problem seems to be that I need to exactly position the Button and TextField within the Applet window.

Is this possible? I have tried several Layout Managers and tried using the .move(int,int) method on the Button and TextField objects with no luck. The objects seem to stay where they originally put themselves.

In the exceptional cases in which you need absolute control over a layout, you can omit the layout manager for a container and set the size and positions of all your components explicitly. Note that each Container object comes with a default layout manager (e.g., FlowLayout for Applets), so you need to explicitly set the layout to be null (see the code example below). Also, using absolute layouts is not recommended for cross-platform applications, since they can easily break (i.e., look lousy) when switching from one platform to another.

An alternative is to define your own custom LayoutManager to do your layout. A general introduction to layouts, including pointers on custom layouts, is provided in the User Interface section of our Java language tutorial.

Some sample code:

    /* NullLayout -- An example applet with no layout manager.
     */

    import java.awt.*;

    public class NullLayout extends java.applet.Applet {

	public void init() {
	    resize(300, 300);	// resize the applet
	    setLayout(null);	// don't use a layout manager

	    Button b1 = new Button("button 1");
	    Button b2 = new Button("long button 2");
	    Button b3 = new Button("button 3");
	    Button b4 = new Button("b4");
	    add(b1);
	    add(b2);
	    add(b3);
	    add(b4);

	    /* Set button 1 and button 2 to their natural sizes. */
	    b1.resize(b1.preferredSize());
	    b2.resize(b2.preferredSize());

	    /* Explicitly position buttons. */
	    b1.move(10,10);
	    b2.move(10,50);

	    /* Alternatively, you can set size and position all in one go,
	     * using Component's reshape method.
	     */
	    b3.reshape(40, 110, 80, 40);
	    b4.reshape(40, 150, 80, 40);
	}

    }
  


Do you have an example of an applet that does XYZ?

The Gamelan site carries a large catalogue of applets sorted into broad categories. This site, together with our beta applets page, offer many sample applets that might meet your needs.


I have some problem when I try to compile any java source (even the examples located at the directory demo). For example, I write:
    javac animator.java
  
And the compiler says:
 
    Animator.java:52: Warning: Public class animator must be defined
    in a file called "animator.java".
    ...
  
And it do not create the animator.class. What can I do?

The Java system is case sensitive. The javac compiler will be much happier if you change your file name to

    Animator.java
  


I'm trying to compile a JAVA Applet in Windows 95 within a DOS window using the following command:
  cd e:\www\hotjava\bin
  javac -classpath e:\www\html\classes junk.jav
      or
  javac -classpath e:\www\html\classes junk.java
  
I get the following message:
  javac: can't read: junk.java
  
What am I doing wrong?

Javac uses the CLASSPATH variable to search for classes it encounters while compiling your code. However, to get started on a .java source file in the first place, it needs to find the file directly. I'd suggest you cd to the directory containing the .java file and run javac there:

    MS-DOS Prompt> e:
    MS-DOS Prompt> cd \www\html\classes
    MS-DOS Prompt> javac junk.java
  
Simply calling javac will work if you set your path variable to include your java\bin directory (or e:\www\hotjava\bin in your case). Otherwise, you need to include the full path to the javac executable in your command line:
    MS-DOS Prompt> e:\www\hotjava\bin\javac junk.java
  


I am trying to see if I can take advantage of Javas connectivity from a C++ application. Is it possible to communicate with/drive a standalone (out of browser) java app for data transfer etc, to make use of knowledge of real time protocols etc?

I have noticed from documentation that Java can call OUT to code, but can we call IN?

I could re-develop existing work totally within Java, but that means re-develop and needing Java where I may not need it (or have it)

Today's Java doesn't support the notion of embedding, or otherwise running Java code within a client frame. Netscape did it in their application by including the complete Java Virtual Machine (also referred to as the Java interpreter) in their latest Navigator beta.

Note that Java is appropriate for writing machine-independent applets and applications, especially if you want to distribute them effortlessly via the Internet. The moment you mix in C or C++ code, you've lost those features. If machine independence or Internet distribution is important to you or your clients, it may well be worth the effort to rewrite existing C or C++ code in Java.


I'd like to suggest feature/capability XXX for the Animator applet.

Thanks - we always welcome such suggestions and pass them on to the applet's author.


I can't get long file names, like myApplet.java, to work in a Win95 DOS shell. What's the fix?

You can use MS-DOS Prompt (in Start->Programs) to run all your Java commands. MS-DOS Prompt, thank goodness, does not provide full DOS emulation :-)


Is there anyway to implement tabbing between fields using the AWT? When I have a dialog or a frame displayed that contains multiple entry fields( text fields ), whenever I press the TAB key, all it does is beep. If I try to handle the keypress myself, I don't get the event for the TAB key, the entry field seems to be discarding it.

Is there any support for this? Shouldn't this be built into the base AWT classes?

Missing events was a bug in our initial Beta release and should be fixed with the new event model in our Beta 2 release. A brief explanation of the model is available in our Java Developers Kit FAQ.

We haven't provided support for tabbing between TextFields in our base classes, but the new event model should make it possible for you to implement your own subclasses to handle this. I'll pass your message on as a feature suggestion.


How can I install and run the Animator applet on my local machine?

The Animator applet depends on three class files:


All three files should be installed in the same directory. Note that if you run javac on the source file Animator.java, it should create all the necessary class files in one pass.



Other


I know this is a strange request, but do you have any coffee mugs with the java logo on them that you offer for sale? I'd love to have one!

You can order t-shirts and other Java merchandise through our SunWare Catalog. See http://e-web.ebay/cgi-bin/sunware_catalog.pl.


I am interested in learning about Java and how to program with it. Could you recommend a book for me?

Although we can't make recommendations, here are some resources that you might find helpful. One resource independent of Sun that provides a comprehensive list of Java books is Cye Definitive HTML Book List.

Our group is working on a series of books on the Java programming language. The first group of The Java Series is due out early June. If you are interested in creating applets for web pages, you may also want to check out "Hooked on Java," written by three members of the our group.


Can I obtain the specifications for the upcoming Java chips? Could you tell me how to get them and who I should contact with?

For information about this and other questions, check out Sun Microelectronics' press release.


Can you tell me whether java support sunvideo or videoblaster ... etc. video capture board and Codecs such as CellB, Jpeg, Mpeg, H261 ...etc. ?

Currently, we do not support video in any form. Our initial focus has been on defining and implementing the 1.0 Java Applet API, with support for simple sounds and images. For the future, we are looking into supporting a richer range of multimedia capabilities.


Does the Java language support internationalization in the form of multibyte chararacters etc..?

Presently, the Java language only supports the first 256 characters of Unicode (i.e., iso-latin-1 characters). We will eventually support all Unicode characters.


i bought your book hooked on java and i am having trouble expanding the zip files on a machine runnning win95. I ahve pkunzip and winzip and a lot of files were not expanded. Any suggestions?

Pkunzip cannot handle longer file names, so you'll need to use a different zip utility that can. For details on this and other known problems, see the "Hooked on Java" web page.


Do you have a version that will run with Windows 3.1 - if so, where do I find it. If not, when can one be expected?

IBM's Java Info site has recent announcements about Java on OS/2, AIX and Win 3.1.


I would appreciate it if you could clarify what the system requirements are for running Java on an x86 PC.

We don't have official guidelines on hardware requirements, but here are some ballpark minimums:


How do I deal with the long file extension ".java"? In trying to follow your instructions on building my first htm page, this extension is a problem, there are too many characters in the file extension ".java".

You can get the ".java" extension if you use a text editor that allows long file names (for instance, Notepad). In general, Java requires support for long file names, so be careful not to use any DOS-flavored programs that might truncate your file names to 8.3 limits behind your back.


I download the HotJava browser but it doesn't connect to the net, even when i click on the sun icon to go to your home page. Please, help me to solve this problem.

To help us diagnose the problem, try starting HotJava again, using the -verbose switch:

    \hotjava\bin\hotjava -verbose	(for Windows NT/95)
    hotjava -verbose &			(for Solaris)
visit a local demo URL, visit a remote URL, quit HotJava, and then send me copies of your access_mode, properties, and weblog files (in your .hotjava directory). Also, please send me info on your hardware/software setup and verbatim copies of any error messages you see in the process.


Do you have any suggestions for talented Java programmers that we could recruit? I would appreciate any help or guidance you could give me.

We don't keep a developer/consultant list in our group, but there are some resources for Java information independent of Sun that might be helpful to you:


Sun Microsystemshomemirror sitessearch
Copyright © 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043-1100 USA. All rights reserved. For Java technical support, see the newsgroup comp.lang.java or send mail to java@java.sun.com. For problems with this web site, send mail to webmaster@java.sun.com.