[Chapter 21] Reference: JavaMethod
Author: David Flanagan
Date: Fri Aug 29 11:16:56 1997

#

| Chapter 21 JavaScript Reference |

# JavaMethod Object

## Name

JavaMethod Object---JavaScript representation of a Java method

## Availability

Navigator 3.0

## Synopsis

    javamethod(...)   invoke an instance method

## Description

The JavaMethod object is a JavaScript representation of a Java method. It is the part of LiveConnect that implements the functionality that allows JavaScript to invoke class and instance methods accessed through the JavaClass and JavaObject objects. See Chapter 19, LiveConnect: JavaScript and Java for full details.

## Usage

Bear in mind that Java is a typed language. This means that the arguments passed to a JavaMethod must be compatible with the type of the expected arguments. If arguments of the wrong type are passed, a JavaScript error will occur.

## Example

`java.lang` is the name of a JavaPackage. It contains the JavaClass `java.lang.System` This class has a property `out` which is an JavaObject. This JavaObject has a property `println`, which is a JavaMethod. LiveConnect allows us to invoke this Java method using JavaScript syntax with code like the following:

    java.lang.System.out.println("Hello from Java!");

The line of code above will write a message on the Java console. (See the Options menu to pop up the Java console in Navigator 3.0.)

## See Also

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

JavaClass |  | JavaObject