please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

JavaArray Object

Name

JavaArray Object---JavaScript representation of a Java array

Availability

Navigator 3.0

Synopsis

javaarray.length  the length of the array
javaarray[index]    read or write an array element

Properties

length

A read-only integer that specifies the number of elements in the Java array represented by the JavaArray object.

Description

The JavaArray object is a JavaScript representation of a Java array, and it allows JavaScript code to read and write the elements of the array using familiar JavaScript array syntax. In addition, the JavaArray object has a length field which specifies the number of elements in the Java array.

When reading and writing values from array elements, data conversion between JavaScript and Java representations is automatically handled by the system. See Chapter 19, LiveConnect: JavaScript and Java for full details.

Usage

Note that Java arrays differ from JavaScript arrays in a couple of important aspects. First, Java arrays have a fixed length that is specified when they are created. For this reason, the JavaArray length field is read-only. The second difference is that Java arrays are typed--i.e., their elements must all be of the same type of data. Attempting to set an array element to a value of the wrong type will result in a JavaScript error.

Example

java.awt.Polygon is a JavaClass object. We can create a JavaObject representing an instance of the class like this:

p =index.html new java.awt.Polygon();

This object p has properties xpoints and ypoints which are JavaArray objects representing Java arrays of integers. We could initialize the contents of these arrays with JavaScript code like the following:

for(int i =index.html 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);

See Also

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


Previous Home Next
java Book Index JavaArray.length

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

file: /Techref/language/java/script/definitive/refp_178.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/11/27 02:07,
TOP NEW HELP FIND: 
18.225.175.230: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://ecomorder.com/Techref/language/java/script/definitive/refp_178.htm"> [Chapter 21] Reference: JavaArray</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?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .