JavaClass object (Object/Navigator)

A JavaScript data type that encapsulates a Java Class.

Availability:

JavaScript - 1.1
Netscape - 3.0
JavaScript syntax:NmyJavaClass = myWindow.Packages.java

The static fields of the Java Class are presented as properties of the JavaClass object.

The static methods of the Java Class are presented as methods available to the JavaClass object. They may be presented as JavaMethod objects depending on how you access them from JavaScript.

The only properties and methods this object has, correspond to the public properties and methods of the Java class that it represents. You can enumerate these properties in a loop.

Java classes are either stored in individual class files or are collected together into groups stored in a ZIP file. Groups of classes will be represented by a JavaPackage object. Each individual class is represented by a JavaClass object. The JavaClass objects belong to a parent JavaPackage object.

To operate on these objects, you really need to know something about the Java classes they encapsulate. There are many standard classes and some that may have been custom written for your project.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <SCRIPT>

   // Create a JavaScript object that encapsulates a Java Class

   var myJavaDateClass  = Packages.java.util.Date;

   var myJavaDateObject = new Packages.java.util.Date;

   // Write the date to a web page

   document.write(myJavaDateObject.toString());

   // Write the same date value date to the Java console

   java.lang.System.out.println(myJavaDateObject);

   </SCRIPT>

   </BODY>

   </HTML>

See also:JavaScript to Java values, LiveConnect, Packages.java, Packages.netscape, Window.Packages

Cross-references:

O'Reilly JavaScript Definitive Guide - page - 358