Main Page

Using the Java console

Using the Java console
In browsers that support LiveConnect (interaction between Java and JavaScript, discussed later in the
book), you can use the Java console to log messages to yourself just as you can in Java.
For example, in Java you can log messages to the console window by doing this:
In JavaScript, you can do the same by expanding the
variable into its full
Placing calls like this into a function is a great way to track code execution:
function test_function() {
java.lang.System.out.println(“Entering function.”);
var iNumber1 = 5;
var iNumber2 = 10;
java.lang.System.out.println(“Before calculation.”);
var iResult = iNumber1 + iNumber2;
java.lang.System.out.println(“After calculation.”);
java.lang.System.out.println(“Leaving function.”);
To see the output, select Tools
Java Console. You see the output after the default Java console output
(Figure 14-10).
Figure 14-10
Error Handling
17_579088 ch14.qxd 3/28/05 11:41 AM Page 429

JavaScript EditorFree JavaScript Editor     Ajax Editor