All JavaPackage objects are contained within a parent JavaPackage, and the Window property named Packages is a top-level JavaPackage that serves as the root of this package hierarchy. It has java, sun, and netscape properties, which are JavaPackage objects that represent the various hierarchies of Java classes that are included with Navigator. For example, the JavaPackage Packages contains the JavaPackage Packages.java, which contains the JavaPackage Packages.java.awt. For convenience, every Window object has java, sun, and netscape properties which are shortcuts to Packages.java, Packages.sun, and Packages.netscape. Thus, instead of typing Packages.java.awt, you can simply use java.awt.
To continue with the example, java.awt is a JavaPackage object that contains JavaClass objects like java.awt.Button, which represents the java.awt.Button class. But it also contains yet another JavaPackage object, java.awt.image which represents the java.awt.image package in Java.
As you can see, the property naming scheme for the JavaPackage hierarchy mirrors the naming scheme for Java packages. Note that there is one big difference between the JavaPackage object and actual Java packages. Packages in Java are collections of classes, not collections of other packages. That is, java.lang is the name of a Java package, but java is not. So the JavaPackage object named java does not actually represent a package in Java, but is simply a convenient placeholder in the package hierarchy for other JavaPackage objects that do represent real Java packages.
On many systems, Java classes are installed in files in a directory hierarchy that corresponds to the package name. For example, the java.lang.String class is stored in the file java/lang/String.class in my Java implementation from Sun. In other implementations, notably that from Netscape, the class files are actually stored in a large uncompressed zip file. The directory hierarchy is still there, encoded in the file; it is just not visible on the surface. Therefore, instead of thinking of the JavaPackage object as representing a Java package, you may find it clearer to consider it as representing a directory in the Java class hierarchy.
As we've said above, a JavaPackage object contains properties for each of the packages and classes it contains. If you think of a JavaPackage as representing a directory in the Java class directory hierarchy, then the properties of the JavaPackage are the contents of the directory. Each subdirectory of the directory becomes a JavaPackage property, with the package name matching the subdirectory name. Each file in the directory becomes a JavaClass property, with the property name matching the file name, after the .class extension is stripped off. When viewed in this way, it is easy to understand why the JavaPackage object does not allow the for/in loop to list all of its properties--those properties actually correspond to directory contents, and they are not actually looked up and created until they are first used. Thus, a for/in loop will only find those properties of a JavaPackage object that have already been used at least once by the program.
var java_console = java.lang.System.out;
var java_version = java.lang.System.getProperty("java.version");
var d = new java.lang.Double(1.23);
Finally, having created a JavaObject in this way, we can return to the getClass() function and show an example of its use:
var d = new java.lang.Double(1.23); // Create a JavaObject. var d_class = getClass(d); // Obtain the JavaClass of the JavaObject. if (d_class == java.lang.Double) ...; // This comparison will be true.
n = d.doubleValue();
 The output of this line of code doesn't appear in the web browser itself, but in the "Java Console." Select Show Java Console in the Options menu to make the console visible.
r = new java.awt.Rectangle();
r.x = r.y = 0; r.width = 4; r.height = 5; var perimeter = 2*r.width + 2*r.height;
var println_method = java.lang.System.out.println; println_method("Hello world!");
var r = java.awt.Rectangle(0, 0, 10, 10); // a 10x10 square at (0,0) var i = r.inside(5,5); // is the point (5,5) inside?
For example, suppose we create an instance of the java.awt.Polygon class:
p = new java.awt.Polygon();
for(int i = 0; i < p.xpoints.length; i++) p.xpoints[i] = Math.round(Math.random()*100); for(int i = 0; i < p.ypoints.length; i++) p.ypoints[i] = Math.round(Math.random()*100);