Introduction to VRML 97
Using the Java examples

These tutorial notes include a few VRML worlds that use Java program scripts within Script nodes. The text for these program scripts is included in files with .java file name extensions. Before use, you will need to compile these Java program scripts to Java byte-code contained in files with .class file name extensions.

Java support

The VRML 97 specification does not require that a VRML browser support the use of Java to create program scripts for Script nodes. Fortunately, most VRML browsers do support Java program scripts, though you should check your VRML browser's release notes to be sure it is Java-enabled.

In principle, all Java-enabled VRML browsers identically support the VRML Java API as documented in the VRML 97 specification. Similarly, in principle, a compiled Java program script using the VRML Java API can be executed on any type of computer within any brand of VRML browser

In practice, neither of these ideal cases occurs. The Java language is supported somewhat differently on different platforms, particularly as the community transitions from Java 1.0 to Java 1.1 and beyond. Additionally, the VRML Java API is implemented somewhat differently by different VRML browsers, making it difficult to insure that a compiled Java class file will work for all VRML browsers available now and in the future.

Because of Java incompatibilities observed with current VRML browsers, these tutorial notes include source Java files, but not compiled Java class files. Before use, you will need to compile the Java program scripts yourself on your platform with your VRML browser and your version of the Java language and support tools.

Compiling Java

To compile the Java examples, you will need:

  • The VRML Java API class files for your VRML browser
  • A Java compiler

All VRML browsers that support Java program scripts supply their own set of VRML Java API class files. Typically these are automatically installed when you install your VRML browser.

There are multiple Java compilers available for most platforms. Sun Microsystems provides the Java Development Kit (JDK) for free from its Web site at The JDK includes the javac compiler and instructions on how to use it. Multiple commercial Java development environments are available from Microsoft, Silicon Graphics, Symantec, and others. An up to date list of available Java products is available at Gamelan's Web site at

Once you have the VRML Java API class files and a Java compiler, you will need to compile the supplied Java files. Each platform and Java compiler is different. You'll have to consult your software's manuals.

Once compiled, place the .class files in the examples folder along with the other tutorial examples. Now, when you click on a VRML world using a Java program script, the class files will be automatically loaded and the example will run.

What if my VRML browser doesn't support Java ?

If your VRML browser doesn't support Java, then those worlds that use Java will produce an error when loaded into your VRML browser. This is unfortunate since Java is an essential feature that all VRML browsers should support. Perhaps you should consider getting a different brand of VRML browser...

What if I don't compile the Java program scripts?

If you have a VRML browser that doesn't support Java, or if if you don't compile the Java program scripts, those worlds that use Java will produce an error when loaded into your VRML browser. Fortunately, Java program scripts are only used in the Writing program scripts with Java section of the tutorial slides. So, if you don't compile the Java program scripts, then just skip the VRML examples in that section and everything will be fine.