please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

JavaClass Object

Name

JavaClass Object---JavaScript representation of a Java class

Availability

Navigator 3.0

Synopsis

javaclass.static_field  read or write a static Java field
new javaclass(...)    create a new Java object

Properties

Each JavaClass object contains properties that have the same names as the public static fields and methods of the Java class it represents. These properties allow you to read and write the static fields of the class. Each JavaClass object has different properties; you can use a for/in loop to enumerate them for any given JavaClass object.

Description

The JavaClass object is a JavaScript representation of a Java class. The properties of a JavaClass object represent the public static fields and methods (sometimes called class fields and class methods) of the represented class. Note that the JavaClass object does not have properties representing the instance fields of a Java class--individual instances of a Java class are represented by the JavaObject object.

The JavaClass object implements the LiveConnect functionality that allows JavaScript programs to read and write the static variables of Java classes using normal JavaScript syntax. The JavaClass object also provides the functionality that allows JavaScript to read the static methods of a Java class, although it is the JavaMethod object that allows JavaScript to actually invoke those methods.

Besides allowing JavaScript to read and write Java variable and method values, the JavaClass object also allows JavaScript programs to create Java objects (represented by a JavaObject object) by using the new keyword and invoking the constructor method of a JavaClass.

The data conversion required for communication between JavaScript and Java through the JavaClass object is handled automatically by LiveConnect. See Chapter 19, LiveConnect: JavaScript and Java for full details.

Usage

Bear in mind that Java is a typed language. This means that each of the fields of an object have a specific data type, and you can only set them to values of that type. Attempting to set a field to a value that is not of the correct type will result in a JavaScript error. Attempting to invoke a method with arguments of the wrong type will also cause an error.

Example

java.lang.System is a JavaClass object that represents the java.lang.System class in Java. You can read a static field of this class with code like the following:

var java_console =index.html java.lang.System.out;

You can invoke a static method of this class with a line like this one:

var version =index.html java.lang.System.getProperty("java.version");

Finally, the JavaClass object also allows you to create new Java objects like this:

var java_date =index.html new java.lang.Date();

See Also

"getClass()", "java", "JavaArray", "JavaMethod", "JavaObject", "JavaPackage", "Packages", Chapter 19, LiveConnect: JavaScript and Java


Previous Home Next
JavaArray.length Book Index JavaMethod

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/JAVA/SCRIPT/definitive/refp_180.htm, 7KB, , updated: 2019/10/14 15:00, local time: 2024/11/19 21:42,
TOP NEW HELP FIND: 
18.223.203.36:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://linistepper.com/Techref/language/JAVA/SCRIPT/definitive/refp_180.htm"> [Chapter 21] Reference: JavaClass</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?