Introduction to Water Programming

This Site is intended to provide helps to Water language programmers around the world through technical examples, informational articles, and personal assistance.

The following examples are meant to be a quick Getting Started sort of tutorial using the Steam Free Version or the IDE. (If you are using the Free Version, be sure to set the output to "Rendered HTML".)

Example 10. Calling Java Code Within Water

Another powerful feature of the Steam IDE is the ability to include Java source code within your Water program to allow for added functionality.

Including Java source code is accomplished through the <java_env /> keyword.

Water:
<java_env />.<eval>
   return "Hello, World!";
</eval>

The above code will return the string "Hello, World!".

Water:
<java_env />.<eval>
   return 10 + 20;
</eval>

The above code will return the integer "30".

Water: passing variables into the Java_Env
<set a_num=447.88 />
<java_env the_num=a_num/>.<eval>
   return java.text.NumberFormat.getCurrencyInstance().format(the_num);
</eval>

The above code will return "$447.88" (or whatever the local currency is.). Notice that we can pass Water variables into the Java environment so that they can take place in the evaluation! This is an incredibly powerful feature!

One might also notice the use of fully-qualified Java class names. This is a necessity in this shell in most cases since explicit "import" statements are not included.

As a final note, I also point out that it is not necessary to include a 'return' statement in the Java_Env; often the last statement in the shell will be returned as the result of the java_env call.

Go back to go to the next example.

©Copyright 2004, Mr. Merrick J. Stemen. All rights reserved.